Struct basic_text::TextStr
source · [−]#[repr(transparent)]pub struct TextStr(_);Expand description
Text slices.
TextStr is to TextString as str is to String. It is usually
used for borrowing, in the form of &TextStr.
Examples
Text literals are text slices:
use basic_text::{text, TextStr};
let hello = text!("Hello, world!");
// with an explicit type annotation
let hello: &'static TextStr = text!("Hello, world!");They are ’static because they’re stored directly in the final binary, and so will be valid for the ’static duration.
Implementations
sourceimpl TextStr
impl TextStr
sourcepub fn from_text_bytes(b: &[u8]) -> Result<&Self, TextError>
pub fn from_text_bytes(b: &[u8]) -> Result<&Self, TextError>
Converts a slice of bytes to a text string slice.
sourcepub fn from_text(s: &str) -> Result<&Self, TextError>
pub fn from_text(s: &str) -> Result<&Self, TextError>
Converts a string slice to a text string slice.
sourcepub fn from_text_bytes_mut(b: &mut [u8]) -> Result<&mut Self, TextError>
pub fn from_text_bytes_mut(b: &mut [u8]) -> Result<&mut Self, TextError>
Converts a mutable slice of bytes to a mutable text string slice.
sourcepub fn from_text_mut(s: &mut str) -> Result<&mut Self, TextError>
pub fn from_text_mut(s: &mut str) -> Result<&mut Self, TextError>
Converts a mutable string slice to a mutable text string slice.
sourcepub unsafe fn from_text_bytes_unchecked(b: &[u8]) -> &Self
pub unsafe fn from_text_bytes_unchecked(b: &[u8]) -> &Self
Converts a slice of bytes to a text string slice without checking that the string contains valid Basic Text.
Safety
This function is unsafe because it does not check that the bytes passed
to it are valid Basic Text. If this constraint is violated, undefined
behavior results, as the rest of this crate assumes that &TextStrs
are valid Basic Text.
sourcepub unsafe fn from_text_unchecked(s: &str) -> &Self
pub unsafe fn from_text_unchecked(s: &str) -> &Self
Converts a string slice to a text string slice without checking that the string contains valid Basic Text.
Safety
This function is unsafe because it does not check that the bytes passed
to it are valid Basic Text. If this constraint is violated, undefined
behavior results, as the rest of this crate assumes that &TextStrs
are valid Basic Text.
sourcepub unsafe fn from_text_bytes_unchecked_mut(b: &mut [u8]) -> &mut Self
pub unsafe fn from_text_bytes_unchecked_mut(b: &mut [u8]) -> &mut Self
Converts a slice of bytes to a text string slice without checking that the string contains valid Basic Text; mutable version.
Safety
This function is unsafe because it does not check that the bytes passed
to it are valid Basic Text. If this constraint is violated, undefined
behavior results, as the rest of this crate assumes that &TextStrs
are valid Basic Text.
sourcepub unsafe fn from_text_unchecked_mut(s: &mut str) -> &mut Self
pub unsafe fn from_text_unchecked_mut(s: &mut str) -> &mut Self
Converts a string slice to a text string slice without checking that the string contains valid Basic Text; mutable version.
Safety
This function is unsafe because it does not check that the string
passed to it is valid Basic Text. If this constraint is violated,
undefined behavior results, as the rest of this crate assumes that
&TextStrs are valid Basic Text.
sourcepub unsafe fn from_boxed_text_bytes_unchecked(v: Box<[u8]>) -> Box<Self>
pub unsafe fn from_boxed_text_bytes_unchecked(v: Box<[u8]>) -> Box<Self>
Converts a boxed slice of bytes to a boxed text string slice without checking that the string contains valid basic text.
Safety
This function is unsafe because it does not check that the bytes passed
to it are valid Basic Text. If this constraint is violated, undefined
behavior results, as the rest of this crate assumes that &TextStrs
are valid Basic Text.
sourcepub unsafe fn from_boxed_text_unchecked(v: Box<str>) -> Box<Self>
pub unsafe fn from_boxed_text_unchecked(v: Box<str>) -> Box<Self>
Converts a boxed string slice to a boxed text string slice without checking that the string contains valid basic text.
Safety
This function is unsafe because it does not check that the bytes passed
to it are valid Basic Text. If this constraint is violated, undefined
behavior results, as the rest of this crate assumes that &TextStrs
are valid Basic Text.
sourcepub const fn as_bytes(&self) -> &[u8]ⓘNotable traits for &'_ [u8]impl<'_> Read for &'_ [u8]impl<'_> Write for &'_ mut [u8]
pub const fn as_bytes(&self) -> &[u8]ⓘNotable traits for &'_ [u8]impl<'_> Read for &'_ [u8]impl<'_> Write for &'_ mut [u8]
Converts a text string slice to a byte slice.
sourcepub unsafe fn as_bytes_mut(&mut self) -> &mut [u8]ⓘNotable traits for &'_ [u8]impl<'_> Read for &'_ [u8]impl<'_> Write for &'_ mut [u8]
pub unsafe fn as_bytes_mut(&mut self) -> &mut [u8]ⓘNotable traits for &'_ [u8]impl<'_> Read for &'_ [u8]impl<'_> Write for &'_ mut [u8]
Converts a mutable text string slice to a mutable byte slice.
Safety
The caller must ensure that the content of the slice is valid
Basic Text before the borrow ends and the underlying TextStr is used.
Use of a TextStr whose contents are not valid Basic Text is undefined
behavior.
sourcepub fn as_mut_ptr(&mut self) -> *mut u8
pub fn as_mut_ptr(&mut self) -> *mut u8
Converts a mutable text string slice to a raw pointer.
sourcepub fn split_at(&self, mid: usize) -> (&Self, &Self)
pub fn split_at(&self, mid: usize) -> (&Self, &Self)
Divide one text string slice into two at an index.
sourcepub fn split_at_mut(&mut self, mid: usize) -> (&mut Self, &mut Self)
pub fn split_at_mut(&mut self, mid: usize) -> (&mut Self, &mut Self)
Divide one mutable text string slice into two at an index.
sourcepub fn char_indices(&self) -> CharIndices<'_>
pub fn char_indices(&self) -> CharIndices<'_>
Returns an iterator over the chars of a text string slice, and their
positions.
sourcepub fn lines(&self) -> Lines<'_>
pub fn lines(&self) -> Lines<'_>
An iterator over the lines of a text string, as text string slices.
TODO: There should be a TextLines which yields &TextStrs.
sourcepub fn encode_utf16(&self) -> EncodeUtf16<'_>
pub fn encode_utf16(&self) -> EncodeUtf16<'_>
Returns an iterator of u16 over the string encoded as Basic Text.
sourcepub fn contains<'a, P>(&'a self, pat: P) -> bool where
P: Pattern<'a>,
pub fn contains<'a, P>(&'a self, pat: P) -> bool where
P: Pattern<'a>,
Returns true if the given pattern matches a sub-slice of this
text string slice.
Returns false if it does not.
sourcepub fn starts_with<'a, P>(&'a self, pat: P) -> bool where
P: Pattern<'a>,
pub fn starts_with<'a, P>(&'a self, pat: P) -> bool where
P: Pattern<'a>,
Returns true if the given pattern matches a prefix of this
text string slice.
Returns false if it does not.
sourcepub fn ends_with<'a, P>(&'a self, pat: P) -> bool where
P: Pattern<'a>,
<P as Pattern<'a>>::Searcher: ReverseSearcher<'a>,
pub fn ends_with<'a, P>(&'a self, pat: P) -> bool where
P: Pattern<'a>,
<P as Pattern<'a>>::Searcher: ReverseSearcher<'a>,
Returns true if the given pattern matches a suffix of this
text string slice.
Returns false if it does not.
sourcepub fn find<'a, P>(&'a self, pat: P) -> Option<usize> where
P: Pattern<'a>,
pub fn find<'a, P>(&'a self, pat: P) -> Option<usize> where
P: Pattern<'a>,
Returns the byte index of the first character of this text string slice that matches the pattern.
Returns None if the pattern doesn’t match.
sourcepub fn rfind<'a, P>(&'a self, pat: P) -> Option<usize> where
P: Pattern<'a>,
<P as Pattern<'a>>::Searcher: ReverseSearcher<'a>,
pub fn rfind<'a, P>(&'a self, pat: P) -> Option<usize> where
P: Pattern<'a>,
<P as Pattern<'a>>::Searcher: ReverseSearcher<'a>,
Returns the byte index for the first character of the rightmost match of the pattern in this text string slice.
Returns None if the pattern doesn’t match.
sourcepub fn matches<'a, P>(&'a self, pat: P) -> Matches<'a, P> where
P: Pattern<'a>,
pub fn matches<'a, P>(&'a self, pat: P) -> Matches<'a, P> where
P: Pattern<'a>,
An iterator over the disjoint matches of a pattern within the given text string slice.
sourcepub fn rmatches<'a, P>(&'a self, pat: P) -> RMatches<'a, P> where
P: Pattern<'a>,
<P as Pattern<'a>>::Searcher: ReverseSearcher<'a>,
pub fn rmatches<'a, P>(&'a self, pat: P) -> RMatches<'a, P> where
P: Pattern<'a>,
<P as Pattern<'a>>::Searcher: ReverseSearcher<'a>,
An iterator over the disjoint matches of a pattern within this text string slice, yielded in reverse order.
TODO: There should be a TextRMatches which yields &TextStrs.
sourcepub fn match_indices<'a, P>(&'a self, pat: P) -> MatchIndices<'a, P> where
P: Pattern<'a>,
pub fn match_indices<'a, P>(&'a self, pat: P) -> MatchIndices<'a, P> where
P: Pattern<'a>,
An iterator over the disjoint matches of a pattern within this text string slice as well as the index that the match starts at.
TODO: There should be a TextMatchIndices which yields &TextStrs.
sourcepub fn rmatch_indices<'a, P>(&'a self, pat: P) -> RMatchIndices<'a, P> where
P: Pattern<'a>,
<P as Pattern<'a>>::Searcher: ReverseSearcher<'a>,
pub fn rmatch_indices<'a, P>(&'a self, pat: P) -> RMatchIndices<'a, P> where
P: Pattern<'a>,
<P as Pattern<'a>>::Searcher: ReverseSearcher<'a>,
An iterator over the disjoint matches of a pattern within self,
yielded in reverse order along with the index of the match.
TODO: There should be a TextRMatchIndices which yields &TextStrs.
sourcepub fn trim(&self) -> &Self
pub fn trim(&self) -> &Self
Returns a text string slice with leading and trailing whitespace removed.
sourcepub fn trim_start(&self) -> &Self
pub fn trim_start(&self) -> &Self
Returns a text string slice with leading whitespace removed.
sourcepub fn parse<F>(&self) -> Result<F, <F as FromStr>::Err> where
F: FromStr,
pub fn parse<F>(&self) -> Result<F, <F as FromStr>::Err> where
F: FromStr,
Parses this text string slice into another type.
sourcepub fn is_ascii(&self) -> bool
pub fn is_ascii(&self) -> bool
Checks if all characters in this text string are within the ASCII range.
sourcepub fn eq_ignore_ascii_case(&self, other: &Self) -> bool
pub fn eq_ignore_ascii_case(&self, other: &Self) -> bool
Checks that two text strings are an ASCII case-insensitive match.
sourcepub fn into_boxed_bytes(self: Box<Self>) -> Box<[u8]>
pub fn into_boxed_bytes(self: Box<Self>) -> Box<[u8]>
Converts a Box<TextStr> into a Box<[u8]> without copying or
allocating.
sourcepub fn into_boxed_text(self: Box<Self>) -> Box<str>
pub fn into_boxed_text(self: Box<Self>) -> Box<str>
Converts a Box<TextStr> into a Box<str> without copying or
allocating.
sourcepub fn into_string(self: Box<Self>) -> String
pub fn into_string(self: Box<Self>) -> String
Converts a Box<TextStr> into a String without copying or
allocating.
sourcepub fn into_text_string(self: Box<Self>) -> TextString
pub fn into_text_string(self: Box<Self>) -> TextString
Converts a Box<TextStr> into a TextString without copying or
allocating.
sourcepub fn repeat(&self, n: usize) -> TextString
pub fn repeat(&self, n: usize) -> TextString
Creates a new TextString by repeating a string n times.
sourcepub fn escape_debug(&self) -> EscapeDebug<'_>
pub fn escape_debug(&self) -> EscapeDebug<'_>
Return an iterator that escapes each char in self with
char::escape_debug.
sourcepub fn escape_default(&self) -> EscapeDefault<'_>
pub fn escape_default(&self) -> EscapeDefault<'_>
Return an iterator that escapes each char in self with
char::escape_default.
sourcepub fn escape_unicode(&self) -> EscapeUnicode<'_>
pub fn escape_unicode(&self) -> EscapeUnicode<'_>
Return an iterator that escapes each char in self with
char::escape_unicode.
Trait Implementations
sourceimpl Add<&'_ TextStr> for TextString
impl Add<&'_ TextStr> for TextString
sourceimpl AddAssign<&'_ TextStr> for TextString
impl AddAssign<&'_ TextStr> for TextString
sourcefn add_assign(&mut self, other: &TextStr)
fn add_assign(&mut self, other: &TextStr)
Performs the += operation. Read more
sourceimpl AsMut<TextStr> for TextString
impl AsMut<TextStr> for TextString
sourceimpl AsRef<TextStr> for TextString
impl AsRef<TextStr> for TextString
sourceimpl AsRef<TextSubstr> for TextStr
impl AsRef<TextSubstr> for TextStr
sourcefn as_ref(&self) -> &TextSubstr
fn as_ref(&self) -> &TextSubstr
Converts this type into a shared reference of the (usually inferred) input type.
sourceimpl Borrow<TextStr> for TextString
impl Borrow<TextStr> for TextString
sourceimpl BorrowMut<TextStr> for TextString
impl BorrowMut<TextStr> for TextString
sourcefn borrow_mut(&mut self) -> &mut TextStr
fn borrow_mut(&mut self) -> &mut TextStr
Mutably borrows from an owned value. Read more
sourceimpl<'a> Extend<&'a TextStr> for TextString
impl<'a> Extend<&'a TextStr> for TextString
sourcefn extend<I: IntoIterator<Item = &'a TextStr>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = &'a TextStr>>(&mut self, iter: I)
Extends a collection with the contents of an iterator. Read more
sourcefn extend_one(&mut self, s: &'a TextStr)
fn extend_one(&mut self, s: &'a TextStr)
extend_one)Extends a collection with exactly one element.
sourcefn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)Reserves capacity in a collection for the given number of additional elements. Read more
sourceimpl From<&'_ TextStr> for TextString
impl From<&'_ TextStr> for TextString
sourceimpl From<&'_ mut TextStr> for TextString
impl From<&'_ mut TextStr> for TextString
sourceimpl From<TextString> for Box<TextStr>
impl From<TextString> for Box<TextStr>
sourcefn from(s: TextString) -> Self
fn from(s: TextString) -> Self
Converts to this type from the input type.
sourceimpl Ord for TextStr
impl Ord for TextStr
sourceimpl<'a> PartialEq<&'a TextStr> for TextString
impl<'a> PartialEq<&'a TextStr> for TextString
sourceimpl<'a> PartialEq<&'a TextStr> for TextSubstring
impl<'a> PartialEq<&'a TextStr> for TextSubstring
sourceimpl<'a, 'b> PartialEq<&'b TextStr> for Cow<'a, TextSubstr>
impl<'a, 'b> PartialEq<&'b TextStr> for Cow<'a, TextSubstr>
sourceimpl<'a, 'b> PartialEq<Cow<'a, TextSubstr>> for &'b TextStr
impl<'a, 'b> PartialEq<Cow<'a, TextSubstr>> for &'b TextStr
sourceimpl PartialEq<TextStr> for TextString
impl PartialEq<TextStr> for TextString
sourceimpl<'a> PartialEq<TextStr> for Cow<'a, TextSubstr>
impl<'a> PartialEq<TextStr> for Cow<'a, TextSubstr>
sourceimpl PartialEq<TextStr> for TextSubstring
impl PartialEq<TextStr> for TextSubstring
sourceimpl<'a> PartialEq<TextString> for &'a TextStr
impl<'a> PartialEq<TextString> for &'a TextStr
sourceimpl PartialEq<TextString> for TextStr
impl PartialEq<TextString> for TextStr
sourceimpl<'a> PartialEq<TextSubstring> for &'a TextStr
impl<'a> PartialEq<TextSubstring> for &'a TextStr
sourceimpl PartialEq<TextSubstring> for TextStr
impl PartialEq<TextSubstring> for TextStr
sourceimpl PartialOrd<TextStr> for TextStr
impl PartialOrd<TextStr> for TextStr
sourcefn partial_cmp(&self, other: &Self) -> Option<Ordering>
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 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self and other) and is used by the <=
operator. Read more
sourceimpl ToOwned for TextStr
impl ToOwned for TextStr
type Owned = TextString
type Owned = TextString
The resulting type after obtaining ownership.
sourcefn to_owned(&self) -> Self::Owned
fn to_owned(&self) -> Self::Owned
Creates owned data from borrowed data, usually by cloning. Read more
1.63.0 · sourcefn clone_into(&self, target: &mut Self::Owned)
fn clone_into(&self, target: &mut Self::Owned)
Uses borrowed data to replace owned data, usually by cloning. Read more
sourceimpl ToSocketAddrs for TextStr
impl ToSocketAddrs for TextStr
type Iter = IntoIter<SocketAddr, Global>
type Iter = IntoIter<SocketAddr, Global>
Returned iterator over socket addresses which this type may correspond to. Read more
sourcefn to_socket_addrs(&self) -> Result<Self::Iter>
fn to_socket_addrs(&self) -> Result<Self::Iter>
Converts this object to an iterator of resolved SocketAddrs. Read more