Skip to main content

Identifier

Trait Identifier 

Source
pub trait Identifier {
    type Boundary: Boundary;
    type Delimiter: Delimiter;
    type Profile: Profile;

Show 45 methods // Required method fn as_ident(&self) -> &Ident<Self::Boundary, Self::Delimiter, Self::Profile>; // Provided methods fn from_fragment( fragment: &Fragment<Self::Boundary, Self::Delimiter, Self::Profile>, ) -> Result<&Ident<Self::Boundary, Self::Delimiter, Self::Profile>, Error> { ... } fn new( s: &str, ) -> Result<&Ident<Self::Boundary, Self::Delimiter, Self::Profile>, Error> { ... } fn new_boxed( s: String, ) -> Result<Box<Ident<Self::Boundary, Self::Delimiter, Self::Profile>>, Error> { ... } fn new_fragment_buffer( ) -> FragmentBuf<Self::Boundary, Self::Delimiter, Self::Profile> { ... } fn new_ident_buffer( ) -> IdentBuf<Self::Boundary, Self::Delimiter, Self::Profile> { ... } fn as_fragment( &self, ) -> &Fragment<Self::Boundary, Self::Delimiter, Self::Profile> { ... } fn first_segment( &self, ) -> Segment<Self::Delimiter, &Chunk<Self::Boundary, Self::Delimiter, Self::Profile>> { ... } fn last_segment( &self, ) -> Segment<Self::Delimiter, &Chunk<Self::Boundary, Self::Delimiter, Self::Profile>> { ... } fn split_at( &self, mid: usize, ) -> (Option<&Ident<Self::Boundary, Self::Delimiter, Self::Profile>>, &Fragment<Self::Boundary, Self::Delimiter, Self::Profile>) { ... } fn split_at_checked( &self, mid: usize, ) -> Option<(Option<&Ident<Self::Boundary, Self::Delimiter, Self::Profile>>, &Fragment<Self::Boundary, Self::Delimiter, Self::Profile>)> { ... } fn trim_decorative_delims( &self, ) -> &Ident<Self::Boundary, Self::Delimiter, Self::Profile> { ... } fn trim_leading_decorative_delims( &self, ) -> &Ident<Self::Boundary, Self::Delimiter, Self::Profile> { ... } fn trim_trailing_decorative_delims( &self, ) -> &Ident<Self::Boundary, Self::Delimiter, Self::Profile> { ... } fn trim_delims( &self, ) -> &Fragment<Self::Boundary, Self::Delimiter, Self::Profile> { ... } fn trim_leading_delims( &self, ) -> &Fragment<Self::Boundary, Self::Delimiter, Self::Profile> { ... } fn trim_trailing_delims( &self, ) -> &Fragment<Self::Boundary, Self::Delimiter, Self::Profile> { ... } fn has_leading_delim(&self) -> bool { ... } fn has_trailing_delim(&self) -> bool { ... } fn is_anonymous(&self) -> bool { ... } fn as_str(&self) -> &str { ... } fn contains<M>(&self, pat: M) -> bool where M: Pattern { ... } fn ends_with<M>(&self, pat: M) -> bool where M: Pattern { ... } fn starts_with<M>(&self, pat: M) -> bool where M: Pattern { ... } fn find<M>(&self, pat: M) -> Option<usize> where M: Pattern { ... } fn rfind<M>(&self, pat: M) -> Option<usize> where M: Pattern { ... } fn chunked_segments( &self, ) -> ChunkedSegments<'_, Self::Boundary, Self::Delimiter, Self::Profile> { ... } fn chunked_segment_indices( &self, ) -> ChunkedSegmentIndices<'_, Self::Boundary, Self::Delimiter, Self::Profile> { ... } fn segments( &self, ) -> Segments<'_, Self::Boundary, Self::Delimiter, Self::Profile> { ... } fn segment_indices( &self, ) -> SegmentIndices<'_, Self::Boundary, Self::Delimiter, Self::Profile> { ... } fn cast<B2, D2, P2>(&self) -> &Ident<B2, D2, P2> where Self::Delimiter: SubsetOf<D2>, Self::Profile: SubsetOf<P2> { ... } fn char_indices( &self, ) -> CharIndices<'_, Self::Boundary, Self::Delimiter, Self::Profile> { ... } fn chars(&self) -> Chars<'_, Self::Boundary, Self::Delimiter, Self::Profile> { ... } fn match_indices<M>( &self, pat: M, ) -> MatchIndices<'_, Self::Boundary, Self::Delimiter, Self::Profile, M> where M: Pattern { ... } fn matches<M>( &self, pat: M, ) -> Matches<'_, Self::Boundary, Self::Delimiter, Self::Profile, M> where M: Pattern { ... } fn rmatch_indices<M>( &self, pat: M, ) -> RMatchIndices<'_, Self::Boundary, Self::Delimiter, Self::Profile, M> where M: Pattern { ... } fn rmatches<M>( &self, pat: M, ) -> RMatches<'_, Self::Boundary, Self::Delimiter, Self::Profile, M> where M: Pattern { ... } fn trim_start_matches<M>( &self, pat: M, ) -> &Fragment<Self::Boundary, Self::Delimiter, Self::Profile> where M: Pattern { ... } fn trim_end_matches<M>( &self, pat: M, ) -> &Fragment<Self::Boundary, Self::Delimiter, Self::Profile> where M: Pattern { ... } fn get<I: SliceIndex<Fragment<Self::Boundary, Self::Delimiter, Self::Profile>>>( &self, i: I, ) -> Option<&Fragment<Self::Boundary, Self::Delimiter, Self::Profile>> { ... } unsafe fn get_unchecked<I: SliceIndex<Fragment<Self::Boundary, Self::Delimiter, Self::Profile>>>( &self, i: I, ) -> &Fragment<Self::Boundary, Self::Delimiter, Self::Profile> { ... } fn len(&self) -> usize { ... } fn strip_circumfix<Prefix, Suffix>( &self, prefix: Prefix, suffix: Suffix, ) -> Option<&Fragment<Self::Boundary, Self::Delimiter, Self::Profile>> where Prefix: Pattern, Suffix: Pattern { ... } fn strip_prefix<M>( &self, prefix: M, ) -> Option<&Fragment<Self::Boundary, Self::Delimiter, Self::Profile>> where M: Pattern { ... } fn strip_suffix<M>( &self, suffix: M, ) -> Option<&Fragment<Self::Boundary, Self::Delimiter, Self::Profile>> where M: Pattern { ... }
}
Expand description

