Struct basic_text::TextStr [−][src]
#[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
impl TextStr
[src]
impl TextStr
[src]pub fn from_text_bytes(b: &[u8]) -> Result<&Self, TextError>
[src]
pub fn from_text_bytes(b: &[u8]) -> Result<&Self, TextError>
[src]Converts a slice of bytes to a text string slice.
pub fn from_text(s: &str) -> Result<&Self, TextError>
[src]
pub fn from_text(s: &str) -> Result<&Self, TextError>
[src]Converts a string slice to a text string slice.
pub fn from_text_bytes_mut(b: &mut [u8]) -> Result<&mut Self, TextError>
[src]
pub fn from_text_bytes_mut(b: &mut [u8]) -> Result<&mut Self, TextError>
[src]Converts a mutable slice of bytes to a mutable text string slice.
pub fn from_text_mut(s: &mut str) -> Result<&mut Self, TextError>
[src]
pub fn from_text_mut(s: &mut str) -> Result<&mut Self, TextError>
[src]Converts a mutable string slice to a mutable text string slice.
pub unsafe fn from_text_bytes_unchecked(b: &[u8]) -> &Self
[src]
pub unsafe fn from_text_bytes_unchecked(b: &[u8]) -> &Self
[src]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 &TextStr
s
are valid Basic Text.
pub unsafe fn from_text_unchecked(s: &str) -> &Self
[src]
pub unsafe fn from_text_unchecked(s: &str) -> &Self
[src]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 &TextStr
s
are valid Basic Text.
pub unsafe fn from_text_bytes_unchecked_mut(b: &mut [u8]) -> &mut Self
[src]
pub unsafe fn from_text_bytes_unchecked_mut(b: &mut [u8]) -> &mut Self
[src]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 &TextStr
s
are valid Basic Text.
pub unsafe fn from_text_unchecked_mut(s: &mut str) -> &mut Self
[src]
pub unsafe fn from_text_unchecked_mut(s: &mut str) -> &mut Self
[src]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
&TextStr
s are valid Basic Text.
pub unsafe fn from_boxed_text_bytes_unchecked(v: Box<[u8]>) -> Box<Self>
[src]
pub unsafe fn from_boxed_text_bytes_unchecked(v: Box<[u8]>) -> Box<Self>
[src]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 &TextStr
s
are valid Basic Text.
pub unsafe fn from_boxed_text_unchecked(v: Box<str>) -> Box<Self>
[src]
pub unsafe fn from_boxed_text_unchecked(v: Box<str>) -> Box<Self>
[src]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 &TextStr
s
are valid Basic Text.
pub unsafe fn as_bytes_mut(&mut self) -> &mut [u8]
[src]
pub unsafe fn as_bytes_mut(&mut self) -> &mut [u8]
[src]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.
pub fn as_mut_ptr(&mut self) -> *mut u8
[src]
pub fn as_mut_ptr(&mut self) -> *mut u8
[src]Converts a mutable text string slice to a raw pointer.
pub fn split_at(&self, mid: usize) -> (&Self, &Self)
[src]
pub fn split_at(&self, mid: usize) -> (&Self, &Self)
[src]Divide one text string slice into two at an index.
pub fn split_at_mut(&mut self, mid: usize) -> (&mut Self, &mut Self)
[src]
pub fn split_at_mut(&mut self, mid: usize) -> (&mut Self, &mut Self)
[src]Divide one mutable text string slice into two at an index.
pub fn char_indices(&self) -> CharIndices<'_>
[src]
pub fn char_indices(&self) -> CharIndices<'_>
[src]Returns an iterator over the char
s of a text string slice, and their
positions.
pub fn lines(&self) -> Lines<'_>
[src]
pub fn lines(&self) -> Lines<'_>
[src]An iterator over the lines of a text string, as text string slices.
TODO: There should be a TextLines
which yields &TextStr
s.
pub fn encode_utf16(&self) -> EncodeUtf16<'_>
[src]
pub fn encode_utf16(&self) -> EncodeUtf16<'_>
[src]Returns an iterator of u16
over the string encoded as Basic Text.
pub fn contains<'a, P>(&'a self, pat: P) -> bool where
P: Pattern<'a>,
[src]
pub fn contains<'a, P>(&'a self, pat: P) -> bool where
P: Pattern<'a>,
[src]Returns true
if the given pattern matches a sub-slice of this
text string slice.
Returns false
if it does not.
pub fn starts_with<'a, P>(&'a self, pat: P) -> bool where
P: Pattern<'a>,
[src]
pub fn starts_with<'a, P>(&'a self, pat: P) -> bool where
P: Pattern<'a>,
[src]Returns true
if the given pattern matches a prefix of this
text string slice.
Returns false
if it does not.
pub fn ends_with<'a, P>(&'a self, pat: P) -> bool where
P: Pattern<'a>,
<P as Pattern<'a>>::Searcher: ReverseSearcher<'a>,
[src]
pub fn ends_with<'a, P>(&'a self, pat: P) -> bool where
P: Pattern<'a>,
<P as Pattern<'a>>::Searcher: ReverseSearcher<'a>,
[src]Returns true
if the given pattern matches a suffix of this
text string slice.
Returns false
if it does not.
pub fn find<'a, P>(&'a self, pat: P) -> Option<usize> where
P: Pattern<'a>,
[src]
pub fn find<'a, P>(&'a self, pat: P) -> Option<usize> where
P: Pattern<'a>,
[src]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.
pub fn rfind<'a, P>(&'a self, pat: P) -> Option<usize> where
P: Pattern<'a>,
<P as Pattern<'a>>::Searcher: ReverseSearcher<'a>,
[src]
pub fn rfind<'a, P>(&'a self, pat: P) -> Option<usize> where
P: Pattern<'a>,
<P as Pattern<'a>>::Searcher: ReverseSearcher<'a>,
[src]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.
pub fn matches<'a, P>(&'a self, pat: P) -> Matches<'a, P> where
P: Pattern<'a>,
[src]
pub fn matches<'a, P>(&'a self, pat: P) -> Matches<'a, P> where
P: Pattern<'a>,
[src]An iterator over the disjoint matches of a pattern within the given text string slice.
pub fn rmatches<'a, P>(&'a self, pat: P) -> RMatches<'a, P> where
P: Pattern<'a>,
<P as Pattern<'a>>::Searcher: ReverseSearcher<'a>,
[src]
pub fn rmatches<'a, P>(&'a self, pat: P) -> RMatches<'a, P> where
P: Pattern<'a>,
<P as Pattern<'a>>::Searcher: ReverseSearcher<'a>,
[src]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 &TextStr
s.
pub fn match_indices<'a, P>(&'a self, pat: P) -> MatchIndices<'a, P> where
P: Pattern<'a>,
[src]
pub fn match_indices<'a, P>(&'a self, pat: P) -> MatchIndices<'a, P> where
P: Pattern<'a>,
[src]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 &TextStr
s.
pub fn rmatch_indices<'a, P>(&'a self, pat: P) -> RMatchIndices<'a, P> where
P: Pattern<'a>,
<P as Pattern<'a>>::Searcher: ReverseSearcher<'a>,
[src]
pub fn rmatch_indices<'a, P>(&'a self, pat: P) -> RMatchIndices<'a, P> where
P: Pattern<'a>,
<P as Pattern<'a>>::Searcher: ReverseSearcher<'a>,
[src]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 &TextStr
s.
pub fn trim(&self) -> &Self
[src]
pub fn trim(&self) -> &Self
[src]Returns a text string slice with leading and trailing whitespace removed.
pub fn trim_start(&self) -> &Self
[src]
pub fn trim_start(&self) -> &Self
[src]Returns a text string slice with leading whitespace removed.
pub fn parse<F>(&self) -> Result<F, <F as FromStr>::Err> where
F: FromStr,
[src]
pub fn parse<F>(&self) -> Result<F, <F as FromStr>::Err> where
F: FromStr,
[src]Parses this text string slice into another type.
pub fn is_ascii(&self) -> bool
[src]
pub fn is_ascii(&self) -> bool
[src]Checks if all characters in this text string are within the ASCII range.
pub fn eq_ignore_ascii_case(&self, other: &Self) -> bool
[src]
pub fn eq_ignore_ascii_case(&self, other: &Self) -> bool
[src]Checks that two text strings are an ASCII case-insensitive match.
pub fn into_boxed_bytes(self: Box<Self>) -> Box<[u8]>
[src]
pub fn into_boxed_bytes(self: Box<Self>) -> Box<[u8]>
[src]Converts a Box<TextStr
> into a Box<[u8]>
without copying or
allocating.
pub fn into_boxed_text(self: Box<Self>) -> Box<str>
[src]
pub fn into_boxed_text(self: Box<Self>) -> Box<str>
[src]Converts a Box<TextStr>
into a Box<str>
without copying or
allocating.
pub fn into_string(self: Box<Self>) -> String
[src]
pub fn into_string(self: Box<Self>) -> String
[src]Converts a Box<TextStr>
into a String
without copying or allocating.
pub fn into_text_string(self: Box<Self>) -> TextString
[src]
pub fn into_text_string(self: Box<Self>) -> TextString
[src]Converts a Box<TextStr>
into a TextString
without copying or
allocating.
pub fn repeat(&self, n: usize) -> TextString
[src]
pub fn repeat(&self, n: usize) -> TextString
[src]Creates a new TextString
by repeating a string n
times.
pub fn escape_debug(&self) -> EscapeDebug<'_>
[src]
pub fn escape_debug(&self) -> EscapeDebug<'_>
[src]Return an iterator that escapes each char
in self
with
char::escape_debug
.
pub fn escape_default(&self) -> EscapeDefault<'_>
[src]
pub fn escape_default(&self) -> EscapeDefault<'_>
[src]Return an iterator that escapes each char
in self
with
char::escape_default
.
pub fn escape_unicode(&self) -> EscapeUnicode<'_>
[src]
pub fn escape_unicode(&self) -> EscapeUnicode<'_>
[src]Return an iterator that escapes each char
in self
with
char::escape_unicode
.
Trait Implementations
impl Add<&'_ TextStr> for TextString
[src]
impl Add<&'_ TextStr> for TextString
[src]impl AddAssign<&'_ TextStr> for TextString
[src]
impl AddAssign<&'_ TextStr> for TextString
[src]fn add_assign(&mut self, other: &TextStr)
[src]
fn add_assign(&mut self, other: &TextStr)
[src]Performs the +=
operation. Read more
impl AsMut<TextStr> for TextString
[src]
impl AsMut<TextStr> for TextString
[src]impl AsRef<TextSubstr> for TextStr
[src]
impl AsRef<TextSubstr> for TextStr
[src]fn as_ref(&self) -> &TextSubstr
[src]
fn as_ref(&self) -> &TextSubstr
[src]Performs the conversion.
impl Borrow<TextStr> for TextString
[src]
impl Borrow<TextStr> for TextString
[src]impl BorrowMut<TextStr> for TextString
[src]
impl BorrowMut<TextStr> for TextString
[src]fn borrow_mut(&mut self) -> &mut TextStr
[src]
fn borrow_mut(&mut self) -> &mut TextStr
[src]Mutably borrows from an owned value. Read more
impl<'a> Extend<&'a TextStr> for TextString
[src]
impl<'a> Extend<&'a TextStr> for TextString
[src]fn extend<I: IntoIterator<Item = &'a TextStr>>(&mut self, iter: I)
[src]
fn extend<I: IntoIterator<Item = &'a TextStr>>(&mut self, iter: I)
[src]Extends a collection with the contents of an iterator. Read more
fn extend_one(&mut self, s: &'a TextStr)
[src]
fn extend_one(&mut self, s: &'a TextStr)
[src]extend_one
)Extends a collection with exactly one element.
fn extend_reserve(&mut self, additional: usize)
[src]
fn extend_reserve(&mut self, additional: usize)
[src]extend_one
)Reserves capacity in a collection for the given number of additional elements. Read more
impl From<&'_ mut TextStr> for TextString
[src]
impl From<&'_ mut TextStr> for TextString
[src]impl Ord for TextStr
[src]
impl Ord for TextStr
[src]impl<'a> PartialEq<&'a TextStr> for TextString
[src]
impl<'a> PartialEq<&'a TextStr> for TextString
[src]impl<'a> PartialEq<&'a TextStr> for TextSubstring
[src]
impl<'a> PartialEq<&'a TextStr> for TextSubstring
[src]impl<'a, 'b> PartialEq<Cow<'a, TextSubstr>> for &'b TextStr
[src]
impl<'a, 'b> PartialEq<Cow<'a, TextSubstr>> for &'b TextStr
[src]impl PartialEq<TextStr> for TextString
[src]
impl PartialEq<TextStr> for TextString
[src]impl PartialEq<TextStr> for TextSubstring
[src]
impl PartialEq<TextStr> for TextSubstring
[src]impl<'a> PartialEq<TextString> for &'a TextStr
[src]
impl<'a> PartialEq<TextString> for &'a TextStr
[src]impl PartialEq<TextString> for TextStr
[src]
impl PartialEq<TextString> for TextStr
[src]impl<'a> PartialEq<TextSubstring> for &'a TextStr
[src]
impl<'a> PartialEq<TextSubstring> for &'a TextStr
[src]impl PartialEq<TextSubstring> for TextStr
[src]
impl PartialEq<TextSubstring> for TextStr
[src]impl PartialOrd<TextStr> for TextStr
[src]
impl PartialOrd<TextStr> for TextStr
[src]fn partial_cmp(&self, other: &Self) -> Option<Ordering>
[src]
fn partial_cmp(&self, other: &Self) -> Option<Ordering>
[src]This method returns an ordering between self
and other
values if one exists. Read more
#[must_use]fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]fn lt(&self, other: &Rhs) -> bool
1.0.0[src]This method tests less than (for self
and other
) and is used by the <
operator. Read more
#[must_use]fn le(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]fn le(&self, other: &Rhs) -> bool
1.0.0[src]This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
impl ToOwned for TextStr
[src]
impl ToOwned for TextStr
[src]type Owned = TextString
type Owned = TextString
The resulting type after obtaining ownership.
fn to_owned(&self) -> Self::Owned
[src]
fn to_owned(&self) -> Self::Owned
[src]Creates owned data from borrowed data, usually by cloning. Read more
fn clone_into(&self, target: &mut Self::Owned)
[src]
fn clone_into(&self, target: &mut Self::Owned)
[src]🔬 This is a nightly-only experimental API. (toowned_clone_into
)
recently added
Uses borrowed data to replace owned data, usually by cloning. Read more
impl ToSocketAddrs for TextStr
[src]
impl ToSocketAddrs for TextStr
[src]type Iter = IntoIter<SocketAddr>
type Iter = IntoIter<SocketAddr>
Returned iterator over socket addresses which this type may correspond to. Read more
fn to_socket_addrs(&self) -> Result<Self::Iter>
[src]
fn to_socket_addrs(&self) -> Result<Self::Iter>
[src]Converts this object to an iterator of resolved SocketAddr
s. Read more