pub struct Text(/* private fields */);
Expand description
The primary type of quetta, representing an immutable sequence of characters.
Internally, this can be either a full string or a slice into another Text
.
Can be cloned cheaply.
Implementations§
Source§impl Text
impl Text
Sourcepub fn new<'a, I: Into<&'a str>>(s: I) -> Self
pub fn new<'a, I: Into<&'a str>>(s: I) -> Self
Creates a new Text
by copying the provided slice.
Sourcepub fn try_lift_slice(&self, slice: &str) -> Option<Text>
pub fn try_lift_slice(&self, slice: &str) -> Option<Text>
Sourcepub fn lift_slice(&self, slice: &str) -> Text
pub fn lift_slice(&self, slice: &str) -> Text
Sourcepub fn try_lift<F: Fn(&str) -> &str>(&self, f: F) -> Option<Text>
pub fn try_lift<F: Fn(&str) -> &str>(&self, f: F) -> Option<Text>
Lifts a function &str -> &str
so it will be executed on the &str
self.
Will return none if the &str
returned by the function is not contained in self
.
§Example
use quetta::Text;
let text = Text::new(" a ");
let trimmed = text.try_lift(|t| t.trim())?;
assert_eq!("a", trimmed.as_str());
Sourcepub fn try_lift_many<'a, I: Iterator<Item = &'a str> + 'a, F: Fn(&'a str) -> I>(
&'a self,
f: F,
) -> impl Iterator<Item = Text> + 'a
pub fn try_lift_many<'a, I: Iterator<Item = &'a str> + 'a, F: Fn(&'a str) -> I>( &'a self, f: F, ) -> impl Iterator<Item = Text> + 'a
Lifts a function &str -> Iterator<Item=&str>
so it will be executed on self
and returns an Iterator<Item=[
Text]>
.
If one of the &str
in the iterator is not contained in self
, the iterator will end.
§Example
use quetta::Text;
let t = Text::new("A:B:C:D");
let lifted: Vec<Text> = t.try_lift_many(|s| s.split(":")).collect();
assert_eq!(4, lifted.len());
assert_eq!("A", lifted[0].as_str());
assert_eq!("B", lifted[1].as_str());
assert_eq!("C", lifted[2].as_str());
assert_eq!("D", lifted[3].as_str());
Sourcepub fn lift_many<'a, I: Iterator<Item = &'a str> + 'a, F: Fn(&'a str) -> I>(
&'a self,
f: F,
) -> impl Iterator<Item = Text> + 'a
pub fn lift_many<'a, I: Iterator<Item = &'a str> + 'a, F: Fn(&'a str) -> I>( &'a self, f: F, ) -> impl Iterator<Item = Text> + 'a
Lifts a function &str -> Iterator<Item=&str>
so it will be executed on self
and returns an Iterator<Item=[
Text]>
.
If the iterator yields a &str
that is not contained within self
, a new Text
will be created from it.
§Example
use quetta::Text;
let t = Text::new("A:B:C:D");
let lifted: Vec<Text> = t.lift_many(|s| s.split(":")).collect();
assert_eq!(4, lifted.len());
assert_eq!("A", lifted[0].as_str());
assert_eq!("B", lifted[1].as_str());
assert_eq!("C", lifted[2].as_str());
assert_eq!("D", lifted[3].as_str());