A trait for dealing with identifiers in a generic way.

Sometimes it can be a bit annoying to be specific about the exact syntax rules for an identifier. Because of that, this trait exists so that you can just generically say that you want something that looks like an identifier.

§Examples

Basic Usage:

fn print_segments<I: Identifier + ?Sized>(ident: &I) {
    println!("segments:");
    for s in ident.segments() {
        println!("* {s:?}");
    }
}

print_segments(LowerSnakeIdent::new("lower_snake")?);
print_segments(UpperCamelIdent::new("UpperCamel")?);

Required Associated Types§

Source

type Boundary: Boundary

The boundary configuration in-use by this identifier.

Source

type Delimiter: Delimiter

The valid delimiters that are allowed by this identifier.

Source

type Profile: Profile

The character profile that is allowed by this identifier.

Required Methods§

Source

fn as_ident(&self) -> &Ident<Self::Boundary, Self::Delimiter, Self::Profile>

Converts to an actual typed identifier.

This is used to fill in the rest of the functionality on the Identifier trait using default functions. However, it can also be useful if you need to depend on some specific trait implementations on an actual identifier type, versus just abstractly working with an identifier through this trait.

Provided Methods§

Source

fn from_fragment( fragment: &Fragment<Self::Boundary, Self::Delimiter, Self::Profile>, ) -> Result<&Ident<Self::Boundary, Self::Delimiter, Self::Profile>, Error>

Converts a fragment to an identifier.

See the Ident::from_fragment documentation for details.

Source

fn new( s: &str, ) -> Result<&Ident<Self::Boundary, Self::Delimiter, Self::Profile>, Error>

Converts a string slice to an identifier.

See the Ident::new documentation for details.

Source

fn new_boxed( s: String, ) -> Result<Box<Ident<Self::Boundary, Self::Delimiter, Self::Profile>>, Error>

Converts an allocated string to a boxed identifier.

See the Ident::new_boxed documentation for details.

Source

fn new_fragment_buffer() -> FragmentBuf<Self::Boundary, Self::Delimiter, Self::Profile>

Constructs a new ident buffer for this type.

See the FragmentBuf documentation for details.

Source

fn new_ident_buffer() -> IdentBuf<Self::Boundary, Self::Delimiter, Self::Profile>

Constructs a new ident buffer for this type.

See the IdentBuf documentation for details.

Source

fn as_fragment( &self, ) -> &Fragment<Self::Boundary, Self::Delimiter, Self::Profile>

Casts the identifier to a fragment.

See the Ident::as_fragment documentation for details.

Source

fn first_segment( &self, ) -> Segment<Self::Delimiter, &Chunk<Self::Boundary, Self::Delimiter, Self::Profile>>

Returns the first segment from an identifier

See the Ident::first_segment documentation for details.

Source

fn last_segment( &self, ) -> Segment<Self::Delimiter, &Chunk<Self::Boundary, Self::Delimiter, Self::Profile>>

Returns the last segment from an identifier

See the Ident::last_segment documentation for details.

Source

