Skip to main content

Strict

Enum Strict 

Source
pub enum Strict {}
Expand description

The same as Unicode, except that it disallows Mc, Me, and Mn characters at the start of a chunk.

§The Issue With Mc, Me, and Mn Characters

If you allow joining characters at chunk-start, you can create some surprisingly valid identifiers.

assert!(LowerCamelIdent::new("_A").is_err()); // Doesn't work (expected).
assert!(LowerCamelIdent::new("_゙A").is_ok());  // Works?
assert!(UpperCamelIdent::new("_a").is_err()); // Doesn't work (expected).
assert!(UpperCamelIdent::new("_゙a").is_ok());  // Works?

If you’re okay with another dependency and slightly less optimized code, you can protect against this with the Strict profile:

assert!(LowerCamelIdent::new("_A").is_err()); // Doesn't work (expected).
assert!(LowerCamelIdent::new("_゙A").is_err()); // Also doesn't work!
assert!(UpperCamelIdent::new("_a").is_err()); // Doesn't work (expected).
assert!(UpperCamelIdent::new("_゙a").is_err()); // Also doesn't work!

§When To Use Strict vs. Unicode

You should almost always just use Unicode.

You only want Strict if you really want to enforce that upper and lower camel look a certain way (e.g. that the first character is upper or lower compatible).

Strict processing is a bit slower, and causes the profile to no longer be APPEND_CLOSED for fragments (which reduces the optimizations we can do). It costs you something, and usually it’s not worth the cost.

Trait Implementations§

Source§

impl CharProfile for Strict

Source§

impl Profile for Strict

Source§

const APPEND_CLOSED: AppendClosed = AppendClosed::Chunk

Whether or not a fragment containing characters in this profile are append-closed. Read more
Source§

type BaseProfile = Strict

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

type Segmentation = Grapheme

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 SubsetOf<Strict> for Ascii

Proof: ASCII is a subset of the Strict profile (which is basically Unicode).

Source§

impl SubsetOf<Strict> for Strict

Proof: It’s always safe to implement this against yourself.

Source§

impl SubsetOf<Unicode> for Strict

Proof: Strict is a subset of the Unicode profile (strict has more restrictions).

Auto Trait Implementations§

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.