pub struct IndexedString { /* private fields */ }
Expand description
A String
replacement that allows for safe indexing and slicing of multi-byte characters.
This is the owned counterpart to IndexedSlice
.
Implementations§
Source§impl IndexedString
impl IndexedString
Sourcepub fn from_str(s: impl Display) -> Self
pub fn from_str(s: impl Display) -> Self
Creates a new IndexedString
from a &str
or anything that implements Display
.
Sourcepub fn from_string(s: String) -> Self
pub fn from_string(s: String) -> Self
Creates a new IndexedString
from a String
, avoiding the need to clone the
string by taking ownership of it.
Sourcepub fn from_chars(chars: impl Iterator<Item = char>) -> Self
pub fn from_chars(chars: impl Iterator<Item = char>) -> Self
Creates a new IndexedString
from an iterator of char
s.
Trait Implementations§
Source§impl AsRef<str> for IndexedString
impl AsRef<str> for IndexedString
Source§impl Clone for IndexedString
impl Clone for IndexedString
Source§fn clone(&self) -> IndexedString
fn clone(&self) -> IndexedString
Returns a copy of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl Debug for IndexedString
impl Debug for IndexedString
Source§impl Display for IndexedString
impl Display for IndexedString
Source§impl<'a> From<&'a IndexedString> for IndexedSlice<'a>
impl<'a> From<&'a IndexedString> for IndexedSlice<'a>
Source§fn from(s: &'a IndexedString) -> Self
fn from(s: &'a IndexedString) -> Self
Converts to this type from the input type.
Source§impl From<&String> for IndexedString
impl From<&String> for IndexedString
Source§impl From<&str> for IndexedString
impl From<&str> for IndexedString
Source§impl<'a> From<IndexedSlice<'a>> for IndexedString
impl<'a> From<IndexedSlice<'a>> for IndexedString
Source§fn from(s: IndexedSlice<'a>) -> Self
fn from(s: IndexedSlice<'a>) -> Self
Converts to this type from the input type.
Source§impl From<String> for IndexedString
impl From<String> for IndexedString
Source§impl Hash for IndexedString
impl Hash for IndexedString
Source§impl IndexedStr for &IndexedString
impl IndexedStr for &IndexedString
Source§fn as_slice(&self) -> IndexedSlice<'_>
fn as_slice(&self) -> IndexedSlice<'_>
Returns a
IndexedSlice
that represents the entire contents of this IndexedStr
.Source§fn len(&self) -> usize
fn len(&self) -> usize
Returns the length of this
IndexedStr
in characters, NOT bytes.Source§fn byte_len(&self) -> usize
fn byte_len(&self) -> usize
Returns the byte length of this
IndexedStr
. This will be longer than the
len
if the string contains multi-byte characters.Source§fn char_at(&self, index: usize) -> Option<char>
fn char_at(&self, index: usize) -> Option<char>
Returns the character at the given index, if it exists.
Source§fn slice<R: RangeBounds<usize>>(&self, range: R) -> IndexedSlice<'_>
fn slice<R: RangeBounds<usize>>(&self, range: R) -> IndexedSlice<'_>
Returns a sub-slice of this
IndexedStr
based on the given range in terms of the
characters in the string, not bytes. Read moreSource§fn chars(&self) -> &[char]
fn chars(&self) -> &[char]
Returns a slice containing all characters of this
IndexedStr
in order.Source§fn to_indexed_string(&self) -> IndexedString
fn to_indexed_string(&self) -> IndexedString
Converts this
IndexedStr
into an owned, dynamically allocated IndexedString
.Source§fn lines(&self) -> IndexedLines<'_> ⓘ
fn lines(&self) -> IndexedLines<'_> ⓘ
Returns an iterator over the lines of this
IndexedStr
.Source§fn is_empty(&self) -> bool
fn is_empty(&self) -> bool
Returns
true
if this IndexedStr
is empty (of length 0).Source§fn to_lowercase(&self) -> IndexedString
fn to_lowercase(&self) -> IndexedString
Returns a new
IndexedStr
that is the lowercase version of this IndexedStr
.Source§fn to_uppercase(&self) -> IndexedString
fn to_uppercase(&self) -> IndexedString
Returns a new
IndexedStr
that is the uppercase version of this IndexedStr
.Source§fn starts_with<S: AsRef<str>>(&self, s: S) -> bool
fn starts_with<S: AsRef<str>>(&self, s: S) -> bool
Returns
true
if this IndexedStr
starts with the given string.Source§impl IndexedStr for IndexedString
impl IndexedStr for IndexedString
Source§fn char_at(&self, index: usize) -> Option<char>
fn char_at(&self, index: usize) -> Option<char>
Returns the character at the given index, if it exists.
Source§fn chars(&self) -> &[char]
fn chars(&self) -> &[char]
Returns a slice containing all characters of this
IndexedStr
in order.Source§fn len(&self) -> usize
fn len(&self) -> usize
Returns the length of this
IndexedStr
in characters, NOT bytes.Source§fn byte_len(&self) -> usize
fn byte_len(&self) -> usize
Returns the byte length of this
IndexedStr
. This will be longer than the
len
if the string contains multi-byte characters.Source§fn slice<R: RangeBounds<usize>>(&self, range: R) -> IndexedSlice<'_>
fn slice<R: RangeBounds<usize>>(&self, range: R) -> IndexedSlice<'_>
Returns a sub-slice of this
IndexedStr
based on the given range in terms of the
characters in the string, not bytes. Read moreSource§fn to_indexed_string(&self) -> IndexedString
fn to_indexed_string(&self) -> IndexedString
Converts this
IndexedStr
into an owned, dynamically allocated IndexedString
.Source§fn as_slice(&self) -> IndexedSlice<'_>
fn as_slice(&self) -> IndexedSlice<'_>
Returns a
IndexedSlice
that represents the entire contents of this IndexedStr
.Source§fn lines(&self) -> IndexedLines<'_> ⓘ
fn lines(&self) -> IndexedLines<'_> ⓘ
Returns an iterator over the lines of this
IndexedStr
.Source§fn is_empty(&self) -> bool
fn is_empty(&self) -> bool
Returns
true
if this IndexedStr
is empty (of length 0).Source§fn to_lowercase(&self) -> IndexedString
fn to_lowercase(&self) -> IndexedString
Returns a new
IndexedStr
that is the lowercase version of this IndexedStr
.Source§fn to_uppercase(&self) -> IndexedString
fn to_uppercase(&self) -> IndexedString
Returns a new
IndexedStr
that is the uppercase version of this IndexedStr
.Source§fn starts_with<S: AsRef<str>>(&self, s: S) -> bool
fn starts_with<S: AsRef<str>>(&self, s: S) -> bool
Returns
true
if this IndexedStr
starts with the given string.Source§impl PartialEq<IndexedSlice<'_>> for &IndexedString
impl PartialEq<IndexedSlice<'_>> for &IndexedString
Source§impl PartialEq<IndexedString> for &IndexedSlice<'_>
impl PartialEq<IndexedString> for &IndexedSlice<'_>
Source§impl PartialEq<IndexedString> for &IndexedString
impl PartialEq<IndexedString> for &IndexedString
Source§impl PartialEq<IndexedString> for &str
impl PartialEq<IndexedString> for &str
Source§impl PartialEq<IndexedString> for String
impl PartialEq<IndexedString> for String
impl Eq for IndexedString
Auto Trait Implementations§
impl Freeze for IndexedString
impl RefUnwindSafe for IndexedString
impl Send for IndexedString
impl Sync for IndexedString
impl Unpin for IndexedString
impl UnwindSafe for IndexedString
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
Mutably borrows from an owned value. Read more