pub enum Segment<D, C> {
Chunk(C),
Delim(D),
}Expand description
A part of an identifier returned during segmentation.
The default type contents of a segment are:
D: The delimiter from the fragment/identifier.C: A chunk formed from the type parameters (&Chunk<B, D, P>).
If you don’t need strong typing, you can use the type_erased method to
drop the type information (producing char and &str). There is a typedef
associated with this type for convenience (StrSegment).
You have two main things you can control about how segmentation happens;
whether or not a contiguous chunk is broken into it’s largest “words” (runs
of characters with no natural boundaries as defined by B), and whether or
not you are returned the byte offset to the segment from the original data.
| Words \ Indices | No | Yes |
|---|---|---|
| No | chunked_segments | chunked_segment_indices |
| Yes | segments | segment_indices |
Normally, you’ll want chunks broken into their largest words. So we’ve named
the variant that breaks chunks into their largest words simply segments.
See the respective functions for more details.
Variants§
Implementations§
Source§impl<D> Segment<D, &str>
impl<D> Segment<D, &str>
Sourcepub fn into_owned(self) -> Segment<D, String>
pub fn into_owned(self) -> Segment<D, String>
Converts a type-erased segment into an owned representation.
§Examples
let segment = CamelSegment::Delim(LowLine)
.type_erased_chunk()
.into_owned();
assert_eq!(segment, CamelSegment::Delim(LowLine).type_erased_chunk());
let segment = CamelSegment::Chunk(CamelChunk::new("Upper")?)
.type_erased_chunk()
.into_owned();
assert_eq!(segment, StringSegment::Chunk(String::from("Upper")));Source§impl<D: Delimiter> Segment<D, String>
impl<D: Delimiter> Segment<D, String>
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the byte length of the string representation of self.
For delimiters, this will first cast as a character, then return the UTF-8 length of the character. For chunks, the length of the chunk is used directly.
§Examples
let segment = CamelSegment::Delim(LowLine)
.type_erased_chunk()
.into_owned();
assert_eq!(segment.len(), 1);
let segment = CamelSegment::Chunk(CamelChunk::new("Upper")?)
.type_erased_chunk()
.into_owned();
assert_eq!(segment.len(), 5);Source§impl Segment<char, String>
impl Segment<char, String>
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the byte length of the string representation of self.
For delimiters, this will first cast as a character, then return the UTF-8 length of the character. For chunks, the length of the chunk is used directly.
§Examples
let segment = CamelSegment::Delim(LowLine)
.type_erased()
.into_owned();
assert_eq!(segment.len(), 1);
let segment = CamelSegment::Chunk(CamelChunk::new("Upper")?)
.type_erased()
.into_owned();
assert_eq!(segment.len(), 5);Source§impl<'a, B, D: Delimiter, P> Segment<D, &'a Chunk<B, D, P>>
impl<'a, B, D: Delimiter, P> Segment<D, &'a Chunk<B, D, P>>
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true if the contents of this segment is an empty chunk.
§Examples
let segment = CamelSegment::Delim(LowLine);
assert_eq!(segment.is_empty(), false);
let segment = CamelSegment::Chunk(CamelChunk::new("Upper")?);
assert_eq!(segment.is_empty(), false);
let segment = CamelSegment::Chunk(CamelChunk::new("")?);
assert_eq!(segment.is_empty(), true);Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the byte length of the string representation of self.
For delimiters, this will first cast as a character, then return the UTF-8 length of the character. For chunks, the length of the chunk is used directly.
§Examples
let segment = CamelSegment::Delim(LowLine);
assert_eq!(segment.len(), 1);
let segment = CamelSegment::Chunk(CamelChunk::new("Upper")?);
assert_eq!(segment.len(), 5);Sourcepub fn type_erased(self) -> Segment<char, &'a str>
pub fn type_erased(self) -> Segment<char, &'a str>
Converts the segment to a type-erased representation.
The Delim variant will be converted to a char, and the Chunk
variant will be converted to a &str.
§Examples
let segment = CamelSegment::Delim(LowLine).type_erased();
assert!(segment.is_delim_and(|c| *c == '_'));
let segment = CamelSegment::Chunk(CamelChunk::new("Upper")?).type_erased();
assert!(segment.is_chunk_and(|c| *c == "Upper"));Sourcepub fn type_erased_delim(self) -> Segment<char, &'a Chunk<B, D, P>>
pub fn type_erased_delim(self) -> Segment<char, &'a Chunk<B, D, P>>
Converts a segment’s delimiter to a type-erased representation.
The Delim variant will be converted to a char, but the chunk
will remain strongly-typed.
§Examples
let segment = CamelSegment::Delim(LowLine).type_erased_delim();
assert!(segment.is_delim_and(|c| *c == '_'));
let segment = CamelSegment::Chunk(CamelChunk::new("Upper")?).type_erased_delim();
assert!(segment.is_chunk_and(|c| *c == "Upper"));Sourcepub fn type_erased_chunk(self) -> Segment<D, &'a str>
pub fn type_erased_chunk(self) -> Segment<D, &'a str>
Converts a segment’s chunk to a type-erased representation.
The Chunk variant will be converted to a &str, but the delimiter
will remain strongly-typed.
§Examples
let segment = CamelSegment::Delim(LowLine).type_erased_chunk();
assert!(segment.is_delim_and(|c| *c == '_'));
let segment = CamelSegment::Chunk(CamelChunk::new("Upper")?).type_erased_chunk();
assert!(segment.is_chunk_and(|c| *c == "Upper"));Source§impl<'a, D: Delimiter> Segment<D, &'a str>
impl<'a, D: Delimiter> Segment<D, &'a str>
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true if the contents of this segment is an empty chunk.
§Examples
let segment = CamelSegment::Delim(LowLine)
.type_erased_chunk();
assert_eq!(segment.is_empty(), false);
let segment = CamelSegment::Chunk(CamelChunk::new("Upper")?)
.type_erased_chunk();
assert_eq!(segment.is_empty(), false);
let segment = CamelSegment::Chunk(CamelChunk::new("")?)
.type_erased_chunk();
assert_eq!(segment.is_empty(), true);Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the byte length of the string representation of self.
For delimiters, this will first cast as a character, then return the UTF-8 length of the character. For chunks, the length of the chunk is used directly.
§Examples
let segment = CamelSegment::Delim(LowLine)
.type_erased_chunk();
assert_eq!(segment.len(), 1);
let segment = CamelSegment::Chunk(CamelChunk::new("Upper")?)
.type_erased_chunk();
assert_eq!(segment.len(), 5);Sourcepub fn type_erased(self) -> Segment<char, &'a str>
pub fn type_erased(self) -> Segment<char, &'a str>
Converts the segment to a type-erased representation.
The Delim variant will be converted to a char, and the Chunk
variant will be converted to a &str.
§Examples
let segment = CamelSegment::Delim(LowLine)
.type_erased_chunk().type_erased();
assert!(segment.is_delim_and(|c| *c == '_'));
let segment = CamelSegment::Chunk(CamelChunk::new("Upper")?)
.type_erased_chunk().type_erased();
assert!(segment.is_chunk_and(|c| *c == "Upper"));Source§impl<'a, B, D, P> Segment<char, &'a Chunk<B, D, P>>
impl<'a, B, D, P> Segment<char, &'a Chunk<B, D, P>>
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true if the contents of this segment is an empty chunk.
§Examples
let segment = CamelSegment::Delim(LowLine)
.type_erased_delim();
assert_eq!(segment.is_empty(), false);
let segment = CamelSegment::Chunk(CamelChunk::new("Upper")?)
.type_erased_delim();
assert_eq!(segment.is_empty(), false);
let segment = CamelSegment::Chunk(CamelChunk::new("")?)
.type_erased_delim();
assert_eq!(segment.is_empty(), true);Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the byte length of the string representation of self.
For character delimiters, this will return the UTF-8 length of the character. For chunks, the length of the chunk is used directly.
§Examples
let segment = CamelSegment::Delim(LowLine)
.type_erased_delim();
assert_eq!(segment.len(), 1);
let segment = CamelSegment::Chunk(CamelChunk::new("Upper")?)
.type_erased_delim();
assert_eq!(segment.len(), 5);Sourcepub fn type_erased(self) -> Segment<char, &'a str>
pub fn type_erased(self) -> Segment<char, &'a str>
Converts the segment to a type-erased representation.
The Chunk variant will be converted to a &str.
§Examples
let segment = CamelSegment::Delim(LowLine)
.type_erased_delim().type_erased();
assert!(segment.is_delim_and(|c| *c == '_'));
let segment = CamelSegment::Chunk(CamelChunk::new("Upper")?)
.type_erased_delim().type_erased();
assert!(segment.is_chunk_and(|c| *c == "Upper"));Source§impl Segment<char, &str>
impl Segment<char, &str>
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true if the contents of this segment is an empty chunk.
§Examples
let segment = CamelSegment::Delim(LowLine)
.type_erased();
assert_eq!(segment.is_empty(), false);
let segment = CamelSegment::Chunk(CamelChunk::new("Upper")?)
.type_erased();
assert_eq!(segment.is_empty(), false);
let segment = CamelSegment::Chunk(CamelChunk::new("")?)
.type_erased();
assert_eq!(segment.is_empty(), true);Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the byte length of the string representation of self.
For character delimiters, this will return the UTF-8 length of the character. For chunks, the length of the chunk is used directly.
§Examples
let segment = CamelSegment::Delim(LowLine)
.type_erased();
assert_eq!(segment.len(), 1);
let segment = CamelSegment::Chunk(CamelChunk::new("Upper")?)
.type_erased();
assert_eq!(segment.len(), 5);Source§impl<D, C> Segment<D, C>
impl<D, C> Segment<D, C>
Sourcepub fn as_str(&self) -> &str
pub fn as_str(&self) -> &str
Returns the original string representation of this segment.
§Examples
let delim = CamelSegment::Delim(LowLine);
assert_eq!(delim.as_str(), "_");
let chunk = CamelSegment::Chunk(CamelChunk::new("chunk")?);
assert_eq!(chunk.as_str(), "chunk");Sourcepub const fn is_delim(&self) -> bool
pub const fn is_delim(&self) -> bool
Returns true if the segment contains a delimiter, false if not.
§Examples
let delim = CamelSegment::Delim(LowLine);
assert!(delim.is_delim());
let chunk = CamelSegment::Chunk(CamelChunk::new("chunk")?);
assert!(!chunk.is_delim());Sourcepub fn is_delim_and(&self, pred: impl FnOnce(&D) -> bool) -> bool
pub fn is_delim_and(&self, pred: impl FnOnce(&D) -> bool) -> bool
Returns true if the segment contains a delimiter, and if the
provided predicate passes. Returns false if not.
§Examples
let delim = CamelSegment::Delim(LowLine);
assert!(delim.is_delim_and(|d| *d == '_'));
assert!(!delim.is_delim_and(|d| *d == '-'));
let chunk = CamelSegment::Chunk(CamelChunk::new("chunk")?);
assert!(!chunk.is_delim_and(|d| *d == '_'));Sourcepub fn is_delim_or(&self, pred: impl FnOnce(&C) -> bool) -> bool
pub fn is_delim_or(&self, pred: impl FnOnce(&C) -> bool) -> bool
Returns true if the segment contains a delimiter, or if the segment
contained a chunk, and provided predicate passes. Returns false
otherwise.
§Examples
let delim = CamelSegment::Delim(LowLine);
assert!(delim.is_delim_or(|c| *c == "chunk"));
let chunk = CamelSegment::Chunk(CamelChunk::new("chunk")?);
assert!(chunk.is_delim_or(|c| *c == "chunk"));
assert!(!chunk.is_delim_or(|c| *c == "text"));Sourcepub const fn is_chunk(&self) -> bool
pub const fn is_chunk(&self) -> bool
Returns true if the segment contains a chunk, false if not.
§Examples
let delim = CamelSegment::Delim(LowLine);
assert!(!delim.is_chunk());
let chunk = CamelSegment::Chunk(CamelChunk::new("chunk")?);
assert!(chunk.is_chunk());Sourcepub fn is_chunk_and(&self, pred: impl FnOnce(&C) -> bool) -> bool
pub fn is_chunk_and(&self, pred: impl FnOnce(&C) -> bool) -> bool
Returns true if the segment contains a chunk, and if the provided
predicate passes. Returns false otherwise.
§Examples
let delim = CamelSegment::Delim(LowLine);
assert!(!delim.is_chunk_and(|c| *c == "chunk"));
let chunk = CamelSegment::Chunk(CamelChunk::new("chunk")?);
assert!(chunk.is_chunk_and(|c| *c == "chunk"));
assert!(!chunk.is_chunk_and(|c| *c == "text"));Sourcepub fn is_chunk_or(&self, pred: impl FnOnce(&D) -> bool) -> bool
pub fn is_chunk_or(&self, pred: impl FnOnce(&D) -> bool) -> bool
Returns true if the segment contains a chunk, or if the segment
contained a delimiter, and provided predicate passes. Returns false
otherwise.
§Examples
let delim = CamelSegment::Delim(LowLine);
assert!(delim.is_chunk_or(|d| *d == '_'));
assert!(!delim.is_chunk_or(|d| *d == '-'));
let chunk = CamelSegment::Chunk(CamelChunk::new("chunk")?);
assert!(chunk.is_chunk_or(|d| *d == '_'));