Struct Text

Source
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

Source

pub fn new<'a, I: Into<&'a str>>(s: I) -> Self

Creates a new Text by copying the provided slice.

Source

pub fn as_str(&self) -> &str

Gets the Text as a slice.

Source

pub fn substring(&self, start: usize, len: usize) -> Text

Creates another Text with a provided start code point and length. Will panic if the substring exceeds the Text’s bounds.

§Example
use quetta::Text;

let text = Text::new("qwerty");
let sub = text.substring(0, 2);
assert_eq!("qw", sub.as_str());
Source

pub fn slice(&self, start: usize, end: usize) -> Text

Creates another Text with a provided start code point and end code point, similar to the slice operator. Will panic if the slice exceeds the Text’s bounds.

§Example
use quetta::Text;

let text = Text::new("qwerty");
let sub = text.slice(1, 3);
assert_eq!("we", sub.as_str());
Source

pub fn len(&self) -> usize

Gets the length of the Text.

§Example
use quetta::Text;

let text = Text::new("I was born in a water moon");
assert_eq!(26, text.len());
Source

pub fn is_empty(&self) -> bool

Is this Text empty?

§Example
use quetta::Text;

let text = Text::default();
assert!(text.is_empty());
Source

pub fn try_lift_slice(&self, slice: &str) -> Option<Text>

Attempt to create a Text from a slice sliced from this Text. Will return None if the slice is not contained in self.

§Example
use quetta::Text;

let text = Text::new("Test");
let s = &text.as_str()[0..2];
let st = text.try_lift_slice(s);
assert!(st.is_some());
assert_eq!("Te", st.unwrap().as_str());
Source

pub fn lift_slice(&self, slice: &str) -> Text

Creates a Text from a slice, if possible, as a substring of self.

§Example
use quetta::Text;

let text = Text::new("Test");
let s = &text.as_str()[0..2];
let st = text.lift_slice(s);
assert_eq!("Te", st.as_str());
Source

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());
Source

pub fn lift<F: Fn(&str) -> &str>(&self, f: F) -> Text

Lifts a function &str -> &str so it will be executed on the &str self. If the returned &str is not contained in self, a new Text will be created from it.

§Example
use quetta::Text;

let text = Text::new("  a  ");
let trimmed = text.try_lift(|t| t.trim())?;
assert_eq!("a", trimmed.as_str());
Source

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());
Source

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());

Trait Implementations§

Source§

impl AsRef<str> for Text

Source§

fn as_ref(&self) -> &str

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

impl Borrow<str> for Text

Source§

fn borrow(&self) -> &str

Immutably borrows from an owned value. Read more
Source§

impl Clone for Text

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Text

Source§

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

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

impl Default for Text

Source§

fn default() -> Self

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

impl Display for Text

Source§

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

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

impl<'a> From<&'a Text> for &'a str

Source§

fn from(t: &'a Text) -> Self

Converts to this type from the input type.
Source§

impl<'a> From<&'a Text> for String

Source§

fn from(text: &'a Text) -> Self

Converts to this type from the input type.
Source§

impl<'a> From<&'a str> for Text

Source§

fn from(t: &'a str) -> Self

Converts to this type from the input type.
Source§

impl FromStr for Text

Source§

type Err = ()

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 Hash for Text

Source§

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

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<'a, Idx: SliceIndex<str>> Index<Idx> for &'a Text

Source§

type Output = <Idx as SliceIndex<str>>::Output

The returned type after indexing.
Source§

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

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

impl<'a, Idx: SliceIndex<str>> Index<Idx> for Text

Source§

type Output = <Idx as SliceIndex<str>>::Output

The returned type after indexing.
Source§

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

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

impl Ord for Text

Source§

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

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

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

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

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

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

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

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

impl PartialEq for Text

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for Text

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · 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 · 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 · 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 · 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 Eq for Text

Auto Trait Implementations§

§

impl Freeze for Text

§

impl RefUnwindSafe for Text

§

impl Send for Text

§

impl Sync for Text

§

impl Unpin for Text

§

impl UnwindSafe for Text

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<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 = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.