Skip to main content

IdentBuf

Struct IdentBuf 

Source
pub struct IdentBuf<B, D, P> { /* private fields */ }
Expand description

A dynamic, growable identifier.

This allows you to build a identifier dynamically, instead of having to get one from a string slice.

§Not Inherently an Ident

Unlike Fragments, Idents have a requirement not only of being comprised of certain characters in a certain order, but also that the identifier itself is not empty.

Because of that, and because IdentBuf can be empty, it might surprise you to realize that IdentBuf does NOT implement Deref to Ident (as String, PathBuf, or indeed, FragmentBuf would for their respective immutably borrowed counterparts).

Instead, you must attempt a fallible cast to an identifier, which can only fail if the buffer itself is empty.

let mut buffer = UpperCamelIdentBuf::new();
assert!(buffer.as_ident().is_none());

buffer.push('V')?;
assert!(buffer.as_ident().is_some());

If your chosen delimiter implements Default, there’s a nice helper function for this, which does what I believe most people would do in this situation; see as_ident_or_anonymous.

Implementations§

Source§

impl<B: Boundary, D: Delimiter, P: Profile> IdentBuf<B, D, P>

Source

pub fn from_str(s: &str) -> Result<Self, Error>

Constructs an ident buffer, initializing the contents to a provided string slice (attempting first to convert the string slice to a valid ident).

This is equivalent to IdentBuf::from_fragment(Fragment::new(s)?).

§Examples

Basic Usage:

assert!(UpperCamelIdentBuf::from_str("").is_err());
assert!(UpperCamelIdentBuf::from_str("ValidUpperCamel").is_ok());
assert!(UpperCamelIdentBuf::from_str("continuingUpperCamel").is_err());
assert!(UpperCamelIdentBuf::from_str("not_validUpperCamel").is_err());
Source

pub fn from_string(s: String) -> Result<Self, Error>

Constructs an ident buffer, initializing the contents to a provided buffered string (checking first that the string is a valid ident).

This is similar to from_str, except that it will not allocate a separate string. It will use the provided string, if it’s valid.

§Examples

Basic Usage:

assert!(UpperCamelIdentBuf::from_string(String::from("")).is_err());
assert!(UpperCamelIdentBuf::from_string(String::from("ValidUpperCamel")).is_ok());
assert!(UpperCamelIdentBuf::from_string(String::from("continuingUpperCamel")).is_err());
assert!(UpperCamelIdentBuf::from_string(String::from("not_validUpperCamel")).is_err());
Source

pub fn insert_fragment( &mut self, idx: usize, fragment: &Fragment<B, D, P>, ) -> Result<(), Error>

Attempts to insert a fragment into the buffer.

§Panics

This function will panic if the byte index is larger than the element’s length, or if it does not fall on a character sequence boundary.

§Errors

On failure to interpret the provided data as a valid fragment (a character does not match the profile, or an unexpected/disallowed delimiter is used) InvalidFormat will be returned, and byte_offset will be set to the index of the invalid character.

If the fragment was valid, but we failed to insert it, InvalidLeftJoin or InvalidRightJoin will be returned, depending on whether the insertion failed because of the data on the left or the right of the join.

If the insertion targeted the beginning of the identifier, but the first character was not a valid identifier start character, then the error kind will be InvalidFormat.

§Examples

Basic Usage:

let mut buffer = UpperCamelIdentBuf::from_str("UpperCamel")?;

// Inserting at the beginning is ~prepend, and thus must be `UpperCamel`.
let mut example = buffer.clone();
assert!(example.insert_fragment(0, UpperCamelFragment::new("Valid")?).is_ok());

// Inserting at the end is ~append, so it must not accidentally produce a `lowerCamel`.
let mut example = buffer.clone();
example.push('_')?;
assert!(example.insert_fragment(example.len(), UpperCamelFragment::new("invalid")?).is_err());
assert!(example.insert_fragment(example.len(), UpperCamelFragment::new("Valid")?).is_ok());

// But note, that if it would simply append an ongoing chunk, that's fine.
let mut example = buffer.clone();
assert!(example.insert_fragment(example.len(), UpperCamelFragment::new("valid")?).is_ok());

// Inserting in the middle is tricky, you must ensure it forms a valid `UpperCamel` ident.
let mut example = buffer.clone();
assert!(example.insert_fragment(2, UpperCamelFragment::new("_")?).is_err());
assert!(example.insert_fragment(5, UpperCamelFragment::new("_")?).is_ok());
Source

pub fn insert_bounded_fragment_with( &mut self, idx: usize, fragment: &Fragment<B, D, P>, delim: D, ) -> Result<(), Error>

Attempts to insert a fragment into the buffer, preserving chunk boundaries by conditionally inserting delimiters where needed.

If the fragment already contains delimiters on both ends, it will always be inserted verbatim.

If the fragment does NOT contain delimiters on both ends, the fragment will first be inserted, and then it will be tested to ensure that both sides of the fragment don’t merge into the surrounding chunks. If it did, a delimiter will be inserted to force separation.

§Panics

This function will panic if the byte index is larger than the element’s length, or if it does not fall on a character sequence boundary.

§Errors

On failure to interpret the provided data as a valid fragment (a character does not match the profile, or an unexpected/disallowed delimiter is used) InvalidFormat will be returned, and byte_offset will be set to the index of the invalid character.

If the fragment was valid, but we failed to insert it, InvalidLeftJoin or InvalidRightJoin will be returned, depending on whether the insertion failed because of the data on the left or the right of the join.

If the insertion targeted the beginning of the identifier, but the first character was not a valid identifier start character, then the error kind will be InvalidFormat.

§Examples

Basic Usage:

let mut buffer = UpperCamelIdentBuf::from_str("UpperCamel")?;

// Inserting a character that needs no separation introduces no delims.
let mut example = buffer.clone();
assert!(example.insert_bounded_fragment(5, UpperCamelFragment::new("Formatted")?).is_ok());
assert_eq!(example, "UpperFormattedCamel");

// Inserting a delimiter works as long as you don't break the formatting.
let mut example = buffer.clone();
assert!(example.insert_bounded_fragment(5, UpperCamelFragment::new("_")?).is_ok());
assert!(example.insert_bounded_fragment(2, UpperCamelFragment::new("_")?).is_err());
assert_eq!(example, "Upper_Camel");

// It's most common to push characters onto the end though.
let mut example = buffer.clone();
assert!(example.insert_bounded_fragment(10, UpperCamelFragment::new("1")?).is_ok());
assert_eq!(example, "UpperCamel_1");
assert!(example.insert_bounded_fragment(12, UpperCamelFragment::new("FRAGMENT")?).is_ok());
assert_eq!(example, "UpperCamel_1_FRAGMENT");

There’s an interesting case where fixing one side makes the other side combine with the chunk to its left (only impacts certain syntaxes).

let mut buffer = CamelIdentBuf::from_str("UpperCamel")?;
assert!(buffer.insert_bounded_str(1, "U").is_ok());
assert_eq!(buffer, "U_U_pperCamel"); // Instead of "UU_pperCamel"
Source

pub fn insert_delimited_fragment_with( &mut self, idx: usize, fragment: &Fragment<B, D, P>, delim: D, ) -> Result<(), Error>

Attempts to insert a fragment into the buffer, preserving chunk boundaries by ensuring a delimiter is present on each side (where needed).

If the fragment already contains delimiters on both ends, it will always be inserted verbatim.

If the fragment does NOT contain delimiters on both ends, then a delimiter will be inserted a number of times depending on how many sides have chunk data immediately next to the insertion point. Finally, the fragment itself will be inserted such that the inserted delimiters will fall on the left or right depending on where they were intended.

§Panics

This function will panic if the byte index is larger than the element’s length, or if it does not fall on a character sequence boundary.

§Errors

On failure to interpret the provided data as a valid fragment (a character does not match the profile, or an unexpected/disallowed delimiter is used) InvalidFormat will be returned, and byte_offset will be set to the index of the invalid character.

If the fragment was valid, but we failed to insert it, InvalidLeftJoin or InvalidRightJoin will be returned, depending on whether the insertion failed because of the data on the left or the right of the join.

If the insertion targeted the beginning of the identifier, but the first character was not a valid identifier start character, then the error kind will be InvalidFormat.

§Examples

Basic Usage:

let mut buffer = UpperCamelIdentBuf::from_str("UpperCamel")?;

// Inserting a character that needs no separation introduces no delims.
let mut example = buffer.clone();
assert!(example.insert_delimited_fragment_with(5, UpperCamelFragment::new("Formatted")?, LowLine).is_ok());
assert_eq!(example, "Upper_Formatted_Camel");

// Inserting a delimiter works as long as you don't break the formatting.
let mut example = buffer.clone();
assert!(example.insert_delimited_fragment_with(5, UpperCamelFragment::new("_")?, LowLine).is_ok());
assert!(example.insert_delimited_fragment_with(2, UpperCamelFragment::new("_")?, LowLine).is_err());
assert_eq!(example, "Upper_Camel");

// It's most common to push characters onto the end though.
let mut example = buffer.clone();
assert!(example.insert_delimited_fragment_with(10, UpperCamelFragment::new("1")?, LowLine).is_ok());
assert_eq!(example, "UpperCamel_1");
assert!(example.insert_delimited_fragment_with(12, UpperCamelFragment::new("Fragment")?, LowLine).is_ok());
assert_eq!(example, "UpperCamel_1_Fragment");
Source

pub fn push_delim_with(&mut self, delim: D) -> Result<(), Error>

Attempts to push a delimiter into the buffer.

§Errors

If the delimiter itself was valid, but not at the position pushed, then InvalidPosition will be returned.

If the insertion targeted the beginning of the identifier, but the first character was not a valid identifier start character, then the error kind will be InvalidFormat.

§Examples

Basic Usage:

let mut buffer = UpperCamelIdentBuf::new();

// For all preset and provided delimiters, you can push them anywhere in
// an identifier. Unless you have a custom delimiter, it's always safe to push.
assert!(buffer.push_delim_with(LowLine).is_ok());

Example Failure:

#[derive(Copy, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
struct DollarStart;

impl Delimiter for DollarStart {
    fn as_char(&self) -> char {
        '$'
    }
    fn from_ident_start(c: char) -> Option<Self> {
        match c {
            '$' => Some(Self),
            _ => None,
        }
    }
    fn from_chunk_delim(c: char) -> Option<Self> {
        None
    }
}

type DollarStartIdentBuf = IdentBuf<
    boundary::Standard,
    DollarStart,
    profile::Unicode,
>;

let mut buffer = DollarStartIdentBuf::new();

// Okay to push one `$` in, because it may be the start fragment.
assert!(buffer.push_delim_with(DollarStart).is_ok());

// But you definitely cannot push another in - that's invalid.
assert!(buffer.push_delim_with(DollarStart).is_err());
Source

pub fn remove(&mut self, idx: usize) -> Result<(), Error>

Removes a character from the buffer at a given index.

§Panics

This function will panic if the byte index is larger than the element’s length, or if it does not fall on a character sequence boundary.

§Errors

If the removal of the character at the provided index would lead to an invalid buffer, then the character will not be remove and instead the error FailedRemove will be returned.

§Examples

Basic Usage:

let mut buffer = UpperCamelFragmentBuf::from_str("Upper_Camel")?;

// This would be valid, because it might be a continuation fragment.
assert!(buffer.remove(0).is_ok());
assert_eq!(buffer, "pper_Camel");

// However, attempting to remove `C` would fail for `UpperCamel`.
assert!(buffer.remove(5).is_err());
assert_eq!(buffer, "pper_Camel");
Source

pub fn replace_range_fragment<R>( &mut self, range: R, replace_with: &Fragment<B, D, P>, ) -> Result<(), Error>
where R: RangeBounds<usize>,

Replace a range of characters with a provided replacement.

§Panics

This function will panic if the byte index is larger than the element’s length, or if it does not fall on a character sequence boundary.

§Errors

If the replacement of the range provided with the given fragment would lead to an invalid buffer, then the range will not be remove and instead the error InvalidReplace will be returned.

If the insertion targeted the beginning of the identifier, but the first character was not a valid identifier start character, then the error kind will be InvalidFormat.

§Examples

Basic Usage:

let buffer = UpperCamelIdentBuf::from_str("Upper_Camel")?;

// Examples replacing various ranges.
let replacement = UpperCamelFragment::new("R")?;
let mut example = buffer.clone();
assert!(example.replace_range_fragment(4..7, replacement).is_ok());
assert_eq!(example, "UppeRamel");

let mut example = buffer.clone();
assert!(example.replace_range_fragment(4..=7, replacement).is_ok());
assert_eq!(example, "UppeRmel");

let mut example = buffer.clone();
assert!(example.replace_range_fragment(..7, replacement).is_ok());
assert_eq!(example, "Ramel");

let mut example = buffer.clone();
assert!(example.replace_range_fragment(..=7, replacement).is_ok());
assert_eq!(example, "Rmel");

let mut example = buffer.clone();
assert!(example.replace_range_fragment(4.., replacement).is_ok());
assert_eq!(example, "UppeR");
Source

pub fn split_off(&mut self, idx: usize) -> FragmentBuf<B, D, P>

Splits the buffer into two halves at a given byte index.

Returns a newly allocated buffer. self contains bytes [0, at), and the returned buffer contains bytes [at, len). at must be on the boundary of a UTF-8 code point.

Note that the capacity of self does not change.

§Panics

This function will panic if the byte index is larger than the element’s length, or if it does not fall on a character sequence boundary.

§Examples

Basic Usage:

let mut buffer = UpperCamelIdentBuf::from_str("UpperCamel")?;
let split = buffer.split_off(5);
assert_eq!(buffer, "Upper");
assert_eq!(split, "Camel");
Source§

impl<B, D, P> IdentBuf<B, D, P>

Source

pub fn as_ident(&self) -> Option<&Ident<B, D, P>>

Fallibly casts the buffer to an identifier.

This can fail because the buffer can be empty. As long as the buffer is not empty, than this will succeed (because this type enforces that what is added to the buffer conforms to the requirements of a valid identifier).

§Examples

Basic Usage:

let mut buffer = LowerCamelIdentBuf::new();
assert_eq!(buffer.as_ident(), None);

buffer.push_str("ident")?;
assert_eq!(buffer.as_ident(), Some(LowerCamelIdent::new("ident")?));
Source

pub fn as_ident_or<'a>( &'a self, default: &'a Ident<B, D, P>, ) -> &'a Ident<B, D, P>

Either returns the identifier contained by this buffer (if non-empty), or return the provided default identifier.

This is equivalent to as_ident().unwrap_or(_), but it’s provided for convenience and to parallel the as_ident_or_anonymous.

§Examples

Basic Usage:

let fallback = LowerCamelIdent::new("fallback")?;
let mut buffer = LowerCamelIdentBuf::new();
assert_eq!(buffer.as_ident_or(fallback), fallback);

buffer.push_str("ident")?;
assert_eq!(buffer.as_ident_or(fallback), "ident");
Source

pub fn as_ident_or_anonymous(&self) -> &Ident<B, D, P>
where D: UnitDelimiter,

Either returns the identifier contained by this buffer (if non-empty), or return a single delimiter representing an anonymous value.

This can only be called if it’s obvious which delimiter should be provided, and that is only possible for UnitDelimiter delimiters (Like LowLine and HyphenMinus).

§Examples

Basic Usage:

let mut buffer = LowerCamelIdentBuf::new();
assert_eq!(buffer.as_ident_or_anonymous(), "_");

buffer.push_str("ident")?;
assert_eq!(buffer.as_ident_or_anonymous(), "ident");
Source

pub fn from_ident(orig: &Ident<B, D, P>) -> Self

Converts an ident into an ident buffer.

§Examples
let ident = UpperCamelIdent::new("Example")?;
let mut buffer = UpperCamelIdentBuf::from_ident(ident);
assert_eq!(buffer, "Example");
Source

pub fn into_boxed_ident(self) -> Option<Box<Ident<B, D, P>>>

Convert the buffer into a boxed identifier (if possible).

This can fail if the buffer is empty.

§Examples
let mut buffer = HybridIdentBuf::from_str("example")?;
let boxed: Box<HybridIdent> = buffer.into_boxed_ident().unwrap();
assert_eq!(boxed.as_ref(), "example");
Source

pub fn into_string(self) -> String

Convert the buffer into an owned string.

§Examples
let buffer = UpperCamelIdentBuf::from_str("Example")?;
let string: String = buffer.into_string();
assert_eq!(string, "Example");
Source

pub fn leak<'a>(self) -> Option<&'a Ident<B, D, P>>

Leaks the identifier so that it lives for the rest of the execution of the program.

This can fail if the buffer is empty.

This is a typed wrapper over the String::leak method.

§Examples
let fragment = UpperCamelIdentBuf::from_str("Example")?;
let string: &'static UpperCamelFragment = fragment.leak().unwrap();
Source

pub fn with_capacity(capacity: usize) -> Self

Constructs an empty ident buffer with an initial capacity.

This has the same properties as String::with_capacity.

§Examples
let buffer = UpperCamelIdentBuf::with_capacity(10);
assert!(buffer.capacity() >= 10);
Source

pub fn with_overhead(ident: &Ident<B, D, P>, additional: usize) -> Self

Constructs an ident buffer with enough space to hold the provided ident, as well as additional bytes, then initializes the contents of this buffer to ident.