fn split_at( &self, mid: usize, ) -> (Option<&Ident<Self::Boundary, Self::Delimiter, Self::Profile>>, &Fragment<Self::Boundary, Self::Delimiter, Self::Profile>)

Splits an identifier into fragments at the given index.

See the Ident::split_at documentation for details.

§Panics

Panics if mid is not on a UTF-8 code point boundary, or if it is past the end of the last code point of the identifier. For a non-panicking alternative see split_at_checked.

Source

fn split_at_checked( &self, mid: usize, ) -> Option<(Option<&Ident<Self::Boundary, Self::Delimiter, Self::Profile>>, &Fragment<Self::Boundary, Self::Delimiter, Self::Profile>)>

Splits an identifier into fragments at the given index (checked variant).

See the Ident::split_at_checked documentation for details.

Source

fn trim_decorative_delims( &self, ) -> &Ident<Self::Boundary, Self::Delimiter, Self::Profile>

Trims the decorative (non-required) delimiters from the ends of an identifier.

See the Ident::trim_decorative_delims documentation for details.

Source

fn trim_leading_decorative_delims( &self, ) -> &Ident<Self::Boundary, Self::Delimiter, Self::Profile>

Trims the decorative (non-required) delimiters from the start of an identifier.

See the Ident::trim_leading_decorative_delims documentation for details.

Source

fn trim_trailing_decorative_delims( &self, ) -> &Ident<Self::Boundary, Self::Delimiter, Self::Profile>

Trims the decorative (non-required) delimiters from the end of an identifier.

See the Ident::trim_trailing_decorative_delims documentation for details.

Source

fn trim_delims( &self, ) -> &Fragment<Self::Boundary, Self::Delimiter, Self::Profile>

Trims the delimiters from the ends of an identifier.

This function can leave you with an invalid identifier, because it may remove required delimiters to make the identifier valid (or strip down to an empty identifier). As such, it returns a Fragment.

For a version that leaves you with a valid identifier, see trim_decorative_delims.

See the Fragment::trim_delims documentation for details.

Source

fn trim_leading_delims( &self, ) -> &Fragment<Self::Boundary, Self::Delimiter, Self::Profile>

Trims the delimiters from the start of an identifier.

This function can leave you with an invalid identifier, because it may remove required delimiters to make the identifier valid (or strip down to an empty identifier). As such, it returns a Fragment.

For a version that leaves you with a valid identifier, see trim_leading_decorative_delims.

See the Fragment::trim_leading_delims documentation for details.

Source

fn trim_trailing_delims( &self, ) -> &Fragment<Self::Boundary, Self::Delimiter, Self::Profile>

Trims the delimiters from the end of an identifier.

This function can leave you with an invalid identifier, because it may strip down to an empty identifier. As such, it returns a Fragment.

For a version that leaves you with a valid identifier, see trim_trailing_decorative_delims.

See the Fragment::trim_trailing_delims documentation for details.

Source

fn has_leading_delim(&self) -> bool

Returns whether the identifier has leading delimiters.

See the Fragment::has_leading_delim documentation for details.

Source

fn has_trailing_delim(&self) -> bool

Returns whether the identifier has trailing delimiters.

See the Fragment::has_trailing_delim documentation for details.

Source

fn is_anonymous(&self) -> bool

Returns whether the identifier consists of only delimiters.

See the Fragment::is_anonymous documentation for details.

Source

fn as_str(&self) -> &str

Returns the string representation of an identifier.

See the Fragment::as_str documentation for details.

Source

fn contains<M>(&self, pat: M) -> bool
where M: Pattern,

Returns whether the identifier contains a pattern.

See the Fragment::contains documentation for details.

Source

fn ends_with<M>(&self, pat: M) -> bool
where M: Pattern,

Returns whether the identifier ends with a pattern.

See the Fragment::ends_with documentation for details.

Source

fn starts_with<M>(&self, pat: M) -> bool
where M: Pattern,

Returns whether the identifier starts with a pattern.

See the Fragment::starts_with documentation for details.

Source

fn find<M>(&self, pat: M) -> Option<usize>
where M: Pattern,

Returns the position where a pattern can first be found.

See the Fragment::find documentation for details.

Source

fn rfind<M>(&self, pat: M) -> Option<usize>
where M: Pattern,

Returns the position where a pattern can first be found from the end.

See the Fragment::rfind documentation for details.

Source

fn chunked_segments( &self, ) -> ChunkedSegments<'_, Self::Boundary, Self::Delimiter, Self::Profile>

Returns an iterator for chunked segments of an identifier.

See the Fragment::chunked_segments documentation for details.

Source

fn chunked_segment_indices( &self, ) -> ChunkedSegmentIndices<'_, Self::Boundary, Self::Delimiter, Self::Profile>

Returns an iterator for chunked segments of an identifier with their positions.

See the Fragment::chunked_segment_indices documentation for details.

