[][src]Struct inlinable_string::inline_string::InlineString

pub struct InlineString { /* fields omitted */ }

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; 14][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]

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]

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]

impl Debug for InlineString[src]

impl Default for InlineString[src]

impl Deref for InlineString[src]

type Target = str

The resulting type after dereferencing.

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.

impl Hash for InlineString[src]

impl Index<Range<usize>> for InlineString[src]

type Output = str

The returned type after indexing.

impl Index<RangeFrom<usize>> for InlineString[src]

type Output = str

The returned type after indexing.

impl Index<RangeFull> for InlineString[src]

type Output = str

The returned type after indexing.

impl Index<RangeTo<usize>> for InlineString[src]

type Output = str

The returned type after indexing.

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]

impl<'a> PartialEq<Cow<'a, str>> for InlineString[src]

impl<'a> PartialEq<InlinableString> for InlineString[src]

impl PartialEq<InlineString> for InlineString[src]

impl<'a> PartialEq<InlineString> for str[src]

impl<'a> PartialEq<InlineString> for &'a str[src]

impl<'a> PartialEq<InlineString> for Cow<'a, str>[src]

impl<'a> PartialEq<InlineString> for InlinableString[src]

impl<'a> PartialEq<str> for InlineString[src]

impl StructuralEq for InlineString[src]

impl Write for InlineString[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.