§Examples
let ident = UpperCamelIdent::new("Example")?;
let buffer = UpperCamelIdentBuf::with_overhead(ident, 20);
assert!(buffer.capacity() >= 27);
assert_eq!(buffer, "Example");
Source§

impl<B: Boundary, D: Delimiter, P: Profile> IdentBuf<B, D, P>

Source

pub fn insert(&mut self, idx: usize, c: char) -> Result<(), Error>

Attempts to insert a character into the buffer.

§Unicode Warning

If you are working with Unicode data, you very likely don’t want this function. Instead, you likely want to insert an entire grapheme. Inserting one character from a grapheme bounded, and then inserting other characters unbounded could change the decision for whether or not a grapheme cluster bounds on the left or right.

This function really only works as one would expect if the grapheme cluster is exactly one character big (for example, ASCII data has this property).

§Panics

This function will panic if the byte index is larger than the element’s length, or if it does not fall on a character sequence boundary.

§Errors

On failure to interpret the provided data as a valid fragment (a character does not match the profile, or an unexpected/disallowed delimiter is used) InvalidFormat will be returned, and byte_offset will be set to the index of the invalid character.

If the fragment was valid, but we failed to insert it, InvalidLeftJoin or InvalidRightJoin will be returned, depending on whether the insertion failed because of the data on the left or the right of the join.

§Examples

Basic Usage:

let mut buffer = UpperCamelIdentBuf::from_str("UpperCamel")?;

// Inserting at the beginning is ~prepend.
let mut example = buffer.clone();
assert!(example.insert(0, 'V').is_ok());
assert!(example.insert(0, '_').is_ok());
assert_eq!(example, "_VUpperCamel");

// Inserting at the end is ~append.
let mut example = buffer.clone();
example.push('_')?;
assert!(example.insert(example.len(), 'i').is_err());
assert!(example.insert(example.len(), 'V').is_ok());
assert_eq!(example, "UpperCamel_V");

// Inserting in the middle can be tricky, as your insertions
// may invalidate the buffer's invariants in surprising ways.
let mut example = buffer.clone();
assert!(example.insert(2, '_').is_err()); // "Up_perCamel" != UpperCamel casing
assert!(example.insert(5, '_').is_ok());
assert_eq!(example, "Upper_Camel");
Source

pub fn insert_bounded(&mut self, idx: usize, c: char) -> Result<(), Error>
where D: Default,

Attempts to insert a character into the buffer, preserving chunk boundaries by conditionally inserting delimiters where needed.

If the character is a delimiter, it will always be inserted verbatim.

If the character is NOT a delimiter, the character will first be inserted, and then it will be tested to ensure that both sides of the character don’t merge into the surrounding chunks. If it did, a delimiter will be inserted to force separation.

§Unicode Warning

If you are working with Unicode data, you very likely don’t want this function. Instead, you likely want to insert an entire grapheme. Inserting one character from a grapheme bounded, and then inserting other characters unbounded could change the decision for whether or not a grapheme cluster bounds on the left or right.

This function really only works as one would expect if the grapheme cluster is exactly one character big (for example, ASCII data has this property).

§Panics

This function will panic if the byte index is larger than the element’s length, or if it does not fall on a character sequence boundary.

§Errors

On failure to interpret the provided data as a valid fragment (a character does not match the profile, or an unexpected/disallowed delimiter is used) InvalidFormat will be returned, and byte_offset will be set to the index of the invalid character.

If the fragment was valid, but we failed to insert it, InvalidLeftJoin or InvalidRightJoin will be returned, depending on whether the insertion failed because of the data on the left or the right of the join.

§Examples

Basic Usage:

let mut buffer = UpperCamelIdentBuf::from_str("UpperCamel")?;

// Inserting at the beginning is ~prepend.
let mut example = buffer.clone();
assert!(example.insert_bounded(0, 'V').is_ok()); // Bounded because of `HAT` rules.
assert!(example.insert_bounded(0, 'V').is_ok()); // But another `V` would not be.
assert_eq!(example, "V_VUpperCamel");

// Inserting at the end is ~append.
let mut example = buffer.clone();
assert!(example.insert_bounded(example.len(), 'i').is_err()); // "UpperCamel_i" != UpperCamel casing
assert!(example.insert_bounded(example.len(), 'V').is_ok()); // Because of `CAMEL` boundary.
assert_eq!(example, "UpperCamelV");

// Inserting in the middle can be tricky, as your insertions
// may invalidate the buffer's invariants in surprising ways.
let mut example = buffer.clone();
assert!(example.insert_bounded(2, 'V').is_err()); // "Up_V_perCamel" != UpperCamel casing
assert!(example.insert_bounded(5, 'V').is_ok()); // Surprisingly a `CAMEL` & `HAT` boundary.
assert_eq!(example, "UpperVCamel");
Source

pub fn insert_bounded_with( &mut self, idx: usize, c: char, delim: D, ) -> Result<(), Error>

Attempts to insert a character into the buffer, preserving chunk boundaries by conditionally inserting delimiters where needed.

If the character is a delimiter, it will always be inserted verbatim.

If the character is NOT a delimiter, the character will first be inserted, and then it will be tested to ensure that both sides of the character don’t merge into the surrounding chunks. If it did, a delimiter will be inserted to force separation.

§Unicode Warning

If you are working with Unicode data, you very likely don’t want this function. Instead, you likely want to insert an entire grapheme. Inserting one character from a grapheme bounded, and then inserting other characters unbounded could change the decision for whether or not a grapheme cluster bounds on the left or right.

This function really only works as one would expect if the grapheme cluster is exactly one character big (for example, ASCII data has this property).

§Panics

This function will panic if the byte index is larger than the element’s length, or if it does not fall on a character sequence boundary.

§Errors

On failure to interpret the provided data as a valid fragment (a character does not match the profile, or an unexpected/disallowed delimiter is used) InvalidFormat will be returned, and byte_offset will be set to the index of the invalid character.

If the fragment was valid, but we failed to insert it, InvalidLeftJoin or InvalidRightJoin will be returned, depending on whether the insertion failed because of the data on the left or the right of the join.

§Examples

Basic Usage:

let mut buffer = UpperCamelIdentBuf::from_str("UpperCamel")?;

// Inserting at the beginning is ~prepend.
let mut example = buffer.clone();
assert!(example.insert_bounded_with(0, 'V', LowLine).is_ok()); // Bounded because of `HAT` rules.
assert!(example.insert_bounded_with(0, 'V', LowLine).is_ok()); // But another `V` would not be.
assert_eq!(example, "V_VUpperCamel");

// Inserting at the end is ~append.
let mut example = buffer.clone();
assert!(example.insert_bounded_with(example.len(), 'i', LowLine).is_err()); // "UpperCamel_i" != UpperCamel casing
assert!(example.insert_bounded_with(example.len(), 'V', LowLine).is_ok()); // Because of `CAMEL` boundary.
assert_eq!(example, "UpperCamelV");

// Inserting in the middle can be tricky, as your insertions
// may invalidate the buffer's invariants in surprising ways.
let mut example = buffer.clone();
assert!(example.insert_bounded_with(2, 'V', LowLine).is_err()); // "Up_V_perCamel" != UpperCamel casing
assert!(example.insert_bounded_with(5, 'V', LowLine).is_ok()); // Surprisingly a `CAMEL` & `HAT` boundary.
assert_eq!(example, "UpperVCamel");
Source

pub fn insert_delim(&mut self, idx: usize) -> Result<(), Error>
where D: Default,

Attempts to insert a delimiter into the buffer.

§Panics

This function will panic if the byte index is larger than the element’s length, or if it does not fall on a character sequence boundary.

§Errors

If the delimiter itself was valid, but not at the position inserted, then InvalidPosition will be returned.

If inserting the provided delimiter at a position idx would lead to an invalid fragment, then the error InvalidInsertion will be returned, containing either Direction::Left or Direction::Right for whether the insertion failed because of the data on the left or the right.

§Examples

Basic Usage:

let mut buffer = UpperCamelIdentBuf::from_str("UpperCamel")?;

// Inserting at the beginning is ~prepend.
let mut example = buffer.clone();
assert!(example.insert_delim(0).is_ok());
assert_eq!(example, "_UpperCamel");

// Inserting at the end is ~append.
let mut example = buffer.clone();
assert!(example.insert_delim(example.len()).is_ok());
assert_eq!(example, "UpperCamel_");

// Inserting in the middle can be tricky, as your insertions
// may invalidate the buffer's invariants in surprising ways.
let mut example = buffer.clone();
assert!(example.insert_delim(2).is_err()); // "Up_perCamel" != UpperCamel casing
assert!(example.insert_delim(5).is_ok());
assert_eq!(example, "Upper_Camel");
Source

pub fn insert_delim_with(&mut self, idx: usize, delim: D) -> Result<(), Error>

Attempts to insert a delimiter into the buffer.

§Panics

This function will panic if the byte index is larger than the element’s length, or if it does not fall on a character sequence boundary.

§Errors

If the delimiter itself was valid, but not at the position inserted, then InvalidPosition will be returned.

If inserting the provided delimiter at a position idx would lead to an invalid fragment, then the error InvalidInsertion will be returned, containing either Direction::Left or Direction::Right for whether the insertion failed because of the data on the left or the right.

§Examples

Basic Usage:

let mut buffer = UpperCamelIdentBuf::from_str("UpperCamel")?;

// Inserting at the beginning is ~prepend.
let mut example = buffer.clone();
assert!(example.insert_delim_with(0, LowLine).is_ok());
assert_eq!(example, "_UpperCamel");

// Inserting at the end is ~append.
let mut example = buffer.clone();
assert!(example.insert_delim_with(example.len(), LowLine).is_ok());
assert_eq!(example, "UpperCamel_");

// Inserting in the middle can be tricky, as your insertions
// may invalidate the buffer's invariants in surprising ways.
let mut example = buffer.clone();
assert!(example.insert_delim_with(2, LowLine).is_err()); // "Up_perCamel" != UpperCamel casing
assert!(example.insert_delim_with(5, LowLine).is_ok());
assert_eq!(example, "Upper_Camel");
Source

pub fn insert_delimited(&mut self, idx: usize, c: char) -> Result<(), Error>
where D: Default,

Attempts to insert a character into the buffer, preserving chunk boundaries by ensuring a delimiter is present on each side (where needed).

If the character is a delimiter, it will always be inserted verbatim.

If the character is NOT a delimiter, then a delimiter will be inserted a number of times depending on how many sides have chunk data immediately next to the insertion point. Finally, the character itself will be inserted such that the inserted delimiters will fall on the left or right depending on where they were intended.

§Panics

This function will panic if the byte index is larger than the element’s length, or if it does not fall on a character sequence boundary.

§Errors

On failure to interpret the provided data as a valid fragment (a character does not match the profile, or an unexpected/disallowed delimiter is used) InvalidFormat will be returned, and byte_offset will be set to the index of the invalid character.

If the fragment was valid, but we failed to insert it, InvalidLeftJoin or InvalidRightJoin will be returned, depending on whether the insertion failed because of the data on the left or the right of the join.

§Examples

Basic Usage:

let mut buffer = UpperCamelIdentBuf::from_str("UpperCamel")?;

// Inserting at the beginning is ~prepend.
let mut example = buffer.clone();
assert!(example.insert_delimited(0, 'V').is_ok());
assert_eq!(example, "V_UpperCamel");

// Inserting at the end is ~append.
let mut example = buffer.clone();
assert!(example.insert_delimited(example.len(), 'i').is_err()); // "UpperCamel_i" != UpperCamel casing
assert!(example.insert_delimited(example.len(), 'V').is_ok());
assert_eq!(example, "UpperCamel_V");

// Inserting in the middle can be tricky, as your insertions
// may invalidate the buffer's invariants in surprising ways.
let mut example = buffer.clone();
assert!(example.insert_delimited(2, 'V').is_err()); // "Up_V_perCamel" != UpperCamel casing
assert!(example.insert_delimited(5, 'V').is_ok());
assert_eq!(example, "Upper_V_Camel");
Source

pub fn insert_delimited_with( &mut self, idx: usize, c: char, delim: D, ) -> Result<(), Error>

Attempts to insert a character into the buffer, preserving chunk boundaries by ensuring a delimiter is present on each side (where needed).

If the character is a delimiter, it will always be inserted verbatim.

If the character is NOT a delimiter, then a delimiter will be inserted a number of times depending on how many sides have chunk data immediately next to the insertion point. Finally, the character itself will be inserted such that the inserted delimiters will fall on the left or right depending on where they were intended.

§Panics

This function will panic if the byte index is larger than the element’s length, or if it does not fall on a character sequence boundary.

§Errors

On failure to interpret the provided data as a valid fragment (a character does not match the profile, or an unexpected/disallowed delimiter is used) InvalidFormat will be returned, and byte_offset will be set to the index of the invalid character.

If the fragment was valid, but we failed to insert it, InvalidLeftJoin or InvalidRightJoin will be returned, depending on whether the insertion failed because of the data on the left or the right of the join.

§Examples

Basic Usage:

let mut buffer = UpperCamelIdentBuf::from_str("UpperCamel")?;

// Inserting at the beginning is ~prepend.
let mut example = buffer.clone();
assert!(example.insert_delimited_with(0, 'V', LowLine).is_ok());
assert_eq!(example, "V_UpperCamel");

// Inserting at the end is ~append.
let mut example = buffer.clone();
assert!(example.insert_delimited_with(example.len(), 'i', LowLine).is_err()); // "UpperCamel_i" != UpperCamel casing
assert!(example.insert_delimited_with(example.len(), 'V', LowLine).is_ok());
assert_eq!(example, "UpperCamel_V");

// Inserting in the middle can be tricky, as your insertions
// may invalidate the buffer's invariants in surprising ways.
let mut example = buffer.clone();
assert!(example.insert_delimited_with(2, 'V', LowLine).is_err()); // "Up_V_perCamel" != UpperCamel casing
assert!(example.insert_delimited_with(5, 'V', LowLine).is_ok());
assert_eq!(example, "Upper_V_Camel");
Source

pub fn insert_bounded_fragment( &mut self, idx: usize, fragment: &Fragment<B, D, P>, ) -> Result<(), Error>
where D: Default,

Attempts to insert a fragment into the buffer, preserving chunk boundaries by conditionally inserting delimiters where needed.

If the fragment already contains delimiters on both ends, it will always be inserted verbatim.

If the fragment does NOT contain delimiters on both ends, the fragment will first be inserted, and then it will be tested to ensure that both sides of the fragment don’t merge into the surrounding chunks. If it did, a delimiter will be inserted to force separation.

§Panics

This function will panic if the byte index is larger than the element’s length, or if it does not fall on a character sequence boundary.

§Errors

On failure to interpret the provided data as a valid fragment (a character does not match the profile, or an unexpected/disallowed delimiter is used) InvalidFormat will be returned, and byte_offset will be set to the index of the invalid character.

If the fragment was valid, but we failed to insert it, InvalidLeftJoin or InvalidRightJoin will be returned, depending on whether the insertion failed because of the data on the left or the right of the join.

§Examples

Basic Usage:

let mut buffer = UpperCamelIdentBuf::from_str("UpperCamel")?;

// Inserting at the beginning is ~prepend.
let mut example = buffer.clone();
assert!(example.insert_bounded_fragment(
    0,
    UpperCamelFragment::new("HAT")?).is_ok()
); // Bounded because of `HAT` rules.
assert!(example.insert_bounded_fragment(
    0,
    UpperCamelFragment::new("HAT")?).is_ok()
); // But another would not be.
assert_eq!(example, "HAT_HATUpperCamel");

// Inserting at the end is ~append.
let mut example = buffer.clone();
assert!(example.insert_bounded_fragment(
    example.len(),
    UpperCamelFragment::new("lower")?).is_err()
); // "UpperCamel_lower" != UpperCamel casing
assert!(example.insert_bounded_fragment(
    example.len(),
    UpperCamelFragment::new("Camel")?).is_ok()
); // Because of `CAMEL` boundary.
assert_eq!(example, "UpperCamelCamel");

// Inserting in the middle can be tricky, as your insertions
// may invalidate the buffer's invariants in surprising ways.
let mut example = buffer.clone();
assert!(example.insert_bounded_fragment(
    2,
    UpperCamelFragment::new("HAT")?).is_err()
); // "UpHAT_perCamel" != UpperCamel casing
assert!(example.insert_bounded_fragment(
    5,
    UpperCamelFragment::new("HAT")?).is_ok()
); // Surprisingly a `CAMEL` & `HAT` boundary.
assert_eq!(example, "UpperHATCamel");
Source

pub fn insert_delimited_fragment( &mut self, idx: usize, fragment: &Fragment<B, D, P>, ) -> Result<(), Error>
where D: Default,

Attempts to insert a fragment into the buffer, preserving chunk boundaries by ensuring a delimiter is present on each side (where needed).

If the fragment already contains delimiters on both ends, it will always be inserted verbatim.

If the fragment does NOT contain delimiters on both ends, then a delimiter will be inserted a number of times depending on how many sides have chunk data immediately next to the insertion point. Finally, the fragment itself will be inserted such that the inserted delimiters will fall on the left or right depending on where they were intended.

§Panics

This function will panic if the byte index is larger than the element’s length, or if it does not fall on a character sequence boundary.

