Skip to main content

UpperCamel

Struct UpperCamel 

Source
pub struct UpperCamel<P>(/* private fields */);
Expand description

A case adapter for a character profile that accepts uncased, uppercase, and titlecase characters on the first character of a chunk or identifier.

§Note

If you’re using the regular unicode profile, it’s possible that you can construct valid strings which appear to break the requirements of this type.

use typed_ident::presets::unicode::UpperCamelIdent;
assert!(UpperCamelIdent::new("_a").is_err()); // Doesn't work (expected).
assert!(UpperCamelIdent::new("_゙a").is_ok()); // Works?

The payload provided for that second case is:

  • _ (U+005F) LOW LINE
  • (U+3099) COMBINING KATAKANA-HIRAGANA VOICED SOUND MARK
  • a (U+0061) LATIN SMALL LETTER A

The way to prevent this is to disallow Mn/Mc/Me characters on chunk start.

You can get a profile which does this by enabling unicode-strict. This will enable the Strict profile which can be used directly - or if you have presets enabled - used indirectly through strict presets.

use typed_ident::presets::strict::UpperCamelIdent;
assert!(UpperCamelIdent::new("_a").is_err()); // Doesn't work (expected).
assert!(UpperCamelIdent::new("_゙a").is_err()); // Now it doesn't work!

See Strict for more details on when you should do this.

Trait Implementations§

Source§

impl<P: CharProfile> CasedProfile for UpperCamel<P>

Source§

impl<P: CharProfile> Profile for UpperCamel<P>

Source§

const APPEND_CLOSED: AppendClosed

UpperCamel cannot be append-closed for >=Fragment, because is_chunk_start is not identical to is_chunk_continue.

See Profile::APPEND_CLOSED for details.

Source§

type BaseProfile = P

The underlying profile that this profile is based on. Read more
Source§

type Segmentation = <P as Profile>::Segmentation

The segmentation strategy that this profile uses. Read more
Source§

fn is_ident_start(c: char) -> bool

Whether or not the provided character can appear at the absolute start of an identifier. Read more
Source§

fn is_chunk_start(c: char) -> bool

Whether or not the provided character can appear at the start of a new chunk (e.g. right after a delimiter). Read more
Source§

fn in_profile(c: char) -> bool

Whether or not the provided character can appear at any point in a chunk. Read more
Source§

fn is_chunk_continue(c: char) -> bool

Whether or not the provided character is valid at any position after the first character of a chunk (a run of non-delimiter characters).
Source§

impl<Superset, Subset> SubsetOf<Superset> for UpperCamel<Subset>
where Superset: CharProfile, Subset: CharProfile + SubsetOf<Superset>,

Proof: If SuperSubset, then SuperUpperCamel<Subset>.

Let’s pretend that Superset=Unicode, and Subset=Ascii.

If Ascii: SubsetOf<Unicode> (true), then this implies the following:

  • UpperCamel<Ascii>: SubsetOf<Unicode>

§Proof

left_is_subset_of_right::<UpperCamel<Ascii>, Ascii>();
left_is_subset_of_right::<UpperCamel<Unicode>, Unicode>();
left_is_subset_of_right::<UpperCamel<Ascii>, Unicode>();
Source§

impl<Superset, Subset> SubsetOf<UpperCamel<Superset>> for Upper<Subset>
where Superset: CharProfile, Subset: CharProfile + SubsetOf<Superset>,

Proof: If SuperSubset, then UpperCamel<Super>Upper<Subset> (because UpperCamelUpper).

Let’s pretend that Superset=Unicode, and Subset=Ascii.

If Ascii: SubsetOf<Unicode> (true), then this implies the following:

  • Upper<Ascii>: SubsetOf<UpperCamel<Unicode>>

§Examples

left_is_subset_of_right::<Upper<Ascii>, UpperCamel<Ascii>>();
left_is_subset_of_right::<Upper<Unicode>, UpperCamel<Unicode>>();
left_is_subset_of_right::<Upper<Ascii>, UpperCamel<Unicode>>();
Source§

impl<Superset, Subset> SubsetOf<UpperCamel<Superset>> for UpperCamel<Subset>
where Superset: CharProfile, Subset: CharProfile + SubsetOf<Superset>,

Proof: If SuperSubset, then UpperCamel<Super>UpperCamel<Subset>.

Let’s pretend that Superset=Unicode, and Subset=Ascii.

If Ascii: SubsetOf<Unicode> (true), then this implies the following:

  • UpperCamel<Ascii>: SubsetOf<UpperCamel<Unicode>>

§Proof

left_is_subset_of_right::<UpperCamel<Ascii>, UpperCamel<Ascii>>();
left_is_subset_of_right::<UpperCamel<Unicode>, UpperCamel<Unicode>>();
left_is_subset_of_right::<UpperCamel<Ascii>, UpperCamel<Unicode>>();

Auto Trait Implementations§

§

impl<P> Freeze for UpperCamel<P>
where PhantomData<P>: Freeze,

§

impl<P> RefUnwindSafe for UpperCamel<P>

§

impl<P> Send for UpperCamel<P>
where PhantomData<P>: Send,

§

impl<P> Sync for UpperCamel<P>
where PhantomData<P>: Sync,

§

impl<P> Unpin for UpperCamel<P>
where PhantomData<P>: Unpin,

§

impl<P> UnsafeUnpin for UpperCamel<P>

§

impl<P> UnwindSafe for UpperCamel<P>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.