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 MARKa(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§
impl<P: CharProfile> CasedProfile for UpperCamel<P>
Source§impl<P: CharProfile> Profile for UpperCamel<P>
impl<P: CharProfile> Profile for UpperCamel<P>
Source§const APPEND_CLOSED: AppendClosed
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
type BaseProfile = P
Source§type Segmentation = <P as Profile>::Segmentation
type Segmentation = <P as Profile>::Segmentation
Source§fn is_ident_start(c: char) -> bool
fn is_ident_start(c: char) -> bool
Source§fn is_chunk_start(c: char) -> bool
fn is_chunk_start(c: char) -> bool
Source§fn in_profile(c: char) -> bool
fn in_profile(c: char) -> bool
Source§fn is_chunk_continue(c: char) -> bool
fn is_chunk_continue(c: char) -> bool
impl<Superset, Subset> SubsetOf<Superset> for UpperCamel<Subset>
Proof: If Super ⊆ Subset, then 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<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>();impl<Superset, Subset> SubsetOf<UpperCamel<Superset>> for Upper<Subset>
Proof: If Super ⊆ Subset, then UpperCamel<Super> ⊆ Upper<Subset>
(because UpperCamel ⊆ Upper).
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>>();impl<Superset, Subset> SubsetOf<UpperCamel<Superset>> for UpperCamel<Subset>
Proof: If Super ⊆ Subset, 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>>();