§Errors

On failure to interpret the provided data as a valid fragment (a character does not match the profile, or an unexpected/disallowed delimiter is used) InvalidFormat will be returned, and byte_offset will be set to the index of the invalid character.

If the fragment was valid, but we failed to insert it, InvalidLeftJoin or InvalidRightJoin will be returned, depending on whether the insertion failed because of the data on the left or the right of the join.

§Examples

Basic Usage:

let mut buffer = UpperCamelIdentBuf::from_str("UpperCamel")?;

// Inserting at the beginning is ~prepend.
let mut example = buffer.clone();
assert!(example.insert_delimited_fragment(
    0,
    UpperCamelFragment::new("HAT")?).is_ok()
);
assert_eq!(example, "HAT_UpperCamel");

// Inserting at the end is ~append.
let mut example = buffer.clone();
assert!(example.insert_delimited_fragment(
    example.len(),
    UpperCamelFragment::new("lower")?).is_err()
); // "Upper_Camel_lower" != UpperCamel casing
assert!(example.insert_delimited_fragment(
    example.len(),
    UpperCamelFragment::new("Camel")?).is_ok()
);
assert_eq!(example, "UpperCamel_Camel");

// Inserting in the middle can be tricky, as your insertions
// may invalidate the buffer's invariants in surprising ways.
let mut example = buffer.clone();
assert!(example.insert_delimited_fragment(
    2,
    UpperCamelFragment::new("HAT")?).is_err()
); // "Up_HAT_perCamel" != UpperCamel casing
assert!(example.insert_delimited_fragment(
    5,
    UpperCamelFragment::new("HAT")?).is_ok()
); // Surprisingly a `CAMEL` & `HAT` boundary.
assert_eq!(example, "Upper_HAT_Camel");
Source

pub fn insert_str(&mut self, idx: usize, s: &str) -> Result<(), Error>

Attempts to insert a string slice into the buffer.

This will first convert the string slice to a fragment, and then attempting to insert the fragment (it is equivalent to first calling Fragment::new on your input, then calling the fragment-equivalent version of this function instead).

§Panics

This function will panic if the byte index is larger than the element’s length, or if it does not fall on a character sequence boundary.

§Errors

On failure to interpret the provided data as a valid fragment (a character does not match the profile, or an unexpected/disallowed delimiter is used) InvalidFormat will be returned, and byte_offset will be set to the index of the invalid character.

If the fragment was valid, but we failed to insert it, InvalidLeftJoin or InvalidRightJoin will be returned, depending on whether the insertion failed because of the data on the left or the right of the join.

§Examples

Basic Usage:

let mut buffer = UpperCamelIdentBuf::from_str("UpperCamel")?;

// Inserting at the beginning is ~prepend.
let mut example = buffer.clone();
assert!(example.insert_str(0, "HAT").is_ok());
assert_eq!(example, "HATUpperCamel");

// Inserting at the end is ~append.
let mut example = buffer.clone();
assert!(example.insert_str(example.len(),"lower").is_ok());
assert!(example.insert_str(example.len(),"Camel").is_ok());
assert_eq!(example, "UpperCamellowerCamel");

// Inserting in the middle can be tricky, as your insertions
// may invalidate the buffer's invariants in surprising ways.
let mut example = buffer.clone();
assert!(example.insert_str(2,"HAT_").is_err()); // "UpHAT_perCamel" != UpperCamel casing
assert!(example.insert_str(5,"HAT").is_ok());
assert_eq!(example, "UpperHATCamel");
Source

pub fn insert_bounded_str(&mut self, idx: usize, s: &str) -> Result<(), Error>
where D: Default,

Attempts to insert a string slice into the buffer, preserving chunk boundaries by conditionally inserting delimiters where needed.

This will first convert the string slice to a fragment, and then attempting to insert the fragment (it is equivalent to first calling Fragment::new on your input, then calling the fragment-equivalent version of this function instead).

If the fragment already contains delimiters on both ends, it will always be inserted verbatim.

If the fragment does NOT contain delimiters on both ends, the fragment will first be inserted, and then it will be tested to ensure that both sides of the fragment don’t merge into the surrounding chunks. If it did, a delimiter will be inserted to force separation.

§Panics

This function will panic if the byte index is larger than the element’s length, or if it does not fall on a character sequence boundary.

§Errors

On failure to interpret the provided data as a valid fragment (a character does not match the profile, or an unexpected/disallowed delimiter is used) InvalidFormat will be returned, and byte_offset will be set to the index of the invalid character.

If the fragment was valid, but we failed to insert it, InvalidLeftJoin or InvalidRightJoin will be returned, depending on whether the insertion failed because of the data on the left or the right of the join.

§Examples

Basic Usage:

let mut buffer = UpperCamelIdentBuf::from_str("UpperCamel")?;

// Inserting at the beginning is ~prepend.
let mut example = buffer.clone();
assert!(example.insert_bounded_str(0, "HAT").is_ok()); // Bounded because of `HAT` rules.
assert!(example.insert_bounded_str(0, "HAT").is_ok()); // But another would not be.
assert_eq!(example, "HAT_HATUpperCamel");

// Inserting at the end is ~append.
let mut example = buffer.clone();
assert!(example.insert_bounded_str(example.len(), "lower").is_err()); // "UpperCamel_lower" != UpperCamel casing
assert!(example.insert_bounded_str(example.len(), "Camel").is_ok()); // Because of `CAMEL` boundary.
assert_eq!(example, "UpperCamelCamel");

// Inserting in the middle can be tricky, as your insertions
// may invalidate the buffer's invariants in surprising ways.
let mut example = buffer.clone();
assert!(example.insert_bounded_str(2, "HAT").is_err()); // "UpHAT_perCamel" != UpperCamel casing
assert!(example.insert_bounded_str(5, "HAT").is_ok()); // Surprisingly a `CAMEL` & `HAT` boundary.
assert_eq!(example, "UpperHATCamel");
Source

pub fn insert_bounded_str_with( &mut self, idx: usize, s: &str, delim: D, ) -> Result<(), Error>

Attempts to insert a string slice into the buffer, preserving chunk boundaries by conditionally inserting delimiters where needed.

This will first convert the string slice to a fragment, and then attempting to insert the fragment (it is equivalent to first calling Fragment::new on your input, then calling the fragment-equivalent version of this function instead).

If the fragment already contains delimiters on both ends, it will always be inserted verbatim.

If the fragment does NOT contain delimiters on both ends, the fragment will first be inserted, and then it will be tested to ensure that both sides of the fragment don’t merge into the surrounding chunks. If it did, a delimiter will be inserted to force separation.

§Panics

This function will panic if the byte index is larger than the element’s length, or if it does not fall on a character sequence boundary.

§Errors

On failure to interpret the provided data as a valid fragment (a character does not match the profile, or an unexpected/disallowed delimiter is used) InvalidFormat will be returned, and byte_offset will be set to the index of the invalid character.

If the fragment was valid, but we failed to insert it, InvalidLeftJoin or InvalidRightJoin will be returned, depending on whether the insertion failed because of the data on the left or the right of the join.

§Examples

Basic Usage:

let mut buffer = UpperCamelIdentBuf::from_str("UpperCamel")?;

// Inserting at the beginning is ~prepend.
let mut example = buffer.clone();
assert!(example.insert_bounded_str_with(0, "HAT", LowLine).is_ok()); // Bounded because of `HAT` rules.
assert!(example.insert_bounded_str_with(0, "HAT", LowLine).is_ok()); // But another would not be.
assert_eq!(example, "HAT_HATUpperCamel");

// Inserting at the end is ~append.
let mut example = buffer.clone();
assert!(example.insert_bounded_str_with(example.len(), "lower", LowLine).is_err()); // "UpperCamel_lower" != UpperCamel casing
assert!(example.insert_bounded_str_with(example.len(), "Camel", LowLine).is_ok()); // Because of `CAMEL` boundary.
assert_eq!(example, "UpperCamelCamel");

// Inserting in the middle can be tricky, as your insertions
// may invalidate the buffer's invariants in surprising ways.
let mut example = buffer.clone();
assert!(example.insert_bounded_str_with(2, "HAT", LowLine).is_err()); // "UpHAT_perCamel" != UpperCamel casing
assert!(example.insert_bounded_str_with(5, "HAT", LowLine).is_ok()); // Surprisingly a `CAMEL` & `HAT` boundary.
assert_eq!(example, "UpperHATCamel");
Source

pub fn insert_delimited_str(&mut self, idx: usize, s: &str) -> Result<(), Error>
where D: Default,

Attempts to insert a string slice into the buffer, preserving chunk boundaries by ensuring a delimiter is present on each side (where needed).

This will first convert the string slice to a fragment, and then attempting to insert the fragment (it is equivalent to first calling Fragment::new on your input, then calling the fragment-equivalent version of this function instead).

If the fragment already contains delimiters on both ends, it will always be inserted verbatim.

If the fragment does NOT contain delimiters on both ends, then a delimiter will be inserted a number of times depending on how many sides have chunk data immediately next to the insertion point. Finally, the fragment itself will be inserted such that the inserted delimiters will fall on the left or right depending on where they were intended.

§Panics

This function will panic if the byte index is larger than the element’s length, or if it does not fall on a character sequence boundary.

§Errors

On failure to interpret the provided data as a valid fragment (a character does not match the profile, or an unexpected/disallowed delimiter is used) InvalidFormat will be returned, and byte_offset will be set to the index of the invalid character.

If the fragment was valid, but we failed to insert it, InvalidLeftJoin or InvalidRightJoin will be returned, depending on whether the insertion failed because of the data on the left or the right of the join.

§Examples

Basic Usage:

let mut buffer = UpperCamelIdentBuf::from_str("UpperCamel")?;

// Inserting at the beginning is ~prepend.
let mut example = buffer.clone();
assert!(example.insert_delimited_str(0, "HAT").is_ok());
assert_eq!(example, "HAT_UpperCamel");

// Inserting at the end is ~append.
let mut example = buffer.clone();
assert!(example.insert_delimited_str(example.len(), "lower").is_err()); // "UpperCamel_lower" != UpperCamel casing
assert!(example.insert_delimited_str(example.len(), "Camel").is_ok());
assert_eq!(example, "UpperCamel_Camel");

// Inserting in the middle can be tricky, as your insertions
// may invalidate the buffer's invariants in surprising ways.
let mut example = buffer.clone();
assert!(example.insert_delimited_str(2, "HAT").is_err()); // "Up_HAT_perCamel" != UpperCamel casing
assert!(example.insert_delimited_str(5, "HAT").is_ok());
assert_eq!(example, "Upper_HAT_Camel");
Source

pub fn insert_delimited_str_with( &mut self, idx: usize, s: &str, delim: D, ) -> Result<(), Error>

Attempts to insert a string slice into the buffer, preserving chunk boundaries by ensuring a delimiter is present on each side (where needed).

This will first convert the string slice to a fragment, and then attempting to insert the fragment (it is equivalent to first calling Fragment::new on your input, then calling the fragment-equivalent version of this function instead).

If the fragment already contains delimiters on both ends, it will always be inserted verbatim.

If the fragment does NOT contain delimiters on both ends, then a delimiter will be inserted a number of times depending on how many sides have chunk data immediately next to the insertion point. Finally, the fragment itself will be inserted such that the inserted delimiters will fall on the left or right depending on where they were intended.

§Panics

This function will panic if the byte index is larger than the element’s length, or if it does not fall on a character sequence boundary.

§Errors

On failure to interpret the provided data as a valid fragment (a character does not match the profile, or an unexpected/disallowed delimiter is used) InvalidFormat will be returned, and byte_offset will be set to the index of the invalid character.

If the fragment was valid, but we failed to insert it, InvalidLeftJoin or InvalidRightJoin will be returned, depending on whether the insertion failed because of the data on the left or the right of the join.

§Examples

Basic Usage:

let mut buffer = UpperCamelIdentBuf::from_str("UpperCamel")?;

// Inserting at the beginning is ~prepend.
let mut example = buffer.clone();
assert!(example.insert_delimited_str_with(0, "HAT", LowLine).is_ok());
assert_eq!(example, "HAT_UpperCamel");

// Inserting at the end is ~append.
let mut example = buffer.clone();
assert!(example.insert_delimited_str_with(example.len(), "lower", LowLine).is_err()); // "UpperCamel_lower" != UpperCamel casing
assert!(example.insert_delimited_str_with(example.len(), "Camel", LowLine).is_ok());
assert_eq!(example, "UpperCamel_Camel");

// Inserting in the middle can be tricky, as your insertions
// may invalidate the buffer's invariants in surprising ways.
let mut example = buffer.clone();
assert!(example.insert_delimited_str_with(2, "HAT", LowLine).is_err()); // "Up_HAT_perCamel" != UpperCamel casing
assert!(example.insert_delimited_str_with(5, "HAT", LowLine).is_ok());
assert_eq!(example, "Upper_HAT_Camel");
Source

pub fn push(&mut self, c: char) -> Result<(), Error>

Attempts to push a character to the buffer.

§Errors

On failure to interpret the provided data as a valid fragment (a character does not match the profile, or an unexpected/disallowed delimiter is used) InvalidFormat will be returned, and byte_offset will be set to the index of the invalid character.

If the fragment was valid, but we failed to insert it, InvalidLeftJoin or InvalidRightJoin will be returned, depending on whether the insertion failed because of the data on the left or the right of the join.

§Examples

Basic Usage:

let mut buffer = UpperCamelIdentBuf::new();

// You can only push characters that are valid at the given position.
assert!(buffer.push('O').is_ok());
assert!(buffer.push('k').is_ok());
assert_eq!(buffer, "Ok");

// But you have to be mindful of the format to avoid pushing
// invalid characters. Most commonly, after delimiters.
buffer.push('_')?;
assert!(buffer.push('i').is_err());
Source

pub fn push_bounded(&mut self, c: char) -> Result<(), Error>
where D: Default,

Attempts to push a character into the buffer, preserving chunk boundaries by conditionally inserting delimiters if needed.

If the character is a delimiter, it will always be pushed verbatim.

If the character is NOT a delimiter, the character will first be pushed, and then it will be tested to ensure that the left side of the character don’t merge into the prior chunks. If it did, a delimiter will be inserted to force separation.

§Unicode Warning

If you are working with Unicode data, you very likely don’t want this function. Instead, you likely want to insert an entire grapheme. Inserting one character from a grapheme bounded, and then inserting other characters unbounded could change the decision for whether or not a grapheme cluster bounds on the left or right.

This function really only works as one would expect if the grapheme cluster is exactly one character big (for example, ASCII data has this property).

§Errors

On failure to interpret the provided data as a valid fragment (a character does not match the profile, or an unexpected/disallowed delimiter is used) InvalidFormat will be returned, and byte_offset will be set to the index of the invalid character.

If the fragment was valid, but we failed to insert it, InvalidLeftJoin or InvalidRightJoin will be returned, depending on whether the insertion failed because of the data on the left or the right of the join.

§Examples

Basic Usage:

let mut buffer = UpperCamelIdentBuf::new();

// If there's no data at the start, there's nothing to bound against.
assert!(buffer.push_bounded('O').is_ok());
assert_eq!(buffer, "O");

// But the very next bounded push would need to bound the contents.
// As such, you cannot select an invalid character.
assert!(buffer.push_bounded('k').is_err()); // "O_k" != UpperCamel casing
assert!(buffer.push_bounded('K').is_ok());
assert_eq!(buffer, "O_K");

// This won't add a delimiter if the chunks are already bounded.
assert!(buffer.push('o').is_ok()); // Regular push to get a lowercase.
assert!(buffer.push_bounded('K').is_ok()); // A `CAMEL` boundary char.
assert_eq!(buffer, "O_KoK");

// If there's already a delimiter, another would not be inserted.
assert!(buffer.push_delim().is_ok());
assert!(buffer.push_bounded('K').is_ok());
assert_eq!(buffer, "O_KoK_K");
Source

pub fn push_bounded_with(&mut self, c: char, delim: D) -> Result<(), Error>

Attempts to push a character into the buffer, preserving chunk boundaries by conditionally inserting delimiters if needed.

If the character is a delimiter, it will always be pushed verbatim.

If the character is NOT a delimiter, the character will first be pushed, and then it will be tested to ensure that the left side of the character don’t merge into the prior chunks. If it did, a delimiter will be inserted to force separation.

§Unicode Warning

If you are working with Unicode data, you very likely don’t want this function. Instead, you likely want to insert an entire grapheme. Inserting one character from a grapheme bounded, and then inserting other characters unbounded could change the decision for whether or not a grapheme cluster bounds on the left or right.

This function really only works as one would expect if the grapheme cluster is exactly one character big (for example, ASCII data has this property).

§Errors

On failure to interpret the provided data as a valid fragment (a character does not match the profile, or an unexpected/disallowed delimiter is used) InvalidFormat will be returned, and byte_offset will be set to the index of the invalid character.

If the fragment was valid, but we failed to insert it, InvalidLeftJoin or InvalidRightJoin will be returned, depending on whether the insertion failed because of the data on the left or the right of the join.

§Examples

Basic Usage:

let mut buffer = UpperCamelIdentBuf::new();

// If there's no data at the start, there's nothing to bound against.
assert!(buffer.push_bounded_with('O', LowLine).is_ok());
assert_eq!(buffer, "O");