Source

fn segments( &self, ) -> Segments<'_, Self::Boundary, Self::Delimiter, Self::Profile>

Returns an iterator for segments of an identifier.

See the Fragment::segments documentation for details.

Source

fn segment_indices( &self, ) -> SegmentIndices<'_, Self::Boundary, Self::Delimiter, Self::Profile>

Returns an iterator for segments of an identifier with their positions.

See the Fragment::segment_indices documentation for details.

Source

fn cast<B2, D2, P2>(&self) -> &Ident<B2, D2, P2>
where Self::Delimiter: SubsetOf<D2>, Self::Profile: SubsetOf<P2>,

Zero-cost casts an identifier to another compatible format.

See the Ident::cast documentation for details.

Source

fn char_indices( &self, ) -> CharIndices<'_, Self::Boundary, Self::Delimiter, Self::Profile>

Returns an iterator over the characters of an identifier and their positions.

See the Fragment::char_indices documentation for details.

Source

fn chars(&self) -> Chars<'_, Self::Boundary, Self::Delimiter, Self::Profile>

Returns an iterator over the characters of an identifier.

See the Fragment::chars documentation for details.

Source

fn match_indices<M>( &self, pat: M, ) -> MatchIndices<'_, Self::Boundary, Self::Delimiter, Self::Profile, M>
where M: Pattern,

Returns an iterator over the matches of an identifier and their positions.

See the Fragment::match_indices documentation for details.

Source

fn matches<M>( &self, pat: M, ) -> Matches<'_, Self::Boundary, Self::Delimiter, Self::Profile, M>
where M: Pattern,

Returns an iterator over the matches of an identifier.

See the Fragment::matches documentation for details.

Source

fn rmatch_indices<M>( &self, pat: M, ) -> RMatchIndices<'_, Self::Boundary, Self::Delimiter, Self::Profile, M>
where M: Pattern,

Returns an iterator over the matches of an identifier from the end, and their positions.

See the Fragment::rmatch_indices documentation for details.

Source

fn rmatches<M>( &self, pat: M, ) -> RMatches<'_, Self::Boundary, Self::Delimiter, Self::Profile, M>
where M: Pattern,

Returns an iterator over the matches of an identifier from the end.

See the Fragment::rmatches documentation for details.

Source

fn trim_start_matches<M>( &self, pat: M, ) -> &Fragment<Self::Boundary, Self::Delimiter, Self::Profile>
where M: Pattern,

Trims the characters that match the provided pattern from the start.

See the Fragment::trim_start_matches documentation for details.

Source

fn trim_end_matches<M>( &self, pat: M, ) -> &Fragment<Self::Boundary, Self::Delimiter, Self::Profile>
where M: Pattern,

Trims the characters that match the provided pattern from the end.

See the Fragment::trim_end_matches documentation for details.

Source

fn get<I: SliceIndex<Fragment<Self::Boundary, Self::Delimiter, Self::Profile>>>( &self, i: I, ) -> Option<&Fragment<Self::Boundary, Self::Delimiter, Self::Profile>>

Returns a subslice of an identifier.

This is the checked variant to just using the index operator. If you are anyways going to unwrap or expect, you should just use the index operator - as it will panic on failure.

See the Fragment::get documentation for details.

Source

unsafe fn get_unchecked<I: SliceIndex<Fragment<Self::Boundary, Self::Delimiter, Self::Profile>>>( &self, i: I, ) -> &Fragment<Self::Boundary, Self::Delimiter, Self::Profile>

Returns an unchecked subslice of an identifier.

See the Ident::get_unchecked documentation for details.

§Safety

Callers of this function are responsible that these preconditions are satisfied:

  • The starting index must not exceed the ending index;
  • Indexes must be within bounds of the original slice;
  • Indexes must lie on UTF-8 sequence boundaries.
Source

fn len(&self) -> usize

Returns the length of the identifier.

See the Fragment::len documentation for details.

Source

fn strip_circumfix<Prefix, Suffix>( &self, prefix: Prefix, suffix: Suffix, ) -> Option<&Fragment<Self::Boundary, Self::Delimiter, Self::Profile>>
where Prefix: Pattern, Suffix: Pattern,

Strips the circumfix off an identifier.

See the Fragment::strip_circumfix documentation for details.

Source

fn strip_prefix<M>( &self, prefix: M, ) -> Option<&Fragment<Self::Boundary, Self::Delimiter, Self::Profile>>
where M: Pattern,

Strips the prefix off an identifier.

See the Fragment::strip_prefix documentation for details.

Source

fn strip_suffix<M>( &self, suffix: M, ) -> Option<&Fragment<Self::Boundary, Self::Delimiter, Self::Profile>>
where M: Pattern,

Strips the suffix off an identifier.

See the Fragment::strip_suffix documentation for details.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§