pub struct StrData { /* private fields */ }Implementations§
Source§impl StrData
impl StrData
Sourcepub unsafe fn new_str_unchecked(data: Box<Wtf8>, kind: StrKind) -> Self
pub unsafe fn new_str_unchecked(data: Box<Wtf8>, kind: StrKind) -> Self
§Safety
Given bytes must be valid data for given kind
Sourcepub unsafe fn new_with_char_len(
data: Box<Wtf8>,
kind: StrKind,
char_len: usize,
) -> Self
pub unsafe fn new_with_char_len( data: Box<Wtf8>, kind: StrKind, char_len: usize, ) -> Self
§Safety
char_len must be accurate.
pub const fn as_wtf8(&self) -> &Wtf8
pub fn as_str(&self) -> Option<&str>
pub fn as_ascii(&self) -> Option<&AsciiStr>
pub const fn kind(&self) -> StrKind
pub fn as_str_kind(&self) -> PyKindStr<'_>
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
pub fn char_len(&self) -> usize
Sourcepub fn char_index_to_byte(&self, index: usize) -> usize
pub fn char_index_to_byte(&self, index: usize) -> usize
The byte offset the index-th code point starts at.
An index at or past the end answers the buffer’s byte length, so a
caller walking to a bound does not have to special-case it.
O(1), but the first call on a non-ASCII string builds an index over the
whole buffer, so a caller that resolves a single index and stops is
better served by Self::nth_char.
Sourcepub fn char_range_to_bytes(&self, range: Range<usize>) -> Range<usize> ⓘ
pub fn char_range_to_bytes(&self, range: Range<usize>) -> Range<usize> ⓘ
The byte range spanned by the code points in range, whose end must not
exceed the string’s code point count.
A range that reaches within [MAX_WALK_TO_INDEX] of both ends is
walked to for the same reason a single index near one end is – a slice
like s[1:-1] should not build a table over the whole string.
Sourcepub fn byte_to_char_index(&self, bytepos: usize) -> usize
pub fn byte_to_char_index(&self, bytepos: usize) -> usize
The character index of the character starting at byte offset bytepos,
the inverse of Self::char_index_to_byte.
bytepos must be a character boundary at or before the end.
Logarithmic rather than constant, because the index is keyed the other
way – but a search whose bounds came from char_index_to_byte has the
table already, and this is what turns a byte offset back into the answer
a caller asked for in characters.
pub fn nth_char(&self, index: usize) -> CodePoint
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for StrData
impl !RefUnwindSafe for StrData
impl !Send for StrData
impl !Sync for StrData
impl Unpin for StrData
impl UnsafeUnpin for StrData
impl UnwindSafe for StrData
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T, U> ImaginaryInto<U> for Twhere
U: ImaginaryFrom<T>,
impl<T, U> ImaginaryInto<U> for Twhere
U: ImaginaryFrom<T>,
fn imaginary_into(self) -> U
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more