// But the very next bounded push would need to bound the contents.
// As such, you cannot select an invalid character.
assert!(buffer.push_bounded_with('k', LowLine).is_err()); // "O_k" != UpperCamel casing
assert!(buffer.push_bounded_with('K', LowLine).is_ok());
assert_eq!(buffer, "O_K");

// This won't add a delimiter if the chunks are already bounded.
assert!(buffer.push('o').is_ok()); // Regular push to get a lowercase.
assert!(buffer.push_bounded_with('K', LowLine).is_ok()); // A `CAMEL` boundary char.
assert_eq!(buffer, "O_KoK");

// If there's already a delimiter, another would not be inserted.
assert!(buffer.push_delim().is_ok());
assert!(buffer.push_bounded_with('K', LowLine).is_ok());
assert_eq!(buffer, "O_KoK_K");
Source

pub fn push_delimited(&mut self, c: char) -> Result<(), Error>
where D: Default,

Attempts to push a character into the buffer, preserving chunk boundaries by ensuring a delimiter is present on the left side (if needed).

If the character is a delimiter, it will always be pushed verbatim.

If the character is NOT a delimiter, then a delimiter will be pushed first if there is chunk data at the end of the buffer. Finally, the character itself will be pushed.

§Errors

On failure to interpret the provided data as a valid fragment (a character does not match the profile, or an unexpected/disallowed delimiter is used) InvalidFormat will be returned, and byte_offset will be set to the index of the invalid character.

If the fragment was valid, but we failed to insert it, InvalidLeftJoin or InvalidRightJoin will be returned, depending on whether the insertion failed because of the data on the left or the right of the join.

§Examples

Basic Usage:

let mut buffer = UpperCamelIdentBuf::new();

// If there's no data at the start, there's nothing to delimit against.
assert!(buffer.push_delimited('O').is_ok());
assert_eq!(buffer, "O");

// But the very next delimited push would need to delimit the contents.
// As such, you cannot select an invalid character.
assert!(buffer.push_delimited('k').is_err()); // "O_k" != UpperCamel casing
assert!(buffer.push_delimited('K').is_ok());
assert_eq!(buffer, "O_K");

// If there's already a delimiter, another would not be inserted.
assert!(buffer.push_delim().is_ok());
assert!(buffer.push_delimited('K').is_ok());
assert_eq!(buffer, "O_K_K");
Source

pub fn push_delimited_with(&mut self, c: char, delim: D) -> Result<(), Error>

Attempts to push a character into the buffer, preserving chunk boundaries by ensuring a delimiter is present on the left side (if needed).

If the character is a delimiter, it will always be pushed verbatim.

If the character is NOT a delimiter, then a delimiter will be pushed first if there is chunk data at the end of the buffer. Finally, the character itself will be pushed.

§Errors

On failure to interpret the provided data as a valid fragment (a character does not match the profile, or an unexpected/disallowed delimiter is used) InvalidFormat will be returned, and byte_offset will be set to the index of the invalid character.

If the fragment was valid, but we failed to insert it, InvalidLeftJoin or InvalidRightJoin will be returned, depending on whether the insertion failed because of the data on the left or the right of the join.

§Examples

Basic Usage:

let mut buffer = UpperCamelIdentBuf::new();

// If there's no data at the start, there's nothing to delimit against.
assert!(buffer.push_delimited_with('O', LowLine).is_ok());
assert_eq!(buffer, "O");

// But the very next delimited push would need to delimit the contents.
// As such, you cannot select an invalid character.
assert!(buffer.push_delimited_with('k', LowLine).is_err()); // "O_k" != UpperCamel casing
assert!(buffer.push_delimited_with('K', LowLine).is_ok());
assert_eq!(buffer, "O_K");

// If there's already a delimiter, another would not be inserted.
assert!(buffer.push_delim().is_ok());
assert!(buffer.push_delimited_with('K', LowLine).is_ok());
assert_eq!(buffer, "O_K_K");
Source

pub fn push_delim(&mut self) -> Result<(), Error>
where D: Default,

Attempts to push a delimiter into the buffer.

§Errors

If the delimiter itself was valid, but not at the position pushed, then InvalidPosition will be returned.

§Examples

Basic Usage:

let mut buffer = UpperCamelFragmentBuf::new();

// For all preset and provided delimiters, you can push them anywhere in
// an identifier. Unless you have a custom delimiter, it's always safe to push.
assert!(buffer.push_delim().is_ok());
Source

pub fn push_fragment( &mut self, fragment: &Fragment<B, D, P>, ) -> Result<(), Error>

Attempts to push a fragment into the buffer.

§Errors

On failure to interpret the provided data as a valid fragment (a character does not match the profile, or an unexpected/disallowed delimiter is used) InvalidFormat will be returned, and byte_offset will be set to the index of the invalid character.

If the fragment was valid, but we failed to insert it, InvalidLeftJoin or InvalidRightJoin will be returned, depending on whether the insertion failed because of the data on the left or the right of the join.

§Examples

Basic Usage:

let mut buffer = UpperCamelIdentBuf::new();

// This would be valid, because it might be a continuation fragment.
assert!(buffer.push_fragment(UpperCamelFragment::new("Valid")?).is_ok());

// You can add more lowercase at the end, since there's no delimiter.
assert!(buffer.push_fragment(UpperCamelFragment::new("push")?).is_ok());

// But, you cannot add it to the end if there's a delimiter present.
// At least for `UpperCamelIdent`, which dictates chunks start uppercase.
buffer.push('_')?;
assert!(buffer.push_fragment(UpperCamelFragment::new("push")?).is_err());

// If your string is valid for the configuration though, it is allowed.
assert!(buffer.push_fragment(UpperCamelFragment::new("Push")?).is_ok());
Source

pub fn push_bounded_fragment( &mut self, fragment: &Fragment<B, D, P>, ) -> Result<(), Error>
where D: Default,

Attempts to push a fragment into the buffer, preserving chunk boundaries by conditionally inserting delimiters if needed.

If the fragment already contains delimiters on the left, it will always be inserted verbatim.

If the fragment does NOT contain delimiters on the left, the fragment will first be pushed, and then it will be tested to ensure that the left side of the fragment didn’t merge into the prior chunk. If it did, a delimiter will be inserted to force separation.

§Errors

On failure to interpret the provided data as a valid fragment (a character does not match the profile, or an unexpected/disallowed delimiter is used) InvalidFormat will be returned, and byte_offset will be set to the index of the invalid character.

If the fragment was valid, but we failed to insert it, InvalidLeftJoin or InvalidRightJoin will be returned, depending on whether the insertion failed because of the data on the left or the right of the join.

§Examples

Basic Usage:

let mut buffer = UpperCamelIdentBuf::new();

// If there's no data at the start, there's nothing to bound against.
assert!(buffer.push_bounded_fragment(
    UpperCamelFragment::new("Valid")?
).is_ok());
assert_eq!(buffer, "Valid");

// But the very next bounded push would need to bound the contents.
// As such, you cannot select an invalid character.
assert!(buffer.push_bounded_fragment(
    UpperCamelFragment::new("lower")?
).is_err()); // "Valid_lower" != UpperCamel casing
assert!(buffer.push_bounded_fragment(
    UpperCamelFragment::new("Upper")?
).is_ok()); // A `CAMEL` boundary.
assert_eq!(buffer, "ValidUpper");

// If the character on its own cannot form a boundary, a delimiter
// will be inserted first.
assert!(buffer.push_bounded_fragment(
    UpperCamelFragment::new("2fast")?
).is_ok());
assert_eq!(buffer, "ValidUpper_2fast");

// If there's already a delimiter, another would not be inserted.
assert!(buffer.push_delim().is_ok());
assert!(buffer.push_bounded_fragment(
    UpperCamelFragment::new("2furious")?
).is_ok());
assert_eq!(buffer, "ValidUpper_2fast_2furious");
Source

pub fn push_bounded_fragment_with( &mut self, fragment: &Fragment<B, D, P>, delim: D, ) -> Result<(), Error>

Attempts to push a fragment into the buffer, preserving chunk boundaries by conditionally inserting delimiters if needed.

If the fragment already contains delimiters on the left, it will always be inserted verbatim.

If the fragment does NOT contain delimiters on the left, the fragment will first be pushed, and then it will be tested to ensure that the left side of the fragment didn’t merge into the prior chunk. If it did, a delimiter will be inserted to force separation.

§Errors

On failure to interpret the provided data as a valid fragment (a character does not match the profile, or an unexpected/disallowed delimiter is used) InvalidFormat will be returned, and byte_offset will be set to the index of the invalid character.

If the fragment was valid, but we failed to insert it, InvalidLeftJoin or InvalidRightJoin will be returned, depending on whether the insertion failed because of the data on the left or the right of the join.

§Examples

Basic Usage:

let mut buffer = UpperCamelIdentBuf::new();

// If there's no data at the start, there's nothing to bound against.
assert!(buffer.push_bounded_fragment_with(
    UpperCamelFragment::new("Valid")?,
    LowLine,
).is_ok());
assert_eq!(buffer, "Valid");

// But the very next bounded push would need to bound the contents.
// As such, you cannot select an invalid character.
assert!(buffer.push_bounded_fragment_with(
    UpperCamelFragment::new("lower")?,
    LowLine,
).is_err()); // "Valid_lower" != UpperCamel casing
assert!(buffer.push_bounded_fragment_with(
    UpperCamelFragment::new("Upper")?,
    LowLine,
).is_ok()); // A `CAMEL` boundary.
assert_eq!(buffer, "ValidUpper");

// If the character on its own cannot form a boundary, a delimiter
// will be inserted first.
assert!(buffer.push_bounded_fragment_with(
    UpperCamelFragment::new("2fast")?,
    LowLine,
).is_ok());
assert_eq!(buffer, "ValidUpper_2fast");

// If there's already a delimiter, another would not be inserted.
assert!(buffer.push_delim().is_ok());
assert!(buffer.push_bounded_fragment_with(
    UpperCamelFragment::new("2furious")?,
    LowLine,
).is_ok());
assert_eq!(buffer, "ValidUpper_2fast_2furious");
Source

pub fn push_delimited_fragment( &mut self, fragment: &Fragment<B, D, P>, ) -> Result<(), Error>
where D: Default,

Attempts to push a fragment into the buffer, preserving chunk boundaries by ensuring a delimiter is present on the left side (if needed).

If the fragment already contains delimiters on the left, it will be inserted verbatim.

If the fragment does NOT contain delimiters on the left, and the prior fragment did not contain a delimiter on the right, then a delimiter will be pushed first. Finally, the fragment itself will be pushed.

§Errors

On failure to interpret the provided data as a valid fragment (a character does not match the profile, or an unexpected/disallowed delimiter is used) InvalidFormat will be returned, and byte_offset will be set to the index of the invalid character.

If the fragment was valid, but we failed to insert it, InvalidLeftJoin or InvalidRightJoin will be returned, depending on whether the insertion failed because of the data on the left or the right of the join.

§Examples

Basic Usage:

let mut buffer = UpperCamelIdentBuf::new();

// If there's no data at the start, there's nothing to delimit against.
assert!(buffer.push_delimited_fragment(
    UpperCamelFragment::new("Valid")?
).is_ok());
assert_eq!(buffer, "Valid");

// But the very next delimited push would need to delimit the contents.
// As such, you cannot select an invalid character.
assert!(buffer.push_delimited_fragment(
    UpperCamelFragment::new("lower")?
).is_err()); // "Valid_lower" != UpperCamel casing
assert!(buffer.push_delimited_fragment(
    UpperCamelFragment::new("Upper")?
).is_ok());
assert_eq!(buffer, "Valid_Upper");

// If there's already a delimiter, another would not be inserted.
assert!(buffer.push_delim().is_ok());
assert!(buffer.push_delimited_fragment(
    UpperCamelFragment::new("2fast2furious")?
).is_ok());
assert_eq!(buffer, "Valid_Upper_2fast2furious");
Source

pub fn push_delimited_fragment_with( &mut self, fragment: &Fragment<B, D, P>, delim: D, ) -> Result<(), Error>

Attempts to push a fragment into the buffer, preserving chunk boundaries by ensuring a delimiter is present on the left side (if needed).

If the fragment already contains delimiters on the left, it will be inserted verbatim.

If the fragment does NOT contain delimiters on the left, and the prior fragment did not contain a delimiter on the right, then a delimiter will be pushed first. Finally, the fragment itself will be pushed.

§Errors

On failure to interpret the provided data as a valid fragment (a character does not match the profile, or an unexpected/disallowed delimiter is used) InvalidFormat will be returned, and byte_offset will be set to the index of the invalid character.

If the fragment was valid, but we failed to insert it, InvalidLeftJoin or InvalidRightJoin will be returned, depending on whether the insertion failed because of the data on the left or the right of the join.

§Examples

Basic Usage:

let mut buffer = UpperCamelIdentBuf::new();

// If there's no data at the start, there's nothing to delimit against.
assert!(buffer.push_delimited_fragment_with(
    UpperCamelFragment::new("Valid")?,
    LowLine,
).is_ok());
assert_eq!(buffer, "Valid");

// But the very next delimited push would need to delimit the contents.
// As such, you cannot select an invalid character.
assert!(buffer.push_delimited_fragment_with(
    UpperCamelFragment::new("lower")?,
    LowLine,
).is_err()); // "Valid_lower" != UpperCamel casing
assert!(buffer.push_delimited_fragment_with(
    UpperCamelFragment::new("Upper")?,
    LowLine,
).is_ok());
assert_eq!(buffer, "Valid_Upper");

// If there's already a delimiter, another would not be inserted.
assert!(buffer.push_delim().is_ok());
assert!(buffer.push_delimited_fragment_with(
    UpperCamelFragment::new("2fast2furious")?,
    LowLine,
).is_ok());
assert_eq!(buffer, "Valid_Upper_2fast2furious");
Source

pub fn push_str(&mut self, s: &str) -> Result<(), Error>

Attempts to push a string slice into the buffer.

This will first convert the string slice to a fragment, and then attempting to push the fragment (it is equivalent to first calling Fragment::new on your input, then calling the fragment-equivalent version of this function instead).

§Errors

On failure to interpret the provided data as a valid fragment (a character does not match the profile, or an unexpected/disallowed delimiter is used) InvalidFormat will be returned, and byte_offset will be set to the index of the invalid character.

If the fragment was valid, but we failed to insert it, InvalidLeftJoin or InvalidRightJoin will be returned, depending on whether the insertion failed because of the data on the left or the right of the join.

§Examples

Basic Usage:

let mut buffer = UpperCamelIdentBuf::new();

// You can only push strings that are valid at the given position.
assert!(buffer.push_str("Ok").is_ok());
assert!(buffer.push_str("computer").is_ok());
assert_eq!(buffer, "Okcomputer");

// But you have to be mindful of the format to avoid pushing
// invalid characters. Most commonly, after delimiters.
buffer.push('_')?;
assert!(buffer.push_str("invalid").is_err());
Source

pub fn push_bounded_str(&mut self, s: &str) -> Result<(), Error>
where D: Default,

Attempts to push a string slice into the buffer, preserving chunk boundaries by conditionally inserting delimiters if needed.

This will first convert the string slice to a fragment, and then attempting to push the fragment (it is equivalent to first calling Fragment::new on your input, then calling the fragment-equivalent version of this function instead).

If the fragment already contains delimiters on the left, it will always be inserted verbatim.

If the fragment does NOT contain delimiters on the left, the fragment will first be pushed, and then it will be tested to ensure that the left side of the fragment didn’t merge into the prior chunk. If it did, a delimiter will be inserted to force separation.

§Errors

On failure to interpret the provided data as a valid fragment (a character does not match the profile, or an unexpected/disallowed delimiter is used) InvalidFormat will be returned, and byte_offset will be set to the index of the invalid character.

If the fragment was valid, but we failed to insert it, InvalidLeftJoin or InvalidRightJoin will be returned, depending on whether the insertion failed because of the data on the left or the right of the join.

§Examples

Basic Usage:

let mut buffer = UpperCamelIdentBuf::new();

// If there's no data at the start, there's nothing to bound against.
assert!(buffer.push_bounded_str("Ok").is_ok());

// But the very next bounded push would need to bound the contents.
// As such, you cannot select an invalid string.
assert!(buffer.push_bounded_str("computer").is_err()); // "Ok_computer" != UpperCamel casing
assert!(buffer.push_bounded_str("Computer").is_ok());
assert_eq!(buffer, "OkComputer");

// Some pushes may require a delimiter.
assert!(buffer.push_bounded_str("2fast").is_ok());
assert_eq!(buffer, "OkComputer_2fast");

// If there's already a delimiter, another would not be inserted.
assert!(buffer.push_delim().is_ok());
assert!(buffer.push_bounded_str("2furious").is_ok());
assert_eq!(buffer, "OkComputer_2fast_2furious");
Source

pub fn push_bounded_str_with(&mut self, s: &str, delim: D) -> Result<(), Error>

Attempts to push a string slice into the buffer, preserving chunk boundaries by conditionally inserting delimiters if needed.

This will first convert the string slice to a fragment, and then attempting to push the fragment (it is equivalent to first calling Fragment::new on your input, then calling the fragment-equivalent version of this function instead).

If the fragment already contains delimiters on the left, it will always be inserted verbatim.

