Struct basic_text::TextSubstring [−][src]
#[repr(transparent)]pub struct TextSubstring(_);
Expand description
A substring of a Basic Text string or stream.
This does not enforce the Basic Text requirements on the beginning or end of a stream, so it can represent substrings of Basic Text.
This is an owning string similar to TextString
, but doesn’t enforce the
starting and ending requirements, so it can represent substrings. It’s
accompanied by a borrowing TextSubstr
, which plays an analogous role to
TextStr
.
Examples
You can create a TextSubstring
from a literal text string with TextSubstring::from
:
use basic_text::{text_substr, TextSubstring}; let hello = TextSubstring::from(text_substr!("Hello, world!"));
If you have a String
containing a Basic Text string, you can create a
TextSubstring
from it with the from_text
method:
use basic_text::{text_substr, TextSubstring}; // a `String` let sparkle_heart = "💖".to_owned(); // We know this string is valid, so we'll use `unwrap()`. let sparkle_heart = TextSubstring::from_text(sparkle_heart).unwrap(); assert_eq!(text_substr!("💖"), &sparkle_heart);
If you have a vector of Basic Text bytes, you can create a String
from it
with the from_text_vec
method:
use basic_text::{text_substr, TextSubstring}; // some bytes, in a vector let sparkle_heart = vec![240, 159, 146, 150]; // We know these bytes are valid, so we'll use `unwrap()`. let sparkle_heart = TextSubstring::from_text_vec(sparkle_heart).unwrap(); assert_eq!(text_substr!("💖"), &sparkle_heart);
Implementations
impl TextSubstring
[src]
impl TextSubstring
[src]#[must_use]pub fn with_capacity(capacity: usize) -> Self
[src]
#[must_use]pub fn with_capacity(capacity: usize) -> Self
[src]Creates a new empty TextSubstring
with a particular capacity.
pub fn from_text_vec(vec: Vec<u8>) -> Result<Self, FromTextError>
[src]
pub fn from_text_vec(vec: Vec<u8>) -> Result<Self, FromTextError>
[src]Converts a vector of bytes to a TextSubstring
.
pub fn from_text(s: String) -> Result<Self, FromTextError>
[src]
pub fn from_text(s: String) -> Result<Self, FromTextError>
[src]Converts a String
to a TextSubstring
.
#[must_use]pub fn from_text_bytes_lossy(v: &[u8]) -> Cow<'_, TextSubstr>
[src]
#[must_use]pub fn from_text_bytes_lossy(v: &[u8]) -> Cow<'_, TextSubstr>
[src]Converts a slice of bytes to Basic Text, including invalid characters.
#[must_use]pub fn from_text_lossy(v: &str) -> Cow<'_, TextSubstr>
[src]
#[must_use]pub fn from_text_lossy(v: &str) -> Cow<'_, TextSubstr>
[src]Converts a string to Basic Text, including invalid characters.
#[must_use]pub unsafe fn from_text_vec_unchecked(vec: Vec<u8>) -> Self
[src]
#[must_use]pub unsafe fn from_text_vec_unchecked(vec: Vec<u8>) -> Self
[src]Converts a vector of bytes to a TextSubstring
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 &TextSubstr
s
are valid Basic Text.
#[must_use]pub const unsafe fn from_text_unchecked(s: String) -> Self
[src]
#[must_use]pub const unsafe fn from_text_unchecked(s: String) -> Self
[src]Converts a String
to a TextSubstring
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 &TextSubstr
s
are valid Basic Text.
#[must_use]pub fn into_string(self) -> String
[src]
#[must_use]pub fn into_string(self) -> String
[src]Converts a TextSubstring
into a String
.
#[must_use]pub fn into_bytes(self) -> Vec<u8>
[src]
#[must_use]pub fn into_bytes(self) -> Vec<u8>
[src]Converts a String into a byte vector.
#[must_use]pub fn as_str(&self) -> &str
[src]
#[must_use]pub fn as_str(&self) -> &str
[src]Extracts a UTF-8 string slice containing the entire TextSubstring
.
#[must_use]pub fn as_text(&self) -> &TextSubstr
[src]
#[must_use]pub fn as_text(&self) -> &TextSubstr
[src]Extracts a Basic Text string slice containing the entire TextSubstring
.
#[must_use]pub fn as_mut_text(&mut self) -> &mut TextSubstr
[src]
#[must_use]pub fn as_mut_text(&mut self) -> &mut TextSubstr
[src]Converts a TextSubstring
into a mutable Basic Text substring slice.
pub fn reserve(&mut self, additional: usize)
[src]
pub fn reserve(&mut self, additional: usize)
[src]Ensures that this TextSubstring
’s capacity is at least additional
bytes larger than its length.
pub fn reserve_exact(&mut self, additional: usize)
[src]
pub fn reserve_exact(&mut self, additional: usize)
[src]Ensures that this TextSubstring
’s capacity is additional
bytes larger
than its length.
pub fn try_reserve(&mut self, additional: usize) -> Result<(), TryReserveError>
[src]
pub fn try_reserve(&mut self, additional: usize) -> Result<(), TryReserveError>
[src]Tries to reserve capacity for at least additional
more elements to
be inserted in the given TextSubstring
.
pub fn try_reserve_exact(
&mut self,
additional: usize
) -> Result<(), TryReserveError>
[src]
pub fn try_reserve_exact(
&mut self,
additional: usize
) -> Result<(), TryReserveError>
[src]Tries to reserves the minimum capacity for exactly additional
more
elements to be inserted in the given TextSubstring
.
pub fn shrink_to_fit(&mut self)
[src]
pub fn shrink_to_fit(&mut self)
[src]Shrinks the capacity of this TextSubstring
to match its length.
pub fn shrink_to(&mut self, min_capacity: usize)
[src]
pub fn shrink_to(&mut self, min_capacity: usize)
[src]Shrinks the capacity of this String
with a lower bound.
pub unsafe fn as_mut_vec(&mut self) -> &mut Vec<u8>
[src]
pub unsafe fn as_mut_vec(&mut self) -> &mut Vec<u8>
[src]Returns a mutable reference to the contents of this TextSubstring
.
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, it may
cause memory unsafety issues with future users of the String, as the
rest of this crate assumes that TextSubstring
s are valid Basic Text.
pub unsafe fn as_mut_string(&mut self) -> &mut String
[src]
pub unsafe fn as_mut_string(&mut self) -> &mut String
[src]Returns a mutable reference to the contents of this TextSubstring
.
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, it may
cause memory unsafety issues with future users of the String, as the
rest of this crate assumes that TextSubstring
s are valid Basic Text.
pub fn len(&self) -> usize
[src]
pub fn len(&self) -> usize
[src]Returns the length of this TextSubstring
, in bytes, not char
s or
graphemes.
pub fn is_empty(&self) -> bool
[src]
pub fn is_empty(&self) -> bool
[src]Returns true
if this TextSubstring
has a length of zero, and false
otherwise.
pub fn into_boxed_str(self) -> Box<str>
[src]
pub fn into_boxed_str(self) -> Box<str>
[src]Converts this TextSubstring
into a Box<str>
.
pub fn into_boxed_text(self) -> Box<TextSubstr>
[src]
pub fn into_boxed_text(self) -> Box<TextSubstr>
[src]Converts this TextSubstring
into a Box<TextSubstr>
.
Methods from Deref<Target = TextSubstr>
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 TextSubstr
is used.
Use of a TextSubstr
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 &TextSubstr
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.
TODO: There should be a TextMatches
which yields &TextSubstr
s.
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 &TextSubstr
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 &TextSubstr
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 &TextSubstr
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 repeat(&self, n: usize) -> TextSubstring
[src]
pub fn repeat(&self, n: usize) -> TextSubstring
[src]Creates a new TextSubstring
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 AsMut<TextSubstr> for TextSubstring
[src]
impl AsMut<TextSubstr> for TextSubstring
[src]fn as_mut(&mut self) -> &mut TextSubstr
[src]
fn as_mut(&mut self) -> &mut TextSubstr
[src]Performs the conversion.
impl AsRef<TextSubstr> for TextSubstring
[src]
impl AsRef<TextSubstr> for TextSubstring
[src]fn as_ref(&self) -> &TextSubstr
[src]
fn as_ref(&self) -> &TextSubstr
[src]Performs the conversion.
impl Borrow<TextSubstr> for TextSubstring
[src]
impl Borrow<TextSubstr> for TextSubstring
[src]fn borrow(&self) -> &TextSubstr
[src]
fn borrow(&self) -> &TextSubstr
[src]Immutably borrows from an owned value. Read more
impl BorrowMut<TextSubstr> for TextSubstring
[src]
impl BorrowMut<TextSubstr> for TextSubstring
[src]fn borrow_mut(&mut self) -> &mut TextSubstr
[src]
fn borrow_mut(&mut self) -> &mut TextSubstr
[src]Mutably borrows from an owned value. Read more
impl Clone for TextSubstring
[src]
impl Clone for TextSubstring
[src]impl Debug for TextSubstring
[src]
impl Debug for TextSubstring
[src]impl Default for TextSubstring
[src]
impl Default for TextSubstring
[src]impl Deref for TextSubstring
[src]
impl Deref for TextSubstring
[src]type Target = TextSubstr
type Target = TextSubstr
The resulting type after dereferencing.
impl DerefMut for TextSubstring
[src]
impl DerefMut for TextSubstring
[src]impl From<&'_ TextSubstr> for TextSubstring
[src]
impl From<&'_ TextSubstr> for TextSubstring
[src]fn from(s: &TextSubstr) -> Self
[src]
fn from(s: &TextSubstr) -> Self
[src]Performs the conversion.
impl From<&'_ TextSubstring> for TextSubstring
[src]
impl From<&'_ TextSubstring> for TextSubstring
[src]impl From<&'_ mut TextSubstr> for TextSubstring
[src]
impl From<&'_ mut TextSubstr> for TextSubstring
[src]fn from(s: &mut TextSubstr) -> Self
[src]
fn from(s: &mut TextSubstr) -> Self
[src]Performs the conversion.
impl From<Box<TextSubstr, Global>> for TextSubstring
[src]
impl From<Box<TextSubstr, Global>> for TextSubstring
[src]fn from(s: Box<TextSubstr>) -> Self
[src]
fn from(s: Box<TextSubstr>) -> Self
[src]Performs the conversion.
impl Hash for TextSubstring
[src]
impl Hash for TextSubstring
[src]impl Index<Range<usize>> for TextSubstring
[src]
impl Index<Range<usize>> for TextSubstring
[src]impl Index<RangeFrom<usize>> for TextSubstring
[src]
impl Index<RangeFrom<usize>> for TextSubstring
[src]impl Index<RangeTo<usize>> for TextSubstring
[src]
impl Index<RangeTo<usize>> for TextSubstring
[src]impl<'a> PartialEq<&'a TextStr> for TextSubstring
[src]
impl<'a> PartialEq<&'a TextStr> for TextSubstring
[src]impl<'a> PartialEq<&'a TextSubstr> for TextSubstring
[src]
impl<'a> PartialEq<&'a TextSubstr> for TextSubstring
[src]impl<'a> PartialEq<&'a str> for TextSubstring
[src]
impl<'a> PartialEq<&'a str> for TextSubstring
[src]impl<'a> PartialEq<Cow<'a, TextStr>> for TextSubstring
[src]
impl<'a> PartialEq<Cow<'a, TextStr>> for TextSubstring
[src]impl<'a> PartialEq<Cow<'a, TextSubstr>> for TextSubstring
[src]
impl<'a> PartialEq<Cow<'a, TextSubstr>> for TextSubstring
[src]impl<'a> PartialEq<Cow<'a, str>> for TextSubstring
[src]
impl<'a> PartialEq<Cow<'a, str>> for TextSubstring
[src]impl PartialEq<String> for TextSubstring
[src]
impl PartialEq<String> for TextSubstring
[src]impl PartialEq<TextStr> for TextSubstring
[src]
impl PartialEq<TextStr> for TextSubstring
[src]impl PartialEq<TextSubstr> for TextSubstring
[src]
impl PartialEq<TextSubstr> for TextSubstring
[src]impl<'a> PartialEq<TextSubstring> for &'a TextSubstr
[src]
impl<'a> PartialEq<TextSubstring> for &'a TextSubstr
[src]impl PartialEq<TextSubstring> for TextSubstr
[src]
impl PartialEq<TextSubstring> for TextSubstr
[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 PartialEq<TextSubstring> for TextSubstring
[src]
impl PartialEq<TextSubstring> for TextSubstring
[src]fn eq(&self, other: &TextSubstring) -> bool
[src]
fn eq(&self, other: &TextSubstring) -> bool
[src]This method tests for self
and other
values to be equal, and is used
by ==
. Read more
fn ne(&self, other: &TextSubstring) -> bool
[src]
fn ne(&self, other: &TextSubstring) -> bool
[src]This method tests for !=
.
impl PartialEq<str> for TextSubstring
[src]
impl PartialEq<str> for TextSubstring
[src]impl PartialOrd<TextSubstring> for TextSubstring
[src]
impl PartialOrd<TextSubstring> for TextSubstring
[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 Eq for TextSubstring
[src]
impl StructuralEq for TextSubstring
[src]
impl StructuralPartialEq for TextSubstring
[src]
Auto Trait Implementations
impl RefUnwindSafe for TextSubstring
impl Send for TextSubstring
impl Sync for TextSubstring
impl Unpin for TextSubstring
impl UnwindSafe for TextSubstring
Blanket Implementations
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]pub fn borrow_mut(&mut self) -> &mut T
[src]
pub fn borrow_mut(&mut self) -> &mut T
[src]Mutably borrows from an owned value. Read more
impl<T> ToOwned for T where
T: Clone,
[src]
impl<T> ToOwned for T where
T: Clone,
[src]type Owned = T
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn to_owned(&self) -> T
[src]Creates owned data from borrowed data, usually by cloning. Read more
pub fn clone_into(&self, target: &mut T)
[src]
pub fn clone_into(&self, target: &mut T)
[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