Struct basic_text::TextStr
source · pub struct TextStr(/* private fields */);
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§
source§impl 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 &TextStr
s
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 &TextStr
s
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 &TextStr
s
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
&TextStr
s 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 &TextStr
s
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 &TextStr
s
are valid Basic Text.
sourcepub unsafe fn as_bytes_mut(&mut self) -> &mut [u8] ⓘ
pub unsafe fn as_bytes_mut(&mut self) -> &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 char
s 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 &TextStr
s.
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) -> boolwhere
P: Pattern<'a>,
pub fn contains<'a, P>(&'a self, pat: P) -> boolwhere
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) -> boolwhere
P: Pattern<'a>,
pub fn starts_with<'a, P>(&'a self, pat: P) -> boolwhere
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
pub fn ends_with<'a, P>(&'a self, pat: P) -> bool
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>
pub fn rfind<'a, P>(&'a self, pat: P) -> Option<usize>
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>
pub fn rmatches<'a, P>(&'a self, pat: P) -> RMatches<'a, P>
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.
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 &TextStr
s.
sourcepub fn rmatch_indices<'a, P>(&'a self, pat: P) -> RMatchIndices<'a, P>
pub fn rmatch_indices<'a, P>(&'a self, pat: P) -> RMatchIndices<'a, P>
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.
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§
source§impl Add<&TextStr> for TextString
impl Add<&TextStr> for TextString
source§impl AddAssign<&TextStr> for TextString
impl AddAssign<&TextStr> for TextString
source§fn add_assign(&mut self, other: &TextStr)
fn add_assign(&mut self, other: &TextStr)
+=
operation. Read moresource§impl AsMut<TextStr> for TextString
impl AsMut<TextStr> for TextString
source§impl AsRef<TextStr> for TextString
impl AsRef<TextStr> for TextString
source§impl AsRef<TextSubstr> for TextStr
impl AsRef<TextSubstr> for TextStr
source§fn as_ref(&self) -> &TextSubstr
fn as_ref(&self) -> &TextSubstr
source§impl Borrow<TextStr> for TextString
impl Borrow<TextStr> for TextString
source§impl BorrowMut<TextStr> for TextString
impl BorrowMut<TextStr> for TextString
source§fn borrow_mut(&mut self) -> &mut TextStr
fn borrow_mut(&mut self) -> &mut TextStr
source§impl<'a> Extend<&'a TextStr> for TextString
impl<'a> Extend<&'a TextStr> for TextString
source§fn extend<I: IntoIterator<Item = &'a TextStr>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = &'a TextStr>>(&mut self, iter: I)
source§fn extend_one(&mut self, s: &'a TextStr)
fn extend_one(&mut self, s: &'a TextStr)
extend_one
)source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)source§impl From<&TextStr> for TextString
impl From<&TextStr> for TextString
source§impl From<&mut TextStr> for TextString
impl From<&mut TextStr> for TextString
source§impl From<TextString> for Box<TextStr>
impl From<TextString> for Box<TextStr>
source§fn from(s: TextString) -> Self
fn from(s: TextString) -> Self
source§impl<'a, 'b> PartialEq<&'b TextStr> for Cow<'a, TextStr>
impl<'a, 'b> PartialEq<&'b TextStr> for Cow<'a, TextStr>
source§impl<'a, 'b> PartialEq<&'b TextStr> for Cow<'a, TextSubstr>
impl<'a, 'b> PartialEq<&'b TextStr> for Cow<'a, TextSubstr>
source§impl<'a, 'b> PartialEq<&'b TextStr> for Cow<'a, str>
impl<'a, 'b> PartialEq<&'b TextStr> for Cow<'a, str>
source§impl<'a> PartialEq<&'a TextStr> for String
impl<'a> PartialEq<&'a TextStr> for String
source§impl<'a> PartialEq<&'a TextStr> for TextString
impl<'a> PartialEq<&'a TextStr> for TextString
source§impl<'a> PartialEq<&'a TextStr> for TextSubstring
impl<'a> PartialEq<&'a TextStr> for TextSubstring
source§impl<'a, 'b> PartialEq<Cow<'a, TextStr>> for &'b TextStr
impl<'a, 'b> PartialEq<Cow<'a, TextStr>> for &'b TextStr
source§impl<'a> PartialEq<Cow<'a, TextStr>> for TextStr
impl<'a> PartialEq<Cow<'a, TextStr>> for TextStr
source§impl<'a, 'b> PartialEq<Cow<'a, TextSubstr>> for &'b TextStr
impl<'a, 'b> PartialEq<Cow<'a, TextSubstr>> for &'b TextStr
source§impl<'a, 'b> PartialEq<Cow<'a, str>> for &'b TextStr
impl<'a, 'b> PartialEq<Cow<'a, str>> for &'b TextStr
source§impl<'a> PartialEq<Cow<'a, str>> for TextStr
impl<'a> PartialEq<Cow<'a, str>> for TextStr
source§impl<'a> PartialEq<String> for &'a TextStr
impl<'a> PartialEq<String> for &'a TextStr
source§impl PartialEq<String> for TextStr
impl PartialEq<String> for TextStr
source§impl<'a> PartialEq<TextStr> for Cow<'a, TextStr>
impl<'a> PartialEq<TextStr> for Cow<'a, TextStr>
source§impl<'a> PartialEq<TextStr> for Cow<'a, TextSubstr>
impl<'a> PartialEq<TextStr> for Cow<'a, TextSubstr>
source§impl<'a> PartialEq<TextStr> for Cow<'a, str>
impl<'a> PartialEq<TextStr> for Cow<'a, str>
source§impl PartialEq<TextStr> for String
impl PartialEq<TextStr> for String
source§impl PartialEq<TextStr> for TextString
impl PartialEq<TextStr> for TextString
source§impl PartialEq<TextStr> for TextSubstring
impl PartialEq<TextStr> for TextSubstring
source§impl PartialEq<TextStr> for str
impl PartialEq<TextStr> for str
source§impl<'a> PartialEq<TextString> for &'a TextStr
impl<'a> PartialEq<TextString> for &'a TextStr
source§fn eq(&self, other: &TextString) -> bool
fn eq(&self, other: &TextString) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl PartialEq<TextString> for TextStr
impl PartialEq<TextString> for TextStr
source§fn eq(&self, other: &TextString) -> bool
fn eq(&self, other: &TextString) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl<'a> PartialEq<TextSubstring> for &'a TextStr
impl<'a> PartialEq<TextSubstring> for &'a TextStr
source§fn eq(&self, other: &TextSubstring) -> bool
fn eq(&self, other: &TextSubstring) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl PartialEq<TextSubstring> for TextStr
impl PartialEq<TextSubstring> for TextStr
source§fn eq(&self, other: &TextSubstring) -> bool
fn eq(&self, other: &TextSubstring) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl PartialEq for TextStr
impl PartialEq for TextStr
source§impl PartialOrd for TextStr
impl PartialOrd for TextStr
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresource§impl ToOwned for TextStr
impl ToOwned for TextStr
§type Owned = TextString
type Owned = TextString
source§fn to_owned(&self) -> Self::Owned
fn to_owned(&self) -> Self::Owned
1.63.0 · source§fn clone_into(&self, target: &mut Self::Owned)
fn clone_into(&self, target: &mut Self::Owned)
source§impl ToSocketAddrs for TextStr
impl ToSocketAddrs for TextStr
§type Iter = IntoIter<SocketAddr>
type Iter = IntoIter<SocketAddr>
source§fn to_socket_addrs(&self) -> Result<Self::Iter>
fn to_socket_addrs(&self) -> Result<Self::Iter>
SocketAddr
s. Read more