If the fragment does NOT contain delimiters on the left, the fragment will first be pushed, and then it will be tested to ensure that the left side of the fragment didn’t merge into the prior chunk. If it did, a delimiter will be inserted to force separation.

§Errors

On failure to interpret the provided data as a valid fragment (a character does not match the profile, or an unexpected/disallowed delimiter is used) InvalidFormat will be returned, and byte_offset will be set to the index of the invalid character.

If the fragment was valid, but we failed to insert it, InvalidLeftJoin or InvalidRightJoin will be returned, depending on whether the insertion failed because of the data on the left or the right of the join.

§Examples

Basic Usage:

let mut buffer = UpperCamelIdentBuf::new();

// If there's no data at the start, there's nothing to bound against.
assert!(buffer.push_bounded_str_with("Ok", LowLine).is_ok());

// But the very next bounded push would need to bound the contents.
// As such, you cannot select an invalid string.
assert!(buffer.push_bounded_str_with("computer", LowLine).is_err()); // "Ok_computer" != UpperCamel casing
assert!(buffer.push_bounded_str_with("Computer", LowLine).is_ok());
assert_eq!(buffer, "OkComputer");

// Some pushes may require a delimiter.
assert!(buffer.push_bounded_str_with("2fast", LowLine).is_ok());
assert_eq!(buffer, "OkComputer_2fast");

// If there's already a delimiter, another would not be inserted.
assert!(buffer.push_delim().is_ok());
assert!(buffer.push_bounded_str_with("2furious", LowLine).is_ok());
assert_eq!(buffer, "OkComputer_2fast_2furious");
Source

pub fn push_delimited_str(&mut self, s: &str) -> Result<(), Error>
where D: Default,

Attempts to push a fragment into the buffer, preserving chunk boundaries by ensuring a delimiter is present on the left side (if needed).

This will first convert the string slice to a fragment, and then attempting to push the fragment (it is equivalent to first calling Fragment::new on your input, then calling the fragment-equivalent version of this function instead).

If the fragment already contains delimiters on the left, it will be inserted verbatim.

If the fragment does NOT contain delimiters on the left, and the prior fragment did not contain a delimiter on the right, then a delimiter will be pushed first. Finally, the fragment itself will be pushed.

§Errors

On failure to interpret the provided data as a valid fragment (a character does not match the profile, or an unexpected/disallowed delimiter is used) InvalidFormat will be returned, and byte_offset will be set to the index of the invalid character.

If the fragment was valid, but we failed to insert it, InvalidLeftJoin or InvalidRightJoin will be returned, depending on whether the insertion failed because of the data on the left or the right of the join.

§Examples

Basic Usage:

let mut buffer = UpperCamelIdentBuf::new();

// If there's no data at the start, there's nothing to delimit against.
assert!(buffer.push_delimited_str("Ok").is_ok());

// But the very next delimited push would need to delimit the contents.
// As such, you cannot select an invalid string.
assert!(buffer.push_delimited_str("computer").is_err()); // "Ok_computer" != UpperCamel casing
assert!(buffer.push_delimited_str("Computer").is_ok());
assert_eq!(buffer, "Ok_Computer");

// If there's already a delimiter, another would not be inserted.
assert!(buffer.push_delim().is_ok());
assert!(buffer.push_delimited_str("2fast2furious").is_ok());
assert_eq!(buffer, "Ok_Computer_2fast2furious");
Source

pub fn push_delimited_str_with( &mut self, s: &str, delim: D, ) -> Result<(), Error>

Attempts to push a fragment into the buffer, preserving chunk boundaries by ensuring a delimiter is present on the left side (if needed).

This will first convert the string slice to a fragment, and then attempting to push the fragment (it is equivalent to first calling Fragment::new on your input, then calling the fragment-equivalent version of this function instead).

If the fragment already contains delimiters on the left, it will be inserted verbatim.

If the fragment does NOT contain delimiters on the left, and the prior fragment did not contain a delimiter on the right, then a delimiter will be pushed first. Finally, the fragment itself will be pushed.

§Errors

On failure to interpret the provided data as a valid fragment (a character does not match the profile, or an unexpected/disallowed delimiter is used) InvalidFormat will be returned, and byte_offset will be set to the index of the invalid character.

If the fragment was valid, but we failed to insert it, InvalidLeftJoin or InvalidRightJoin will be returned, depending on whether the insertion failed because of the data on the left or the right of the join.

§Examples

Basic Usage:

let mut buffer = UpperCamelIdentBuf::new();

// If there's no data at the start, there's nothing to delimit against.
assert!(buffer.push_delimited_str_with("Ok", LowLine).is_ok());

// But the very next delimited push would need to delimit the contents.
// As such, you cannot select an invalid string.
assert!(buffer.push_delimited_str_with("computer", LowLine).is_err()); // "Ok_computer" != UpperCamel casing
assert!(buffer.push_delimited_str_with("Computer", LowLine).is_ok());
assert_eq!(buffer, "Ok_Computer");

// If there's already a delimiter, another would not be inserted.
assert!(buffer.push_delim().is_ok());
assert!(buffer.push_delimited_str_with("2fast2furious", LowLine).is_ok());
assert_eq!(buffer, "Ok_Computer_2fast2furious");
Source

pub fn replace_range<R>( &mut self, range: R, replace_with: &str, ) -> Result<(), Error>
where R: RangeBounds<usize>,

Replace a range of characters with a provided replacement.

This will first convert the string slice to a fragment, and then attempt to use it as a replacement (it is equivalent to first calling Fragment::new on your input, then calling the fragment-equivalent version of this function instead).

§Panics

This function will panic if the byte index is larger than the element’s length, or if it does not fall on a character sequence boundary.

§Errors

If the replacement of the range provided with the given fragment would lead to an invalid buffer, then the range will not be remove and instead the error InvalidReplace will be returned.

§Examples

Basic Usage:

let mut buffer = UpperCamelIdentBuf::from_str("Upper_Camel")?;

// Examples replacing various ranges.
let mut example = buffer.clone();
assert!(example.replace_range(4..7, "R").is_ok());
assert_eq!(example, "UppeRamel");

let mut example = buffer.clone();
assert!(example.replace_range(4..=7, "R").is_ok());
assert_eq!(example, "UppeRmel");

let mut example = buffer.clone();
assert!(example.replace_range(..7, "R").is_ok());
assert_eq!(example, "Ramel");

let mut example = buffer.clone();
assert!(example.replace_range(..=7, "R").is_ok());
assert_eq!(example, "Rmel");

let mut example = buffer.clone();
assert!(example.replace_range(4.., "R").is_ok());
assert_eq!(example, "UppeR");
Source§

impl<B, D, P> IdentBuf<B, D, P>

Source

pub const fn as_fragment(&self) -> &Fragment<B, D, P>

Returns a reference to the fragment slice from the buffer.

§Examples

Basic Usage:

let mut buffer = HybridIdentBuf::from_str("example")?;
let fragment: &str = buffer.as_str();
Source

pub const fn as_str(&self) -> &str

Returns a string slice representation of the buffer data.

§Examples

Basic Usage:

let mut buffer = HybridIdentBuf::from_str("example")?;
let fragment: &HybridFragment = buffer.as_fragment();
Source

pub fn capacity(&self) -> usize

Returns the underlying capacity of the buffer.

This has the same properties as String::capacity.

§Examples
let mut buffer = HybridIdentBuf::new();
assert_eq!(buffer.capacity(), 0);
buffer.reserve(10);
assert!(buffer.capacity() >= 10);
Source

pub fn clear(&mut self)

Clears the underlying fragment buffer, making it empty.

This has the same properties as String::clear.

§Examples
let mut buffer = HybridIdentBuf::from_str("example")?;
assert_eq!(buffer, "example");
buffer.clear();
assert_eq!(buffer, "");
Source

pub fn into_boxed_fragment(self) -> Box<Fragment<B, D, P>>

Convert the buffer into a boxed fragment.

§Examples
let mut buffer = HybridIdentBuf::from_str("example")?;
let boxed: Box<HybridFragment> = buffer.into_boxed_fragment();
assert_eq!(boxed.as_ref(), "example");
Source

pub fn into_boxed_str(self) -> Box<str>

Convert the buffer into a boxed string slice.

§Examples
let buffer = HybridIdentBuf::from_str("example")?;
let boxed: Box<str> = buffer.into_boxed_str();
assert_eq!(boxed.as_ref(), "example");
Source

pub const fn is_empty(&self) -> bool

Returns true if the underlying buffer is empty.

This has the same properties as String::is_empty.

§Examples
let mut buffer = HybridIdentBuf::from_str("example")?;
assert!(!buffer.is_empty());
buffer.clear();
assert!(buffer.is_empty());
Source

pub const fn len(&self) -> usize

Returns the byte length of the buffer

This has the same properties as String::len.

§Examples
let mut buffer = HybridIdentBuf::from_str("example")?;
assert_eq!(buffer.len(), 7);
buffer.clear();
assert_eq!(buffer.len(), 0);
Source

pub fn new() -> Self

Constructs a new buffer with the capacity set to 0.

§Examples
let mut buffer = HybridIdentBuf::new();
assert_eq!(buffer, "");
Source

pub fn pop(&mut self) -> Option<char>

Pops the right-most character off the buffer and returns it.

This has the same properties as String::pop.

§Examples
let mut buffer = HybridIdentBuf::from_str("test")?;
assert_eq!(buffer.pop(), Some('t'));
assert_eq!(buffer.pop(), Some('s'));
assert_eq!(buffer.pop(), Some('e'));
assert_eq!(buffer.pop(), Some('t'));
assert_eq!(buffer.pop(), None);
Source

pub fn reserve(&mut self, additional: usize)

Reserves enough buffer space for additional more bytes.

This has the same properties as String::reserve.

§Note

This will over-allocate in most situations. If you need to reserve an exact amount of bytes, see reserve_exact.

§Examples
let mut buffer = HybridIdentBuf::new();
assert_eq!(buffer.capacity(), 0);
buffer.reserve(10);
assert!(buffer.capacity() >= 10);
Source

pub fn reserve_exact(&mut self, additional: usize)

Reserves exact buffer space for additional more bytes.

This has the same properties as String::reserve_exact.

§Examples
let mut buffer = HybridIdentBuf::new();
assert_eq!(buffer.capacity(), 0);
buffer.reserve_exact(10);
assert_eq!(buffer.capacity(), 10);
Source

pub fn shrink_to(&mut self, min_capacity: usize)

Shrinks the buffer to the minimum of the actual length or the provided min_capacity value.

This has the same properties as String::shrink_to.

§Examples
let mut buffer = HybridIdentBuf::with_capacity(10);
assert!(buffer.capacity() >= 10);
buffer.shrink_to(5);
assert_eq!(buffer.capacity(), 5);
buffer.push_str("example")?;
assert!(buffer.capacity() >= 7);
buffer.shrink_to(0);
assert_eq!(buffer.capacity(), 7);
Source

pub fn shrink_to_fit(&mut self)

Shrinks the buffer to the size of the content.

This has the same properties as String::shrink_to_fit.

§Examples
let mut buffer = HybridIdentBuf::with_capacity(10);
assert!(buffer.capacity() >= 10);
buffer.shrink_to_fit();
assert_eq!(buffer.capacity(), 0);
buffer.push_str("example")?;
assert!(buffer.capacity() >= 7);
buffer.shrink_to_fit();
assert_eq!(buffer.capacity(), 7);
Source

pub fn truncate(&mut self, len: usize)

Truncates the buffer to the provided length.

This has the same properties as String::truncate.

§Panics

This will panic if the provided len value does not lie on a character sequence boundary.

§Examples
let mut buffer = HybridIdentBuf::from_str("example")?;
assert_eq!(buffer, "example");
buffer.truncate(4);
assert_eq!(buffer, "exam");
Source

pub fn try_reserve(&mut self, additional: usize) -> Result<(), TryReserveError>

Attempts to reserve buffer space for additional more bytes.

This has the same properties as String::try_reserve.

Source

pub fn try_reserve_exact( &mut self, additional: usize, ) -> Result<(), TryReserveError>

Attempts to reserve exact buffer space for additional more bytes.

This has the same properties as String::try_reserve_exact.

Methods from Deref<Target = Fragment<B, D, P>>§

Source

pub fn join( &self, fragment: &Fragment<B, D, P>, ) -> Result<FragmentBuf<B, D, P>, Error>
where D: Default,

Returns a heap-allocated fragment, joined with the original fragment in a way that preserves chunk boundaries.

At the end of the operation, the total number of chunked segments present in the fragment will be equal to the sum of each fragment, potentially plus one additional fragment in the case where we needed to join using a delimiter to preserve chunk boundaries.

This call is identical to join_with with the default delimiter.

It can be a bit cumbersome to use this function in most cases. Instead, if you find it easier to work with string data (or you don’t have any fragments that you’re joining with), you can use join_str.

§Errors

Returns Err if the fragment formed from the combination of self and fragment is invalid. If invalid, an Error is returned with the error_kind set to FailedJoinLeft.

The value byte_offset will NOT be set from this function. None of the individual characters are invalid, it’s just that the combination of joining the fragments themselves is invalid.

§Examples

Basic Usage:

let fragment = LowerSnakeFragment::new("snake")?;
let fragment = fragment.join(
    LowerSnakeFragment::new("fragment")?,
)?;
assert_eq!(fragment, "snake_fragment");
Source

pub fn join_str(&self, s: &str) -> Result<FragmentBuf<B, D, P>, Error>
where D: Default,

Returns a heap-allocated fragment, joined with the original fragment in a way that preserves chunk boundaries. The provided string is first converted to a fragment before attempting to append it.

At the end of the operation, the total number of chunked segments present in the fragment will be equal to the sum of each fragment, potentially plus one additional fragment in the case where we needed to join using a delimiter to preserve chunk boundaries.

This call is identical to join_str_with with the default delimiter.

§Errors

Returns Err if the fragment formed from the combination of self and fragment is invalid. If invalid, an Error is returned with the error_kind set to FailedJoinLeft.

The value byte_offset MAY be set on this function. If the joining string contained invalid characters, this will be set to the byte index (from the start of the joining string) that was invalid.

However, if all characters are independently valid, but one side failed to join (because the join itself would make the following character invalid), then byte_offset will be set to None.

§Examples

Basic Usage:

let fragment = LowerSnakeFragment::new("snake")?;
let fragment = fragment.join_str("fragment")?;
assert_eq!(fragment, "snake_fragment");
Source

pub fn join_str_with( &self, s: &str, delim: D, ) -> Result<FragmentBuf<B, D, P>, Error>

Returns a heap-allocated fragment, joined with the original fragment in a way that preserves chunk boundaries. The provided string is first converted to a fragment before attempting to append it.

At the end of the operation, the total number of chunked segments present in the fragment will be equal to the sum of each fragment, potentially plus one additional fragment in the case where we needed to join using a delimiter to preserve chunk boundaries.

§Errors

Returns Err if the fragment formed from the combination of self and fragment is invalid. If invalid, an Error is returned with the error_kind set to InvalidFormat or FailedJoinLeft.

The value byte_offset MAY be set on this function. If the joining string contained invalid characters, this will be set to the byte index (from the start of the joining string) that was invalid.

However, if all characters are independently valid, but one side failed to join (because the join itself would make the following character invalid), then byte_offset will be set to None.

§Examples

Basic Usage:

let fragment = LowerSnakeFragment::new("snake")?;
let fragment = fragment.join_str_with("fragment", LowLine)?;
assert_eq!(fragment, "snake_fragment");
Source

pub fn join_with( &self, fragment: &Fragment<B, D, P>, delim: D, ) -> Result<FragmentBuf<B, D, P>, Error>

Returns a heap-allocated fragment, joined with the original fragment in a way that preserves chunk boundaries.

At the end of the operation, the total number of chunked segments present in the fragment will be equal to the sum of each fragment, potentially plus one additional fragment in the case where we needed to join using a delimiter to preserve chunk boundaries.

It can be a bit cumbersome to use this function in most cases. Instead, if you find it easier to work with string data (or you don’t have any fragments that you’re joining with), you can use join_str_with.

§Errors

Returns Err if the fragment formed from the combination of self and fragment is invalid. If invalid, an Error is returned with the error_kind set to FailedJoinLeft.

The value byte_offset will NOT be set from this function. None of the individual characters are invalid, it’s just that the combination of joining the fragments themselves is invalid.

§Examples

Basic Usage:

let fragment = LowerSnakeFragment::new("snake")?;
let fragment = fragment.join_with(
    LowerSnakeFragment::new("fragment")?,
    LowLine,
)?;
assert_eq!(fragment, "snake_fragment");
Source

pub fn replace<M>( &self, from: M, to: &Fragment<B, D, P>, ) -> Result<FragmentBuf<B, D, P>, Error>
where M: Pattern,

Returns a heap-allocated fragment, replacing the provided pattern with a fragment of the user’s choice.

It can be a bit cumbersome to use this function in most cases. Instead, if you find it easier to work with string data (or you don’t have any fragments that you’re replacing with), you can use replace_str.

§Errors

Returns Err if the fragment formed from the combination of self and to is invalid at any replacement index. If invalid, an Error is returned with the error_kind set to either FailedReplaceLeft (if to was invalid at a specific replacement) or FailedReplaceRight (if to was valid, but the remainder was not valid after to).

The value byte_offset WILL be set from this function, and it will be set to the index that caused the failure from the original fragment (self).

