pub struct NonEmptyString(/* private fields */);Expand description
A string that is guaranteed to contain at least one element.
NonEmptyString provides a safe wrapper around String that maintains the invariant
that the string can never be empty.
§Examples
use non_non_full::NonEmptyString;
let string = "Hello, World!".to_owned();
let non_empty = NonEmptyString::new(string).unwrap();
// Empty String returns None
assert!(NonEmptyString::new(String::new()).is_none());Implementations§
Source§impl NonEmptyString
impl NonEmptyString
Sourcepub fn new(string: String) -> Option<Self>
pub fn new(string: String) -> Option<Self>
Creates a new NonEmptyString from a String.
Returns None if the input String is empty.
Sourcepub fn into_string(self) -> String
pub fn into_string(self) -> String
Converts the NonEmptyString back into a String, consuming self
Sourcepub fn insert_str(&mut self, idx: usize, string: &str)
pub fn insert_str(&mut self, idx: usize, string: &str)
Inserts a string slice at the given byte index
Sourcepub fn remove(&mut self, idx: usize) -> Option<char>
pub fn remove(&mut self, idx: usize) -> Option<char>
Removes the char at the given byte index.
Returns None if removing would make the string empty.
Sourcepub fn pop(&mut self) -> Option<char>
pub fn pop(&mut self) -> Option<char>
Removes the last char from the string.
Returns None if this would make the string empty.
Sourcepub fn clear_except_first(&mut self)
pub fn clear_except_first(&mut self)
Clears all chars except the first one
Sourcepub fn char_indices(&self) -> CharIndices<'_>
pub fn char_indices(&self) -> CharIndices<'_>
Returns an iterator over the char indices in the string
Trait Implementations§
Source§impl Clone for NonEmptyString
impl Clone for NonEmptyString
Source§fn clone(&self) -> NonEmptyString
fn clone(&self) -> NonEmptyString
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · 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 NonEmptyString
impl Debug for NonEmptyString
impl Eq for NonEmptyString
Source§impl Hash for NonEmptyString
impl Hash for NonEmptyString
Source§impl PartialEq for NonEmptyString
impl PartialEq for NonEmptyString
impl StructuralPartialEq for NonEmptyString
Auto Trait Implementations§
impl Freeze for NonEmptyString
impl RefUnwindSafe for NonEmptyString
impl Send for NonEmptyString
impl Sync for NonEmptyString
impl Unpin for NonEmptyString
impl UnsafeUnpin for NonEmptyString
impl UnwindSafe for NonEmptyString
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