pub struct NonEmptyString(/* private fields */);
Expand description
A simple String wrapper type, similar to NonZeroUsize and friends. Guarantees that the String contained inside is not of length 0.
Implementations§
source§impl NonEmptyString
impl NonEmptyString
sourcepub fn new(string: String) -> Result<Self, String>
pub fn new(string: String) -> Result<Self, String>
Attempts to create a new NonEmptyString
.
If the given string
is empty, Err
is returned, containing the original String
, Ok
otherwise.
sourcepub unsafe fn new_unchecked(string: String) -> Self
pub unsafe fn new_unchecked(string: String) -> Self
Creates a new NonEmptyString
, assuming string
is not empty.
§Safety
If the given string
is empty, it’ll be undefined behavior.
sourcepub fn into_inner(self) -> String
pub fn into_inner(self) -> String
Consume the NonEmptyString
to get the internal String
out.
sourcepub fn into_bytes(self) -> Vec<u8>
pub fn into_bytes(self) -> Vec<u8>
Is forwarded to the inner String.
See String::into_bytes
sourcepub fn as_str(&self) -> &str
pub fn as_str(&self) -> &str
Is forwarded to the inner String.
See String::as_str
sourcepub fn push_str(&mut self, string: &str)
pub fn push_str(&mut self, string: &str)
Is forwarded to the inner String.
See String::push_str
sourcepub fn capacity(&self) -> usize
pub fn capacity(&self) -> usize
Is forwarded to the inner String.
See String::capacity
sourcepub fn reserve(&mut self, additional: usize)
pub fn reserve(&mut self, additional: usize)
Is forwarded to the inner String.
See String::reserve
sourcepub fn reserve_exact(&mut self, additional: usize)
pub fn reserve_exact(&mut self, additional: usize)
Is forwarded to the inner String.
See String::reserve_exact
sourcepub fn try_reserve_exact(
&mut self,
additional: usize,
) -> Result<(), TryReserveError>
pub fn try_reserve_exact( &mut self, additional: usize, ) -> Result<(), TryReserveError>
Is forwarded to the inner String.
See String::try_reserve_exact
sourcepub fn shrink_to_fit(&mut self)
pub fn shrink_to_fit(&mut self)
Is forwarded to the inner String.
See std::string::String::[(&
]
sourcepub fn shrink_to(&mut self, min_capacity: usize)
pub fn shrink_to(&mut self, min_capacity: usize)
Is forwarded to the inner String.
See String::shrink_to
sourcepub fn push(&mut self, ch: char)
pub fn push(&mut self, ch: char)
Is forwarded to the inner String.
See String::push
sourcepub fn as_bytes(&self) -> &[u8] ⓘ
pub fn as_bytes(&self) -> &[u8] ⓘ
Is forwarded to the inner String.
See String::as_bytes
sourcepub fn insert(&mut self, idx: usize, ch: char)
pub fn insert(&mut self, idx: usize, ch: char)
Is forwarded to the inner String.
See String::insert
sourcepub fn insert_str(&mut self, idx: usize, string: &str)
pub fn insert_str(&mut self, idx: usize, string: &str)
Is forwarded to the inner String.
See String::insert_str
sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Is forwarded to the inner String.
See String::len
sourcepub fn into_boxed_str(self) -> Box<str>
pub fn into_boxed_str(self) -> Box<str>
Is forwarded to the inner String.
See String::into_boxed_str
Trait Implementations§
source§impl Add<&str> for NonEmptyString
impl Add<&str> for NonEmptyString
source§type Output = NonEmptyString
type Output = NonEmptyString
+
operator.source§impl AddAssign<&str> for NonEmptyString
impl AddAssign<&str> for NonEmptyString
source§fn add_assign(&mut self, other: &str)
fn add_assign(&mut self, other: &str)
+=
operation. Read moresource§impl AsRef<String> for NonEmptyString
impl AsRef<String> for NonEmptyString
source§impl AsRef<str> for NonEmptyString
impl AsRef<str> for NonEmptyString
source§impl Borrow<String> for NonEmptyString
impl Borrow<String> for NonEmptyString
source§impl Borrow<str> for NonEmptyString
impl Borrow<str> for NonEmptyString
source§impl Clone for NonEmptyString
impl Clone for NonEmptyString
source§fn clone(&self) -> NonEmptyString
fn clone(&self) -> NonEmptyString
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for NonEmptyString
impl Debug for NonEmptyString
source§impl<'de> Deserialize<'de> for NonEmptyString
impl<'de> Deserialize<'de> for NonEmptyString
source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
source§impl Display for NonEmptyString
impl Display for NonEmptyString
source§impl<'a> Extend<&'a char> for NonEmptyString
impl<'a> Extend<&'a char> for NonEmptyString
source§fn extend<I: IntoIterator<Item = &'a char>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = &'a char>>(&mut self, iter: I)
source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
#72631)source§impl<'a> Extend<&'a str> for NonEmptyString
impl<'a> Extend<&'a str> for NonEmptyString
source§fn extend<I: IntoIterator<Item = &'a str>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = &'a str>>(&mut self, iter: I)
source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
#72631)source§impl Extend<Box<str>> for NonEmptyString
impl Extend<Box<str>> for NonEmptyString
source§impl<'a> Extend<Cow<'a, str>> for NonEmptyString
impl<'a> Extend<Cow<'a, str>> for NonEmptyString
source§impl Extend<String> for NonEmptyString
impl Extend<String> for NonEmptyString
source§fn extend<I: IntoIterator<Item = String>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = String>>(&mut self, iter: I)
source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
#72631)source§impl Extend<char> for NonEmptyString
impl Extend<char> for NonEmptyString
source§fn extend<I: IntoIterator<Item = char>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = char>>(&mut self, iter: I)
source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
#72631)