So for FailedReplaceLeft, this is the byte index of the replacement. For FailedReplaceRight, this is the byte index of the residual that failed to join with the replacement.

§Examples

Basic Usage:

let fragment = LowerSnakeFragment::new("example_snake_identifier")?;
let fragment = fragment.replace(
    "snake",
    LowerSnakeFragment::new("serpent")?,
)?;
assert_eq!(fragment, "example_serpent_identifier");
Source

pub fn replace_str<M>( &self, from: M, to: &str, ) -> Result<FragmentBuf<B, D, P>, Error>
where M: Pattern,

Returns a heap-allocated fragment, replacing the provided pattern with a fragment of the user’s choice. The provided string is first converted to a fragment before attempting to append it.

It can be a bit cumbersome to use this function in most cases. Instead, if you find it easier to work with string data (or you don’t have any fragments that you’re replacing with), you can use replace_str.

§Errors

Returns Err if the fragment formed from the combination of self and to is invalid at any replacement index. If invalid, an Error is returned with the error_kind set to InvalidFormat if the provided fragment was invalid, or InvalidReplace if the replacement failed.

The value byte_offset WILL be set from this function. On invalid fragment, it will be set to the byte index from the start of the fragment which was invalid. On invalid replacement, it will be set to the byte index that caused the failure from the original fragment (self).

§Examples

Basic Usage:

let fragment = LowerSnakeFragment::new("example_snake_identifier")?;
let fragment = fragment.replace_str("snake", "serpent")?;
assert_eq!(fragment, "example_serpent_identifier");
Source

pub fn with_circumfix( &self, prefix: &Fragment<B, D, P>, suffix: &Fragment<B, D, P>, ) -> Result<FragmentBuf<B, D, P>, Error>

Returns a heap-allocated fragment with the provided prefix and suffix attached to the original fragment.

It can be a bit cumbersome to use this function in most cases. Instead, if you find it easier to work with string data (or you don’t have any fragments that you’re joining with), you can use with_circumfix_str.

§Errors

Returns Err if the fragment formed from the combination of prefix, self, and suffix is invalid. If invalid, an Error is returned with the error_kind set either to FailedJoinLeft or FailedJoinRight (depending on which side caused the failure).

The value byte_offset will NOT be set from this function. None of the individual characters are invalid, it’s just that the combination of joining the fragments themselves is invalid.

§Examples

Basic Usage:

let fragment = LowerSnakeFragment::new("snake")?;
let fragment = fragment.with_circumfix(
    LowerSnakeFragment::new("lower_")?,
    LowerSnakeFragment::new("_fragment")?,
)?;
assert_eq!(fragment, "lower_snake_fragment");
Source

pub fn with_circumfix_str( &self, prefix: &str, suffix: &str, ) -> Result<FragmentBuf<B, D, P>, Error>

Returns a heap-allocated fragment with the provided prefix and suffix strings attached to the original fragment. The provided strings are first converted to fragments before attempting to append them.

§Errors

Returns Err if the either of the provided fragments are invalid. If one of them is invalid, an Error is returned with the error_kind set to InvalidPrefix or InvalidSuffix depending on which was invalid (prefix takes precedence if both are invalid).

Returns Err if the fragment formed from the combination of prefix, self, and suffix is invalid. If invalid, an Error is returned with the error_kind set either to FailedJoinLeft or FailedJoinRight (depending on which side caused the failure).

The value byte_offset MAY be set on this function. If the prefix or suffix strings contained invalid characters, this will be set to the byte index (from the start of either the prefix or suffix, depending on which error_kind was set) that was invalid.

However, if all characters are independently valid, but one side failed to join (because the join itself would make the following character invalid), then byte_offset will be set to None.

§Examples

Basic Usage:

let fragment = LowerSnakeFragment::new("snake")?;
let fragment = fragment.with_circumfix_str("lower_", "_fragment")?;
assert_eq!(fragment, "lower_snake_fragment");
Source

pub fn with_prefix( &self, prefix: &Fragment<B, D, P>, ) -> Result<FragmentBuf<B, D, P>, Error>

Returns a heap-allocated fragment with the provided prefix attached to the original fragment.

It can be a bit cumbersome to use this function in most cases. Instead, if you find it easier to work with string data (or you don’t have any fragments that you’re joining with), you can use with_prefix_str.

§Errors

Returns Err if the fragment formed from the combination of prefix and self is invalid. If invalid, an Error is returned with the error_kind set to InvalidPrefix.

The value byte_offset will NOT be set from this function. None of the individual characters are invalid, it’s just that the combination of joining the fragments themselves is invalid.

§Examples

Basic Usage:

let fragment = LowerSnakeFragment::new("snake")?;
let fragment = fragment.with_prefix(
    LowerSnakeFragment::new("lower_")?,
)?;
assert_eq!(fragment, "lower_snake");
Source

pub fn with_prefix_str( &self, prefix: &str, ) -> Result<FragmentBuf<B, D, P>, Error>

Returns a heap-allocated fragment with the provided prefix string attached to the original fragment. The provided string is first converted to a fragment before attempting to append it.

§Errors

Returns Err if the fragment formed from the combination of prefix and self is invalid. If invalid, an Error is returned with the error_kind set to InvalidPrefix.

The value byte_offset MAY be set on this function. If the prefix string contained invalid characters, this will be set to the byte index (from the start of the prefix string) that was invalid.

However, if all characters are independently valid, but one side failed to join (because the join itself would make the following character invalid), then byte_offset will be set to None.

§Examples

Basic Usage:

let fragment = LowerSnakeFragment::new("snake")?;
let fragment = fragment.with_prefix_str("lower_")?;
assert_eq!(fragment, "lower_snake");
Source

pub fn with_suffix( &self, suffix: &Fragment<B, D, P>, ) -> Result<FragmentBuf<B, D, P>, Error>

Returns a heap-allocated fragment with the provided suffix attached to the original fragment.

It can be a bit cumbersome to use this function in most cases. Instead, if you find it easier to work with string data (or you don’t have any fragments that you’re joining with), you can use with_suffix_str.

§Errors

Returns Err if the fragment formed from the combination of self and suffix is invalid. If invalid, an Error is returned with the error_kind set to InvalidPrefix.

The value byte_offset will NOT be set from this function. None of the individual characters are invalid, it’s just that the combination of joining the fragments themselves is invalid.

§Examples

Basic Usage:

let fragment = LowerSnakeFragment::new("snake")?;
let fragment = fragment.with_suffix(
    LowerSnakeFragment::new("_fragment")?,
)?;
assert_eq!(fragment, "snake_fragment");
Source

pub fn with_suffix_str( &self, suffix: &str, ) -> Result<FragmentBuf<B, D, P>, Error>

Returns a heap-allocated fragment with the provided suffix string attached to the original fragment. The provided string is first converted to a fragment before attempting to append it.

§Errors

Returns Err if the fragment formed from the combination of self and suffix is invalid. If invalid, an Error is returned with the error_kind set to InvalidPrefix.

The value byte_offset MAY be set on this function. If the suffix string contained invalid characters, this will be set to the byte index (from the start of the suffix string) that was invalid.

However, if all characters are independently valid, but one side failed to join (because the join itself would make the following character invalid), then byte_offset will be set to None.

§Examples

Basic Usage:

let fragment = LowerSnakeFragment::new("snake")?;
let fragment = fragment.with_suffix_str("_fragment")?;
assert_eq!(fragment, "snake_fragment");
Source

pub fn to_fragment_buf(&self) -> FragmentBuf<B, D, P>

Converts an identifier into a fragment buffer.

§Examples

Basic Usage:

let fragment: &LowerSnakeFragment = Fragment::new("snake_fragment")?;
let buffer: LowerSnakeFragmentBuf = fragment.to_fragment_buf();
Source

pub fn chunked_segments(&self) -> ChunkedSegments<'_, B, D, P>

Produces an iterator over the Segments of a fragment, joining chunks together into one chunk instead of separating based on boundary logic.

Usually, when breaking into segments, you want to also break chunk boundaries. However, this iterator will not do that. It simply breaks into broad segments and chunks.

If you want chunk boundaries to be broken, you should instead use the segments function.

§Type Erasure

Because segments contain type information specific to the fragment, it can be a little hard to use them in generic situations (where maybe you don’t care about the type information, and just want to see general data about the segments).

In these cases, you should call type_erased to drop type information, mapping to a Segment</*Delimiter=*/char, /*Chunk=*/&str> (you can call this on the returned iterator, or on an individual segment).

§Examples

Basic Usage:

let flat_ident = CamelIdent::new("HelloWorld_GoodbyeWorld")?;
let mut segments = flat_ident.chunked_segments().type_erased();
assert_eq!(segments.next(), Some(Segment::Chunk("HelloWorld")));
assert_eq!(segments.next(), Some(Segment::Delim('_')));
assert_eq!(segments.next(), Some(Segment::Chunk("GoodbyeWorld")));
assert_eq!(segments.next(), None);

This also works in reverse:

let flat_ident = CamelIdent::new("HelloWorld_GoodbyeWorld")?;
let mut segments = flat_ident.chunked_segments().type_erased();
assert_eq!(segments.next_back(), Some(Segment::Chunk("GoodbyeWorld")));
assert_eq!(segments.next_back(), Some(Segment::Delim('_')));
assert_eq!(segments.next_back(), Some(Segment::Chunk("HelloWorld")));
assert_eq!(segments.next_back(), None);
Source

pub fn chunked_segment_indices(&self) -> ChunkedSegmentIndices<'_, B, D, P>

Produces an iterator over the Segments of a fragment, and their positions, joining chunks together into one chunk instead of separating based on boundary logic.

Usually, when breaking into segments, you want to also break chunk boundaries. However, this iterator will not do that. It simply breaks into broad segments and chunks.

If you want chunk boundaries to be broken, you should instead use the segment_indices function.

§Type Erasure

Because segments contain type information specific to the fragment, it can be a little hard to use them in generic situations (where maybe you don’t care about the type information, and just want to see general data about the segments).

In these cases, you should call type_erased to drop type information, mapping to a Segment</*Delimiter=*/char, /*Chunk=*/&str> (you can call this on the returned iterator, or on an individual segment).

§Examples

Basic Usage:

let flat_ident = CamelIdent::new("HelloWorld_GoodbyeWorld")?;
let mut segments = flat_ident.chunked_segment_indices().type_erased();
assert_eq!(segments.next(), Some((0, Segment::Chunk("HelloWorld"))));
assert_eq!(segments.next(), Some((10, Segment::Delim('_'))));
assert_eq!(segments.next(), Some((11, Segment::Chunk("GoodbyeWorld"))));
assert_eq!(segments.next(), None);

This also works in reverse:

let flat_ident = CamelIdent::new("HelloWorld_GoodbyeWorld")?;
let mut segments = flat_ident.chunked_segment_indices().type_erased();
assert_eq!(segments.next_back(), Some((11, Segment::Chunk("GoodbyeWorld"))));
assert_eq!(segments.next_back(), Some((10, Segment::Delim('_'))));
assert_eq!(segments.next_back(), Some((0, Segment::Chunk("HelloWorld"))));
assert_eq!(segments.next_back(), None);
Source

pub fn segments(&self) -> Segments<'_, B, D, P>

Produces an iterator over the Segments of a fragment.

This is similar to chunked_segments, except that it will also break chunks based on the configured Boundary type parameter.

§Type Erased

Because segments contain type information specific to the fragment, it can be a little hard to use them in generic situations (where maybe you don’t care about the type information, and just want to see general data about the segments).

In these cases, you should call type_erased to drop type information, mapping to a Segment</*Delimiter=*/char, /*Chunk=*/&str> (you can call this on the returned iterator, or on an individual segment).

§Examples

Basic Usage:

let flat_ident = CamelIdent::new("HelloWorld_GoodbyeWorld")?;
let mut segments = flat_ident.segments().type_erased();
assert_eq!(segments.next(), Some(Segment::Chunk("Hello")));
assert_eq!(segments.next(), Some(Segment::Chunk("World")));
assert_eq!(segments.next(), Some(Segment::Delim('_')));
assert_eq!(segments.next(), Some(Segment::Chunk("Goodbye")));
assert_eq!(segments.next(), Some(Segment::Chunk("World")));
assert_eq!(segments.next(), None);

These work in reverse as well:

let flat_ident = CamelIdent::new("HelloWorld_GoodbyeWorld")?;
let mut segments = flat_ident.segments().type_erased();
assert_eq!(segments.next_back(), Some(Segment::Chunk("World")));
assert_eq!(segments.next_back(), Some(Segment::Chunk("Goodbye")));
assert_eq!(segments.next_back(), Some(Segment::Delim('_')));
assert_eq!(segments.next_back(), Some(Segment::Chunk("World")));
assert_eq!(segments.next_back(), Some(Segment::Chunk("Hello")));
assert_eq!(segments.next_back(), None);
Source

pub fn segment_indices(&self) -> SegmentIndices<'_, B, D, P>

Produces an iterator over the Segments of a fragment, and their positions.

This is similar to chunked_segment_indices, except that it will also break chunks based on the configured Boundary type parameter.

§Type Erased

Because segments contain type information specific to the fragment, it can be a little hard to use them in generic situations (where maybe you don’t care about the type information, and just want to see general data about the segments).

In these cases, you should call type_erased to drop type information, mapping to a Segment</*Delimiter=*/char, /*Chunk=*/&str> (you can call this on the returned iterator, or on an individual segment).

§Examples

Basic Usage:

let flat_ident = CamelIdent::new("HelloWorld_GoodbyeWorld")?;
let mut segments = flat_ident.segment_indices().type_erased();
assert_eq!(segments.next(), Some((0, Segment::Chunk("Hello"))));
assert_eq!(segments.next(), Some((5, Segment::Chunk("World"))));
assert_eq!(segments.next(), Some((10, Segment::Delim('_'))));
assert_eq!(segments.next(), Some((11, Segment::Chunk("Goodbye"))));
assert_eq!(segments.next(), Some((18, Segment::Chunk("World"))));
assert_eq!(segments.next(), None);

These work in reverse as well:

let flat_ident = CamelIdent::new("HelloWorld_GoodbyeWorld")?;
let mut segments = flat_ident.segment_indices().type_erased();
assert_eq!(segments.next_back(), Some((18, Segment::Chunk("World"))));
assert_eq!(segments.next_back(), Some((11, Segment::Chunk("Goodbye"))));
assert_eq!(segments.next_back(), Some((10, Segment::Delim('_'))));
assert_eq!(segments.next_back(), Some((5, Segment::Chunk("World"))));
assert_eq!(segments.next_back(), Some((0, Segment::Chunk("Hello"))));
assert_eq!(segments.next_back(), None);
Source

pub fn has_leading_delim(&self) -> bool

Returns true if the fragment has a leading delimiter, false otherwise.

§Examples
let fragment = UpperCamelFragment::new("__LeadingDelim")?;
assert!(fragment.has_leading_delim());

let fragment = UpperCamelFragment::new("NoLeadingDelim")?;
assert!(!fragment.has_leading_delim());
Source

pub fn has_trailing_delim(&self) -> bool

Returns true if the fragment has a trailing delimiter, false otherwise.

§Examples
let fragment = UpperCamelFragment::new("TrailingDelim__")?;
assert!(fragment.has_trailing_delim());

let fragment = UpperCamelFragment::new("NoTrailingDelim")?;
assert!(!fragment.has_trailing_delim());
Source

pub fn is_anonymous(&self) -> bool

Returns true if the fragment is comprised solely of delimiters, false otherwise.

§Examples
let fragment = UpperCamelFragment::new("__NotAnonymous__")?;
assert!(!fragment.is_anonymous());

let fragment = UpperCamelFragment::new("___")?;
assert!(fragment.is_anonymous());
Source

pub fn trim_delims(&self) -> &Self

Trims the leading and trailing delimiters from a fragment.

§Examples
let fragment = UpperCamelFragment::new("__SurroundingDelim__")?;
assert_eq!(fragment.trim_delims().as_str(), "SurroundingDelim");

// Note that this can leave you with an empty fragment.
let fragment = UpperCamelFragment::new("____")?;
assert_eq!(fragment.trim_delims().as_str(), "");
Source

pub fn trim_leading_delims(&self) -> &Self

Trims the leading delimiters from a fragment.

§Examples
let fragment = UpperCamelFragment::new("__SurroundingDelim__")?;
assert_eq!(fragment.trim_leading_delims().as_str(), "SurroundingDelim__");

// Note that this can leave you with an empty fragment.
let fragment = UpperCamelFragment::new("____")?;
assert_eq!(fragment.trim_leading_delims().as_str(), "");
Source

pub fn trim_trailing_delims(&self) -> &Self

Trims the trailing delimiters from a fragment.

§Examples
let fragment = UpperCamelFragment::new("__SurroundingDelim__")?;
assert_eq!(fragment.trim_trailing_delims().as_str(), "__SurroundingDelim");

// Note that this can leave you with an empty fragment.
let fragment = UpperCamelFragment::new("____")?;
assert_eq!(fragment.trim_trailing_delims().as_str(), "");
Source

pub fn as_str(&self) -> &str

Returns a string slice representation of the fragment.

§Examples
let fragment = UpperCamelFragment::new("ExampleFragment")?;
assert_eq!(fragment.as_str(), "ExampleFragment");
Source

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

