Struct quetta::Text[][src]

pub struct Text(_);
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

Creates a new Text by copying the provided slice.

Gets the Text as a slice.

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

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

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

Is this Text empty?

Example
use quetta::Text;

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

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

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

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

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

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

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

Performs the conversion.

Immutably borrows from an owned value. Read more

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

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

Formats the value using the given formatter. Read more

Performs the conversion.

Performs the conversion.

Performs the conversion.

The associated error which can be returned from parsing.

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

Feeds this value into the given Hasher. Read more

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

The returned type after indexing.

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

The returned type after indexing.

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

This method returns an Ordering between self and other. Read more

Compares and returns the maximum of two values. Read more

Compares and returns the minimum of two values. Read more

Restrict a value to a certain interval. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.