[−][src]Struct inlinable_string::inline_string::InlineString
A short UTF-8 string that uses inline storage and does no heap allocation.
See the module level documentation for more.
Implementations
impl InlineString
[src]
pub fn new() -> InlineString
[src]
Creates a new string buffer initialized with the empty string.
Examples
use inlinable_string::InlineString; let s = InlineString::new();
pub fn into_bytes(self) -> [u8; 30]
[src]
Returns the underlying byte buffer, encoded as UTF-8. Trailing bytes are zeroed.
Examples
use inlinable_string::InlineString; let s = InlineString::from("hello"); let bytes = s.into_bytes(); assert_eq!(&bytes[0..5], [104, 101, 108, 108, 111]);
pub fn push_str(&mut self, string: &str) -> Result<(), NotEnoughSpaceError>
[src]
Pushes the given string onto this string buffer.
Examples
use inlinable_string::InlineString; let mut s = InlineString::from("foo"); s.push_str("bar"); assert_eq!(s, "foobar");
pub fn push(&mut self, ch: char) -> Result<(), NotEnoughSpaceError>
[src]
Adds the given character to the end of the string.
Examples
use inlinable_string::InlineString; let mut s = InlineString::from("abc"); s.push('1'); s.push('2'); s.push('3'); assert_eq!(s, "abc123");
pub fn as_bytes(&self) -> &[u8]
[src]
Works with the underlying buffer as a byte slice.
Examples
use inlinable_string::InlineString; let s = InlineString::from("hello"); assert_eq!(s.as_bytes(), [104, 101, 108, 108, 111]);
pub fn truncate(&mut self, new_len: usize)
[src]
Shortens a string to the specified length.
Panics
Panics if new_len
> current length, or if new_len
is not a character
boundary.
Examples
use inlinable_string::InlineString; let mut s = InlineString::from("hello"); s.truncate(2); assert_eq!(s, "he");
pub fn pop(&mut self) -> Option<char>
[src]
Removes the last character from the string buffer and returns it.
Returns None
if this string buffer is empty.
Examples
use inlinable_string::InlineString; let mut s = InlineString::from("foo"); assert_eq!(s.pop(), Some('o')); assert_eq!(s.pop(), Some('o')); assert_eq!(s.pop(), Some('f')); assert_eq!(s.pop(), None);
pub fn remove(&mut self, idx: usize) -> char
[src]
Removes the character from the string buffer at byte position idx
and
returns it.
Panics
If idx
does not lie on a character boundary, or if it is out of
bounds, then this function will panic.
Examples
use inlinable_string::InlineString; let mut s = InlineString::from("foo"); assert_eq!(s.remove(0), 'f'); assert_eq!(s.remove(1), 'o'); assert_eq!(s.remove(0), 'o');
pub fn insert(
&mut self,
idx: usize,
ch: char
) -> Result<(), NotEnoughSpaceError>
[src]
&mut self,
idx: usize,
ch: char
) -> Result<(), NotEnoughSpaceError>
Inserts a character into the string buffer at byte position idx
.
Examples
use inlinable_string::InlineString; let mut s = InlineString::from("foo"); s.insert(2, 'f'); assert!(s == "fofo");
Panics
If idx
does not lie on a character boundary or is out of bounds, then
this function will panic.
pub fn insert_str(
&mut self,
idx: usize,
string: &str
) -> Result<(), NotEnoughSpaceError>
[src]
&mut self,
idx: usize,
string: &str
) -> Result<(), NotEnoughSpaceError>
Inserts a string into the string buffer at byte position idx
.
Examples
use inlinable_string::InlineString; let mut s = InlineString::from("foo"); s.insert_str(2, "bar"); assert!(s == "fobaro");
pub unsafe fn as_mut_slice(&mut self) -> &mut [u8]
[src]
Views the internal string buffer as a mutable sequence of bytes.
Safety
This is unsafe because it does not check to ensure that the resulting string will be valid UTF-8.
Examples
use inlinable_string::InlineString; let mut s = InlineString::from("hello"); unsafe { let slice = s.as_mut_slice(); assert!(slice == &[104, 101, 108, 108, 111]); slice.reverse(); } assert_eq!(s, "olleh");
pub fn len(&self) -> usize
[src]
Returns the number of bytes in this string.
Examples
use inlinable_string::InlineString; let a = InlineString::from("foo"); assert_eq!(a.len(), 3);
pub fn is_empty(&self) -> bool
[src]
Returns true if the string contains no bytes
Examples
use inlinable_string::InlineString; let mut v = InlineString::new(); assert!(v.is_empty()); v.push('a'); assert!(!v.is_empty());
pub fn clear(&mut self)
[src]
Truncates the string, returning it to 0 length.
Examples
use inlinable_string::InlineString; let mut s = InlineString::from("foo"); s.clear(); assert!(s.is_empty());
Trait Implementations
impl AsMut<[u8]> for InlineString
[src]
impl AsMut<str> for InlineString
[src]
impl AsRef<[u8]> for InlineString
[src]
impl AsRef<str> for InlineString
[src]
impl Clone for InlineString
[src]
pub fn clone(&self) -> InlineString
[src]
pub fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl Debug for InlineString
[src]
impl Default for InlineString
[src]
pub fn default() -> InlineString
[src]
impl Deref for InlineString
[src]
impl DerefMut for InlineString
[src]
impl Display for InlineString
[src]
impl Eq for InlineString
[src]
impl<'a> From<&'a str> for InlineString
[src]
Create a InlineString
from the given &str
.
Panics
If the given string's size is greater than INLINE_STRING_CAPACITY
, this
method panics.
pub fn from(string: &'a str) -> InlineString
[src]
impl Hash for InlineString
[src]
pub fn hash<H: Hasher>(&self, hasher: &mut H)
[src]
pub fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl Index<Range<usize>> for InlineString
[src]
type Output = str
The returned type after indexing.
pub fn index(&self, index: Range<usize>) -> &str
[src]
impl Index<RangeFrom<usize>> for InlineString
[src]
type Output = str
The returned type after indexing.
pub fn index(&self, index: RangeFrom<usize>) -> &str
[src]
impl Index<RangeFull> for InlineString
[src]
type Output = str
The returned type after indexing.
pub fn index(&self, _index: RangeFull) -> &str
[src]
impl Index<RangeTo<usize>> for InlineString
[src]
type Output = str
The returned type after indexing.
pub fn index(&self, index: RangeTo<usize>) -> &str
[src]
impl IndexMut<Range<usize>> for InlineString
[src]
impl IndexMut<RangeFrom<usize>> for InlineString
[src]
impl IndexMut<RangeFull> for InlineString
[src]
impl IndexMut<RangeTo<usize>> for InlineString
[src]
impl<'a> PartialEq<&'a str> for InlineString
[src]
pub fn eq(&self, other: &&'a str) -> bool
[src]
#[must_use]pub fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
impl<'a> PartialEq<Cow<'a, str>> for InlineString
[src]
pub fn eq(&self, other: &Cow<'a, str>) -> bool
[src]
#[must_use]pub fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
impl<'a> PartialEq<InlinableString> for InlineString
[src]
pub fn eq(&self, other: &InlinableString) -> bool
[src]
#[must_use]pub fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
impl PartialEq<InlineString> for InlineString
[src]
pub fn eq(&self, rhs: &InlineString) -> bool
[src]
#[must_use]pub fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
impl<'a> PartialEq<InlineString> for str
[src]
pub fn eq(&self, other: &InlineString) -> bool
[src]
#[must_use]pub fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
impl<'a> PartialEq<InlineString> for &'a str
[src]
pub fn eq(&self, other: &InlineString) -> bool
[src]
#[must_use]pub fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
impl<'a> PartialEq<InlineString> for Cow<'a, str>
[src]
pub fn eq(&self, other: &InlineString) -> bool
[src]
#[must_use]pub fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
impl<'a> PartialEq<InlineString> for InlinableString
[src]
pub fn eq(&self, other: &InlineString) -> bool
[src]
#[must_use]pub fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
impl<'a> PartialEq<str> for InlineString
[src]
pub fn eq(&self, other: &str) -> bool
[src]
#[must_use]pub fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
impl StructuralEq for InlineString
[src]
impl Write for InlineString
[src]
Auto Trait Implementations
impl RefUnwindSafe for InlineString
impl Send for InlineString
impl Sync for InlineString
impl Unpin for InlineString
impl UnwindSafe for InlineString
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,