Returns true if the given pattern matches a sub-fragment of this fragment.

Returns false if it does not.

The pattern can be a &str, char, a slice of chars, or a function or closure that determines if a character matches.

§Examples
let fragment = UpperCamelFragment::new("bananas")?;

assert!(fragment.contains("nana"));
assert!(!fragment.contains("apples"));
Source

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

Returns true if the given pattern matches a suffix of this fragment.

Returns false if it does not.

The pattern can be a &str, char, a slice of chars, or a function or closure that determines if a character matches.

§Examples
let fragment = UpperCamelFragment::new("bananas")?;

assert!(fragment.ends_with("anas"));
assert!(!fragment.ends_with("nana"));
Source

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

Returns true if the given pattern matches a prefix of this fragment.

Returns false if it does not.

The pattern can be a &str, in which case this function will return true if the &str is a prefix of this string slice.

The pattern can also be a char, a slice of chars, or a function or closure that determines if a character matches. These will only be checked against the first character of this fragment. Look at the second example below regarding behavior for slices of chars.

§Examples
let fragment = UpperCamelFragment::new("bananas")?;

assert!(fragment.starts_with("bana"));
assert!(!fragment.starts_with("nana"));
let fragment = UpperCamelFragment::new("bananas")?;

// Note that both of these assert successfully.
assert!(fragment.starts_with(&['b', 'a', 'n', 'a']));
assert!(fragment.starts_with(&['a', 'b', 'c', 'd']));
Source

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

Returns the byte index of the first character of this fragment that matches the pattern.

Returns None if the pattern doesn’t match.

The pattern can be a &str, char, a slice of chars, or a function or closure that determines if a character matches.

§Examples

Simple patterns:

let fragment = UpperCamelFragment::new("こんにちはWorld")?;

assert_eq!(fragment.find('こ'), Some(0));
assert_eq!(fragment.find('W'), Some(15));
assert_eq!(fragment.find("orld"), Some(16));

More complex patterns using point-free style and closures:

let fragment = UpperCamelFragment::new("こんにちはWorld")?;

assert_eq!(fragment.find(char::is_alphabetic), Some(0));
assert_eq!(fragment.find(char::is_lowercase), Some(16));
assert_eq!(fragment.find(|c: char| c == 'W' || c == 'w'), Some(15));

Not finding the pattern:

let fragment = UpperCamelFragment::new("こんにちはWorld")?;
let x: &[_] = &['1', '2'];

assert_eq!(fragment.find(x), None);
Source

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

Returns the byte index of the first character of this fragment that matches the pattern.

Returns None if the pattern doesn’t match.

The pattern can be a &str, char, a slice of chars, or a function or closure that determines if a character matches.

§Examples

Simple patterns:

let fragment = UpperCamelFragment::new("HelloWorld")?;

assert_eq!(fragment.rfind('o'), Some(6));
assert_eq!(fragment.rfind('H'), Some(0));
assert_eq!(fragment.rfind("lo"), Some(3));

More complex patterns using point-free style and closures:

let fragment = UpperCamelFragment::new("HelloWorld")?;

assert_eq!(fragment.rfind(char::is_uppercase), Some(5));
assert_eq!(fragment.rfind(char::is_lowercase), Some(9));
assert_eq!(fragment.rfind(|c: char| c == 'o' || c == 'e'), Some(6));

Not finding the pattern:

let fragment = UpperCamelFragment::new("HelloWorld")?;
let x: &[_] = &['1', '2'];

assert_eq!(fragment.rfind(x), None);
Source

pub fn cast<B2, D2, P2>(&self) -> &Fragment<B2, D2, P2>
where D: SubsetOf<D2>, P: SubsetOf<P2>,

Zero-cost cast into the type-configured target.

This function does not perform any checks that the format matches the expectations of the target type. The way it’s able to be provided depends on implementation of the SubsetOf trait.

§Casting Requirements

This function will be able to be called, if:

  • Source::D: SubsetOf<Target::D>, and…
  • Source::P: SubsetOf<Target::P>

If these invariants are not upheld, attempting to call this function will result in a compilation failure.

§Pro-Tip

If this type can perform a zero-cost cast, then it will also implement AsRef to the target type. Because of this, if you know the shape of target type that you want, but also want to accept the widest range of inputs, you can use an AsRef trait bounds.

fn expect_hybrid<I: AsRef<HybridFragment> + ?Sized>(ident: &I) {}
expect_hybrid(LowerSnakeFragment::new("apple")?);
expect_hybrid(UpperCamelFragment::new("Apple")?);
§Examples

Example traversing case profile boundary:

// Compilable Cast:
let original = LowerSnakeFragment::new("apple")?;
let casted: &LowerCamelFragment = original.cast();
// Bad Cast (Fails Compilation):
let original = LowerCamelFragment::new("apple")?;
let casted: &LowerSnakeFragment = original.cast();

Example traversing character profile boundary:

// Compilable Cast:
let original = ascii::LowerSnakeFragment::new("apple")?;
let casted: &unicode::LowerSnakeFragment = original.cast();
// Bad Cast (Fails Compilation):
let original = unicode::LowerSnakeFragment::new("apple")?;
let casted: &ascii::LowerSnakeFragment = original.cast();

Example traversing delimiter boundary:

// Compilable Cast:
let original = LowerSnakeFragment::new("apple")?;
let casted: &HybridFragment = original.cast();
// Bad Cast (Fails Compilation):
let original = HybridFragment::new("apple")?;
let casted: &LowerSnakeFragment = original.cast();
Source

pub fn char_indices(&self) -> CharIndices<'_, B, D, P>

Returns an iterator over the chars of the underlying string slice, and their positions.

This is a special version of the standard-provided CharIndices. It has additional functions on it to allow you to cast the remainder of the string slice back to this type.

§Examples

Basic Usage:

let slice = HybridFragment::new("test")?;
let mut chars = slice.char_indices();
assert_eq!(chars.next(), Some((0, 't')));
assert_eq!(chars.next(), Some((1, 'e')));
assert_eq!(chars.next(), Some((2, 's')));
assert_eq!(chars.next(), Some((3, 't')));
assert_eq!(chars.next(), None);

If needed, you can cast the remainder back to this type:

let slice = HybridFragment::new("test")?;
let mut chars = slice.char_indices();
assert_eq!(chars.next(), Some((0, 't')));
assert_eq!(chars.next(), Some((1, 'e')));
let remainder: &HybridFragment = chars.as_fragment();
assert_eq!(remainder, "st");

If you don’t need type information, you can drop it with the type_erased method:

let slice = HybridFragment::new("test")?;
let chars: std::str::CharIndices = slice.char_indices().type_erased();
Source

pub fn chars(&self) -> Chars<'_, B, D, P>

Returns an iterator over the chars of the underlying string slice.

This is a special version of the standard-provided Chars. It has additional functions on it to allow you to cast the remainder of the string slice back to this type.

§Examples

Basic Usage:

let slice = HybridFragment::new("test")?;
let mut chars = slice.chars();
assert_eq!(chars.next(), Some('t'));
assert_eq!(chars.next(), Some('e'));
assert_eq!(chars.next(), Some('s'));
assert_eq!(chars.next(), Some('t'));
assert_eq!(chars.next(), None);

If needed, you can cast the remainder back to this type:

let slice = HybridFragment::new("test")?;
let mut chars = slice.chars();
assert_eq!(chars.next(), Some('t'));
assert_eq!(chars.next(), Some('e'));
let remainder: &HybridFragment = chars.as_fragment();
assert_eq!(remainder, "st");

If you don’t need type information, you can drop it with the type_erased method:

let slice = HybridFragment::new("test")?;
let chars: std::str::Chars = slice.chars().type_erased();
Source

pub fn get<I: SliceIndex<Self>>(&self, i: I) -> Option<&Self>

Returns a subslice of a Fragment

This is the non-panicking alternative to using the index operator. Returns None whenever the equivalent indexing operation would panic.

§Examples
let slice = HybridFragment::new("こんにちは世界")?;

// indices not on UTF-8 sequence boundaries
assert!(slice.get(1..).is_none());
assert!(slice.get(..20).is_none());

// out of bounds
assert!(slice.get(..42).is_none());
Source

pub unsafe fn get_unchecked<I: SliceIndex<Self>>(&self, i: I) -> &Self

Returns an unchecked subslice of a Fragment

This is the unchecked alternative to using the index operator.

§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.

Failing that, the returned slice may reference invalid memory or violate the invariants communicated by the Fragment type.

§Examples
let slice = HybridFragment::new("こんにちは世界")?;
unsafe {
    assert_eq!(slice.get_unchecked(0..15), HybridFragment::new("こんにちは")?);
    assert_eq!(slice.get_unchecked(15..21), HybridFragment::new("世界")?);
}
Source

pub fn is_empty(&self) -> bool

Returns true if self has a length of zero bytes.

§Examples
let slice = HybridFragment::new("")?;
assert!(slice.is_empty());

let slice = HybridFragment::new("content")?;
assert!(!slice.is_empty());
Source

pub fn len(&self) -> usize

Returns the length of self.

This length is in bytes, not chars or graphemes. In other words, it might not be what a human considers the length of the subslice.

§Examples
let slice = HybridFragment::new("foo")?;
let len = slice.len();
assert_eq!(len, 3);

let slice = HybridFragment::new("ƒoo")?;
assert_eq!(slice.len(), 4); // fancy f!
assert_eq!(slice.chars().count(), 3);
Source

pub fn match_indices<M>(&self, pat: M) -> MatchIndices<'_, B, D, P, M>
where M: Pattern,

Returns an iterator over the disjoint matches of a pattern within the underlying string slice as well as the index that the match starts at.

This is a special version of the standard-provided MatchIndices. Instead of returning regular string slices, it returns Fragment elements.

The pattern can be a &str, char, a slice of chars, or a function or closure that determines if a character matches.

§Iterator behavior

The returned iterator will be a DoubleEndedIterator if the pattern allows a reverse search and forward/reverse search yields the same elements. This is true for, e.g., char, but not for &str.

If the pattern allows a reverse search but its results might differ from a forward search, the rmatch_indices method can be used.

§Examples

Basic Usage:

let slice = HybridFragment::new("abcXXXabcYYYabc")?;
let mut matches = slice.match_indices("abc");
assert_eq!(matches.next(), Some((0, HybridFragment::new("abc")?)));
assert_eq!(matches.next(), Some((6, HybridFragment::new("abc")?)));
assert_eq!(matches.next(), Some((12, HybridFragment::new("abc")?)));
assert_eq!(matches.next(), None);

let slice = HybridFragment::new("1abcabc2")?;
let mut matches = slice.match_indices("abc");
assert_eq!(matches.next(), Some((1, HybridFragment::new("abc")?)));
assert_eq!(matches.next(), Some((4, HybridFragment::new("abc")?)));
assert_eq!(matches.next(), None);

let slice = HybridFragment::new("ababa")?;
let mut matches = slice.match_indices("aba");
assert_eq!(matches.next(), Some((0, HybridFragment::new("aba")?)));
assert_eq!(matches.next(), None); // only the first `aba`

If you don’t need type information, you can drop it with the type_erased method. This can be especially useful if you don’t need the typed versions of the results.

let slice = HybridFragment::new("test")?;
let mut matches: std::str::MatchIndices<char> = slice.match_indices('t').type_erased();
assert_eq!(matches.next(), Some((0, "t")));
assert_eq!(matches.next(), Some((3, "t")));
assert_eq!(matches.next(), None);
Source

pub fn matches<M>(&self, pat: M) -> Matches<'_, B, D, P, M>
where M: Pattern,

Returns an iterator over the disjoint matches of a pattern within the underlying string slice.

This is a special version of the standard-provided Matches. Instead of returning regular string slices, it returns Fragment elements.

The pattern can be a &str, char, a slice of chars, or a function or closure that determines if a character matches.

§Iterator behavior

The returned iterator will be a DoubleEndedIterator if the pattern allows a reverse search and forward/reverse search yields the same elements. This is true for, e.g., char, but not for &str.

If the pattern allows a reverse search but its results might differ from a forward search, the rmatches method can be used.

§Examples

Basic Usage:

let slice = HybridFragment::new("abcXXXabcYYYabc")?;
let mut matches = slice.matches("abc");
assert_eq!(matches.next(), Some(HybridFragment::new("abc")?));
assert_eq!(matches.next(), Some(HybridFragment::new("abc")?));
assert_eq!(matches.next(), Some(HybridFragment::new("abc")?));
assert_eq!(matches.next(), None);

let slice = HybridFragment::new("1abcabc2")?;
let mut matches = slice.matches("abc");
assert_eq!(matches.next(), Some(HybridFragment::new("abc")?));
assert_eq!(matches.next(), Some(HybridFragment::new("abc")?));
assert_eq!(matches.next(), None);

let slice = HybridFragment::new("ababa")?;
let mut matches = slice.matches("aba");
assert_eq!(matches.next(), Some(HybridFragment::new("aba")?));
assert_eq!(matches.next(), None); // only the first `aba`

If you don’t need type information, you can drop it with the type_erased method. This can be especially useful if you don’t need the typed versions of the results.

let slice = HybridFragment::new("test")?;
let mut matches: std::str::Matches<char> = slice.matches('t').type_erased();
assert_eq!(matches.next(), Some("t"));
assert_eq!(matches.next(), Some("t"));
assert_eq!(matches.next(), None);
Source

pub fn rmatch_indices<M>(&self, pat: M) -> RMatchIndices<'_, B, D, P, M>
where M: Pattern,

Returns an iterator over the disjoint matches of a pattern within the underlying string slice yielded in reverse order, as well as the index that the match starts at

This is a special version of the standard-provided RMatchIndices. Instead of returning regular string slices, it returns Fragment elements.

For matches of pat within self that overlap, only the indices corresponding to the last match are returned.

The pattern can be a &str, char, a slice of chars, or a function or closure that determines if a character matches.

§Iterator behavior

The returned iterator requires that the pattern supports a reverse search, and it will be a DoubleEndedIterator if a forward/reverse search yields the same elements.

For iterating from the front, the match_indices method can be used.

§Examples

Basic Usage:

let slice = HybridFragment::new("abcXXXabcYYYabc")?;
let mut matches = slice.rmatch_indices("abc");
assert_eq!(matches.next(), Some((12, HybridFragment::new("abc")?)));
assert_eq!(matches.next(), Some((6, HybridFragment::new("abc")?)));
assert_eq!(matches.next(), Some((0, HybridFragment::new("abc")?)));
assert_eq!(matches.next(), None);

let slice = HybridFragment::new("1abcabc2")?;
let mut matches = slice.rmatch_indices("abc");
assert_eq!(matches.next(), Some((4, HybridFragment::new("abc")?)));
assert_eq!(matches.next(), Some((1, HybridFragment::new("abc")?)));
assert_eq!(matches.next(), None);

let slice = HybridFragment::new("ababa")?;
let mut matches = slice.rmatch_indices("aba");
assert_eq!(matches.next(), Some((2, HybridFragment::new("aba")?)));
assert_eq!(matches.next(), None); // only the first `aba`

If you don’t need type information, you can drop it with the type_erased method. This can be especially useful if you don’t need the typed versions of the results.

let slice = HybridFragment::new("test")?;
let mut matches: std::str::RMatchIndices<char> = slice.rmatch_indices('t').type_erased();
assert_eq!(matches.next(), Some((3, "t")));
assert_eq!(matches.next(), Some((0, "t")));
assert_eq!(matches.next(), None);
Source

pub fn rmatches<M>(&self, pat: M) -> RMatches<'_, B, D, P, M>
where M: Pattern,

Returns an iterator over the disjoint matches of a pattern within the underlying string slice yielded in reverse order.

This is a special version of the standard-provided RMatches. Instead of returning regular string slices, it returns Fragment elements.

For matches of pat within self that overlap, only the indices corresponding to the last match are returned.

The pattern can be a &str, char, a slice of chars, or a function or closure that determines if a character matches.

§Iterator behavior

The returned iterator requires that the pattern supports a reverse search, and it will be a DoubleEndedIterator if a forward/reverse search yields the same elements.

For iterating from the front, the matches method can be used.

§Examples

Basic Usage:

let slice = HybridFragment::new("abcXXXabcYYYabc")?;
let mut matches = slice.rmatches("abc");
assert_eq!(matches.next(), Some(HybridFragment::new("abc")?));
assert_eq!(matches.next(), Some(HybridFragment::new("abc")?));
assert_eq!(matches.next(), Some(HybridFragment::new("abc")?));
assert_eq!(matches.next(), None);

let slice = HybridFragment::new("1abcabc2")?;
let mut matches = slice.rmatches("abc");
assert_eq!(matches.next(), Some(HybridFragment::new("abc")?));
assert_eq!(matches.next(), Some(HybridFragment::new("abc")?));
assert_eq!(matches.next(), None);

let slice = HybridFragment::new("ababa")?;
let mut matches = slice.rmatches("aba");
assert_eq!(matches.next(), Some(HybridFragment::new("aba")?));
assert_eq!(matches.next(), None); // only the first `aba`

If you don’t need type information, you can drop it with the type_erased method. This can be especially useful if you don’t need the typed versions of the results.

let slice = HybridFragment::new("test")?;
let mut matches: std::str::RMatches<char> = slice.rmatches('t').type_erased();
assert_eq!(matches.next(), Some("t"));
assert_eq!(matches.next(), Some("t"));
assert_eq!(matches.next(), None);
Source

pub fn split_at(&self, mid: usize) -> (&Self, &Self)

Divides one fragment into two at an index.

The argument, mid, should be a byte offset from the start of the fragment. It must also be on the boundary of a UTF-8 code point.

The two slices returned go from the start of the fragment to mid, and from mid to the end of the fragment.

§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 fragment. For a non-panicking alternative see split_at_checked.

§Examples
let slice = HybridFragment::new("こんにちは世界")?;

let (first, last) = slice.split_at(15);
assert_eq!(first, HybridFragment::new("こんにちは")?);
assert_eq!(last, HybridFragment::new("世界")?);
Source

pub fn split_at_checked(&self, mid: usize) -> Option<(&Self, &Self)>

Divides one fragment into two at an index.

The argument, mid, should be a byte offset from the start of the fragment. It must also be on the boundary of a UTF-8 code point. The method returns None if that’s not the case.

The two slices returned go from the start of the fragment to mid, and from mid to the end of the fragment.

§Examples
let slice = HybridFragment::new("こんにちは世界")?;

let (first, last) = slice.split_at_checked(15).unwrap();
assert_eq!(first, HybridFragment::new("こんにちは")?);
assert_eq!(last, HybridFragment::new("世界")?);

assert!(slice.split_at_checked(16).is_none()); // Inside "世"
assert!(slice.split_at_checked(42).is_none()); // Beyond the length
Source

pub fn strip_circumfix<Prefix, Suffix>( &self, prefix: Prefix, suffix: Suffix, ) -> Option<&Self>
where Prefix: Pattern, Suffix: Pattern,

Returns a fragment with the prefix and suffix removed.

If the fragment starts with the pattern prefix and ends with the pattern suffix, and the prefix and suffix don’t overlap, returns the sub-fragment after the prefix and before the suffix, wrapped in Some. Unlike trim_start_matches and trim_end_matches, this method removes both the prefix and suffix exactly once.

If the fragment does not start with prefix, does not end with suffix, or the prefix and suffix overlap, returns None.

Each pattern can be a &str, char, a slice of chars, or a function or closure that determines if a character matches.

§Examples
let slice = HybridFragment::new("FooHelloWorldBar")?;
assert_eq!(slice.strip_circumfix("Foo", "Bar"), Some(HybridFragment::new("HelloWorld")?));
assert_eq!(slice.strip_circumfix("FooHello", "WorldBar"), Some(HybridFragment::new("")?));
assert_eq!(slice.strip_circumfix("Foo", "Foo"), None);
assert_eq!(slice.strip_circumfix("Bar", "Bar"), None);
assert_eq!(slice.strip_circumfix("FooHello", "oWorldBar"), None);
Source

pub fn strip_prefix<M>(&self, prefix: M) -> Option<&Self>
where M: Pattern,

Returns a fragment with the prefix removed.

If the fragment starts with the pattern prefix, returns the sub-fragment after the prefix, wrapped in Some. Unlike trim_start_matches, this method removes the prefix exactly once.

If the fragment does not start with prefix, returns None.

The pattern can be a &str, char, a slice of chars, or a function or closure that determines if a character matches.

§Examples
let slice = HybridFragment::new("HelloWorld")?;
assert_eq!(slice.strip_prefix("Hello"), Some(HybridFragment::new("World")?));
assert_eq!(slice.strip_prefix("HelloWorld"), Some(HybridFragment::new("")?));
assert_eq!(slice.strip_prefix("Goodbye"), None);
Source

pub fn strip_suffix<M>(&self, suffix: M) -> Option<&Self>
where M: Pattern,

Returns a fragment with the suffix removed.

If the fragment ends with the pattern suffix, returns the sub-fragment before the suffix, wrapped in Some. Unlike trim_end_matches, this method removes the suffix exactly once.

If the fragment does not end with suffix, returns None.

The pattern can be a &str, char, a slice of chars, or a function or closure that determines if a character matches.

§Examples
let slice = HybridFragment::new("HelloWorld")?;
assert_eq!(slice.strip_suffix("World"), Some(HybridFragment::new("Hello")?));
assert_eq!(slice.strip_suffix("HelloWorld"), Some(HybridFragment::new("")?));
assert_eq!(slice.strip_suffix("Computer"), None);
Source

pub fn trim_start_matches<M>(&self, pat: M) -> &Self
where M: Pattern,

Returns a fragment with all prefixes that match a pattern repeatedly removed.

The pattern can be a &str, char, a slice of chars, or a function or closure that determines if a character matches.

§Text Directionality

A fragment is a sequence of bytes. start in this context means the first position of that byte string; for a left-to-right language like English or Russian, this will be left side, and for right-to-left languages like Arabic or Hebrew, this will be the right side.

§Examples

Simple examples:

let slice = HybridFragment::new("11foo1bar11")?;
assert_eq!(slice.trim_start_matches('1'), HybridFragment::new("foo1bar11")?);

let slice = HybridFragment::new("123foo1bar123")?;
assert_eq!(slice.trim_start_matches(char::is_numeric), HybridFragment::new("foo1bar123")?);

let x: &[_] = &['1', '2'];
let slice = HybridFragment::new("12foo1bar12")?;
assert_eq!(slice.trim_start_matches(x), HybridFragment::new("foo1bar12")?);

// Example with a right-to-left language
let slice = HybridFragment::new("שלוםעולם")?;
assert_eq!(slice.trim_start_matches("שלום"), HybridFragment::new("עולם")?);

A more complex pattern, using a closure:

let slice = HybridFragment::new("1fooX")?;
assert_eq!(slice.trim_start_matches(|c| c == '1' || c == 'X'), HybridFragment::new("fooX")?);
Source

pub fn trim_end_matches<M>(&self, pat: M) -> &Self
where M: Pattern,

Returns a fragment with all suffixes that match a pattern repeatedly removed.

The pattern can be a &str, char, a slice of chars, or a function or closure that determines if a character matches.

§Text Directionality

A fragment is a sequence of bytes. end in this context means the last position of that byte string; for a left-to-right language like English or Russian, this will be right side, and for right-to-left languages like Arabic or Hebrew, this will be the left side.

§Examples

Simple examples:

let slice = HybridFragment::new("11foo1bar11")?;
assert_eq!(slice.trim_end_matches('1'), HybridFragment::new("11foo1bar")?);

let slice = HybridFragment::new("123foo1bar123")?;
assert_eq!(slice.trim_end_matches(char::is_numeric), HybridFragment::new("123foo1bar")?);

let x: &[_] = &['1', '2'];
let slice = HybridFragment::new("12foo1bar12")?;
assert_eq!(slice.trim_end_matches(x), HybridFragment::new("12foo1bar")?);

// Example with a right-to-left language
let slice = HybridFragment::new("שלוםעולם")?;
assert_eq!(slice.trim_end_matches("עולם"), HybridFragment::new("שלום")?);

A more complex pattern, using a closure:

let slice = HybridFragment::new("1fooX")?;
assert_eq!(slice.trim_end_matches(|c| c == '1' || c == 'X'), HybridFragment::new("1foo")?);
Source

pub fn try_cast<B2, D2, P2>(&self) -> Result<&Fragment<B2, D2, P2>, Error>
where B2: Boundary, D2: Delimiter, P2: Profile,

Attempts a fallible cast into the type-configured target.

You should first attempt to call cast on a type, if that compiles it is preferred to this function (and you will not need to call this), because it is truly zero-cost.

This is equivalent to just calling new on the target type with the current type’s string contents. This function is provided for ergonomic convenience.

Trait Implementations§

Source§

impl<'a, B1, B2, D1, D2, P1, P2> AsRef<Fragment<B2, D2, P2>> for IdentBuf<B1, D1, P1>
where D1: Delimiter + SubsetOf<D2>, P1: Profile + SubsetOf<P2>,

Source§

fn as_ref(&self) -> &Fragment<B2, D2, P2>

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<B, D, P> AsRef<[u8]> for IdentBuf<B, D, P>

Source§

fn as_ref(&self) -> &[u8]

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<B, D, P> AsRef<str> for IdentBuf<B, D, P>

Source§

fn as_ref(&self) -> &str

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<B, D, P> Clone for IdentBuf<B, D, P>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<B, D, P> Debug for IdentBuf<B, D, P>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<B, D, P> Default for IdentBuf<B, D, P>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<B, D, P> Deref for IdentBuf<B, D, P>

Source§

type Target = Fragment<B, D, P>

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<B, D, P> Display for IdentBuf<B, D, P>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<B, D, P> Eq for IdentBuf<B, D, P>

Source§

impl<'a, B, D, P> From<&'a Ident<B, D, P>> for IdentBuf<B, D, P>

Source§

fn from(orig: &'a Ident<B, D, P>) -> Self

Converts to this type from the input type.
Source§

impl<'a, B, D, P> From<&'a IdentBuf<B, D, P>> for &'a str

Source§

fn from(orig: &'a IdentBuf<B, D, P>) -> &'a str

Converts to this type from the input type.
Source§

impl<B, D, P> From<IdentBuf<B, D, P>> for String

Source§

fn from(orig: IdentBuf<B, D, P>) -> Self

Converts to this type from the input type.
Source§

impl<B, D, P> From<IdentBuf<B, D, P>> for Box<Fragment<B, D, P>>

Source§

fn from(orig: IdentBuf<B, D, P>) -> Self

Converts to this type from the input type.
Source§

impl<B, D, P> From<IdentBuf<B, D, P>> for Box<str>

Source§

fn from(orig: IdentBuf<B, D, P>) -> Self

Converts to this type from the input type.
Source§

impl<B: Boundary, D: Delimiter, P: Profile> FromStr for IdentBuf<B, D, P>

Source§

type Err = Error

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

impl<B, D, P> Hash for IdentBuf<B, D, P>

Source§

fn hash<H>(&self, state: &mut H)
where H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<I, B, D, P> Index<I> for IdentBuf<B, D, P>
where I: SliceIndex<Fragment<B, D, P>>,

Source§

type Output = Fragment<B, D, P>

The returned type after indexing.
Source§

fn index(&self, index: I) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<B, D, P> Ord for IdentBuf<B, D, P>

Source§

fn cmp(&self, rhs: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

fn clamp_to<R>(self, range: R) -> Self
where Self: Sized, R: ClampBounds<Self>,

🔬This is a nightly-only experimental API. (clamp_to)
Restrict a value to a certain range. Read more
Source§

impl<B, D, P> PartialEq<&str> for IdentBuf<B, D, P>

Source§

fn eq(&self, rhs: &&str) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<B1, B2, D1, D2, P1, P2> PartialEq<Chunk<B1, D1, P1>> for IdentBuf<B2, D2, P2>

Source§

fn eq(&self, rhs: &Chunk<B1, D1, P1>) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<B1, B2, D1, D2, P1, P2> PartialEq<Fragment<B1, D1, P1>> for IdentBuf<B2, D2, P2>

Source§

fn eq(&self, rhs: &Fragment<B1, D1, P1>) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<B1, B2, D1, D2, P1, P2> PartialEq<FragmentBuf<B1, D1, P1>> for IdentBuf<B2, D2, P2>

Source§

fn eq(&self, rhs: &FragmentBuf<B1, D1, P1>) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<B1, B2, D1, D2, P1, P2> PartialEq<Ident<B1, D1, P1>> for IdentBuf<B2, D2, P2>

Source§

fn eq(&self, rhs: &Ident<B1, D1, P1>) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<B1, B2, D1, D2, P1, P2> PartialEq<IdentBuf<B1, D1, P1>> for IdentBuf<B2, D2, P2>

Source§

fn eq(&self, rhs: &IdentBuf<B1, D1, P1>) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<B1, B2, D1, D2, P1, P2> PartialEq<IdentBuf<B1, D1, P1>> for Chunk<B2, D2, P2>

Source§

fn eq(&self, rhs: &IdentBuf<B1, D1, P1>) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<B1, B2, D1, D2, P1, P2> PartialEq<IdentBuf<B1, D1, P1>> for Fragment<B2, D2, P2>

Source§

fn eq(&self, rhs: &IdentBuf<B1, D1, P1>) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<B1, B2, D1, D2, P1, P2> PartialEq<IdentBuf<B1, D1, P1>> for FragmentBuf<B2, D2, P2>

Source§

fn eq(&self, rhs: &IdentBuf<B1, D1, P1>) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<B1, B2, D1, D2, P1, P2> PartialEq<IdentBuf<B1, D1, P1>> for Ident<B2, D2, P2>

Source§

fn eq(&self, rhs: &IdentBuf<B1, D1, P1>) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<'a, B, D, P> PartialEq<IdentBuf<B, D, P>> for &str

Source§

fn eq(&self, rhs: &IdentBuf<B, D, P>) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<'a, B, D, P> PartialEq<IdentBuf<B, D, P>> for str

Source§

fn eq(&self, rhs: &IdentBuf<B, D, P>) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<B, D, P> PartialEq<IdentBuf<B, D, P>> for String

Source§

fn eq(&self, rhs: &IdentBuf<B, D, P>) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<B, D, P> PartialEq<String> for IdentBuf<B, D, P>

Source§

fn eq(&self, rhs: &String) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<B, D, P> PartialEq<str> for IdentBuf<B, D, P>

Source§

fn eq(&self, rhs: &str) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<B, D, P> PartialOrd<&str> for IdentBuf<B, D, P>

Source§

fn partial_cmp(&self, rhs: &&str) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<B1, B2, D1, D2, P1, P2> PartialOrd<Chunk<B1, D1, P1>> for IdentBuf<B2, D2, P2>

Source§

fn partial_cmp(&self, rhs: &Chunk<B1, D1, P1>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<B1, B2, D1, D2, P1, P2> PartialOrd<Fragment<B1, D1, P1>> for IdentBuf<B2, D2, P2>

Source§

fn partial_cmp(&self, rhs: &Fragment<B1, D1, P1>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<B1, B2, D1, D2, P1, P2> PartialOrd<FragmentBuf<B1, D1, P1>> for IdentBuf<B2, D2, P2>

Source§

fn partial_cmp(&self, rhs: &FragmentBuf<B1, D1, P1>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<B1, B2, D1, D2, P1, P2> PartialOrd<Ident<B1, D1, P1>> for IdentBuf<B2, D2, P2>

Source§

fn partial_cmp(&self, rhs: &Ident<B1, D1, P1>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<B1, B2, D1, D2, P1, P2> PartialOrd<IdentBuf<B1, D1, P1>> for IdentBuf<B2, D2, P2>

Source§

fn partial_cmp(&self, rhs: &IdentBuf<B1, D1, P1>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<B1, B2, D1, D2, P1, P2> PartialOrd<IdentBuf<B1, D1, P1>> for Chunk<B2, D2, P2>

Source§

fn partial_cmp(&self, rhs: &IdentBuf<B1, D1, P1>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<B1, B2, D1, D2, P1, P2> PartialOrd<IdentBuf<B1, D1, P1>> for Fragment<B2, D2, P2>

Source§

fn partial_cmp(&self, rhs: &IdentBuf<B1, D1, P1>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<B1, B2, D1, D2, P1, P2> PartialOrd<IdentBuf<B1, D1, P1>> for FragmentBuf<B2, D2, P2>

Source§

fn partial_cmp(&self, rhs: &IdentBuf<B1, D1, P1>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<B1, B2, D1, D2, P1, P2> PartialOrd<IdentBuf<B1, D1, P1>> for Ident<B2, D2, P2>

Source§

fn partial_cmp(&self, rhs: &IdentBuf<B1, D1, P1>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<B, D, P> PartialOrd<IdentBuf<B, D, P>> for &str

Source§

fn partial_cmp(&self, rhs: &IdentBuf<B, D, P>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<B, D, P> PartialOrd<IdentBuf<B, D, P>> for str

Source§

fn partial_cmp(&self, rhs: &IdentBuf<B, D, P>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<B, D, P> PartialOrd<IdentBuf<B, D, P>> for String

Source§

fn partial_cmp(&self, rhs: &IdentBuf<B, D, P>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<B, D, P> PartialOrd<String> for IdentBuf<B, D, P>

Source§

fn partial_cmp(&self, rhs: &String) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<B, D, P> PartialOrd<str> for IdentBuf<B, D, P>

Source§

fn partial_cmp(&self, rhs: &str) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Auto Trait Implementations§

§

impl<B, D, P> Freeze for IdentBuf<B, D, P>
where FragmentBuf<B, D, P>: Freeze,

§

impl<B, D, P> RefUnwindSafe for IdentBuf<B, D, P>
where FragmentBuf<B, D, P>: RefUnwindSafe,

§

impl<B, D, P> Send for IdentBuf<B, D, P>
where FragmentBuf<B, D, P>: Send,

§

impl<B, D, P> Sync for IdentBuf<B, D, P>
where FragmentBuf<B, D, P>: Sync,

§

impl<B, D, P> Unpin for IdentBuf<B, D, P>
where FragmentBuf<B, D, P>: Unpin,

§

impl<B, D, P> UnsafeUnpin for IdentBuf<B, D, P>
where FragmentBuf<B, D, P>: UnsafeUnpin,

§

impl<B, D, P> UnwindSafe for IdentBuf<B, D, P>
where FragmentBuf<B, D, P>: UnwindSafe,

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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.