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

source

pub fn new(string: String) -> Result<NonEmptyString, String>

Attempts to create a new NonEmptyString. If the given string is empty, Err is returned, containing the original String, Ok otherwise.

source

pub fn get(&self) -> &str

Returns a reference to the contained value.

source

pub fn into_inner(self) -> String

Consume the NonEmptyString to get the internal String out.

source

pub fn into_bytes(self) -> Vec<u8>

Is forwarded to the inner String. See String::into_bytes

source

pub fn as_str(&self) -> &str

Is forwarded to the inner String. See String::as_str

source

pub fn push_str(&mut self, string: &str)

Is forwarded to the inner String. See String::push_str

source

pub fn capacity(&self) -> usize

Is forwarded to the inner String. See String::capacity

source

pub fn reserve(&mut self, additional: usize)

Is forwarded to the inner String. See String::reserve

source

pub fn reserve_exact(&mut self, additional: usize)

Is forwarded to the inner String. See String::reserve_exact

source

pub fn try_reserve_exact( &mut self, additional: usize ) -> Result<(), TryReserveError>

Is forwarded to the inner String. See String::try_reserve_exact

source

pub fn shrink_to_fit(&mut self)

Is forwarded to the inner String. See std::string::String::[(&]

source

pub fn shrink_to(&mut self, min_capacity: usize)

Is forwarded to the inner String. See String::shrink_to

source

pub fn push(&mut self, ch: char)

Is forwarded to the inner String. See String::push

source

pub fn as_bytes(&self) -> &[u8]

Is forwarded to the inner String. See String::as_bytes

source

pub fn insert(&mut self, idx: usize, ch: char)

Is forwarded to the inner String. See String::insert

source

pub fn insert_str(&mut self, idx: usize, string: &str)

Is forwarded to the inner String. See String::insert_str

source

pub fn len(&self) -> usize

Is forwarded to the inner String. See String::len

source

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

§

type Output = NonEmptyString

The resulting type after applying the + operator.
source§

fn add(self, other: &str) -> NonEmptyString

Performs the + operation. Read more
source§

impl AddAssign<&str> for NonEmptyString

source§

fn add_assign(&mut self, other: &str)

Performs the += operation. Read more
source§

impl AsRef<String> for NonEmptyString

source§

fn as_ref(&self) -> &String

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl AsRef<str> for NonEmptyString

source§

fn as_ref(&self) -> &str

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl Borrow<String> for NonEmptyString

source§

fn borrow(&self) -> &String

Immutably borrows from an owned value. Read more
source§

impl Borrow<str> for NonEmptyString

source§

fn borrow(&self) -> &str

Immutably borrows from an owned value. Read more
source§

impl Clone for NonEmptyString

source§

fn clone(&self) -> NonEmptyString

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for NonEmptyString

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'de> Deserialize<'de> for NonEmptyString

source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl Display for NonEmptyString

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'a> Extend<&'a char> for NonEmptyString

source§

fn extend<I: IntoIterator<Item = &'a char>>(&mut self, iter: I)

Extends a collection with the contents of an iterator. Read more
source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one #72631)
Extends a collection with exactly one element.
source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one #72631)
Reserves capacity in a collection for the given number of additional elements. Read more
source§

impl<'a> Extend<&'a str> for NonEmptyString

source§

fn extend<I: IntoIterator<Item = &'a str>>(&mut self, iter: I)

Extends a collection with the contents of an iterator. Read more
source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one #72631)
Extends a collection with exactly one element.
source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one #72631)
Reserves capacity in a collection for the given number of additional elements. Read more
source§

impl Extend<Box<str>> for NonEmptyString

source§

fn extend<I: IntoIterator<Item = Box<str>>>(&mut self, iter: I)

Extends a collection with the contents of an iterator. Read more
source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one #72631)
Extends a collection with exactly one element.
source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one #72631)
Reserves capacity in a collection for the given number of additional elements. Read more
source§

impl<'a> Extend<Cow<'a, str>> for NonEmptyString

source§

fn extend<I: IntoIterator<Item = Cow<'a, str>>>(&mut self, iter: I)

Extends a collection with the contents of an iterator. Read more
source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one #72631)
Extends a collection with exactly one element.
source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one #72631)
Reserves capacity in a collection for the given number of additional elements. Read more
source§

impl Extend<String> for NonEmptyString

source§

fn extend<I: IntoIterator<Item = String>>(&mut self, iter: I)

Extends a collection with the contents of an iterator. Read more
source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one #72631)
Extends a collection with exactly one element.
source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one #72631)
Reserves capacity in a collection for the given number of additional elements. Read more
source§

impl Extend<char> for NonEmptyString

source§

fn extend<I: IntoIterator<Item = char>>(&mut self, iter: I)

Extends a collection with the contents of an iterator. Read more
source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one #72631)
Extends a collection with exactly one element.
source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one #72631)
Reserves capacity in a collection for the given number of additional elements. Read more
source§

impl From<NonEmptyString> for String

source§

fn from(value: NonEmptyString) -> Self

Converts to this type from the input type.
source§

impl From<char> for NonEmptyString

source§

fn from(c: char) -> Self

Converts to this type from the input type.
source§

impl FromStr for NonEmptyString

§

type Err = <NonEmptyString as TryFrom<String>>::Error

The associated error which can be returned from parsing.
source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
source§

impl Hash for NonEmptyString

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl Index<Range<usize>> for NonEmptyString

§

type Output = str

The returned type after indexing.
source§

fn index(&self, index: Range<usize>) -> &str

Performs the indexing (container[index]) operation. Read more
source§

impl Index<RangeFrom<usize>> for NonEmptyString

§

type Output = str

The returned type after indexing.
source§

fn index(&self, index: RangeFrom<usize>) -> &str

Performs the indexing (container[index]) operation. Read more
source§

impl Index<RangeFull> for NonEmptyString

§

type Output = str

The returned type after indexing.
source§

fn index(&self, index: RangeFull) -> &str

Performs the indexing (container[index]) operation. Read more
source§

impl Index<RangeInclusive<usize>> for NonEmptyString

§

type Output = str

The returned type after indexing.
source§

fn index(&self, index: RangeInclusive<usize>) -> &str

Performs the indexing (container[index]) operation. Read more
source§

impl Index<RangeTo<usize>> for NonEmptyString

§

type Output = str

The returned type after indexing.
source§

fn index(&self, index: RangeTo<usize>) -> &str

Performs the indexing (container[index]) operation. Read more
source§

impl Index<RangeToInclusive<usize>> for NonEmptyString

§

type Output = str

The returned type after indexing.
source§

fn index(&self, index: RangeToInclusive<usize>) -> &str

Performs the indexing (container[index]) operation. Read more
source§

impl Ord for NonEmptyString

source§

fn cmp(&self, other: &NonEmptyString) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Selfwhere Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl<'a, 'b> PartialEq<&'a str> for NonEmptyString

source§

fn eq(&self, other: &&'a str) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'a, 'b> PartialEq<Cow<'a, str>> for NonEmptyString

source§

fn eq(&self, other: &Cow<'a, str>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'a, 'b> PartialEq<NonEmptyString> for &'a str

source§

fn eq(&self, other: &NonEmptyString) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'a, 'b> PartialEq<NonEmptyString> for Cow<'a, str>

source§

fn eq(&self, other: &NonEmptyString) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'a, 'b> PartialEq<NonEmptyString> for String

source§

fn eq(&self, other: &NonEmptyString) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'a, 'b> PartialEq<NonEmptyString> for str

source§

fn eq(&self, other: &NonEmptyString) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'a, 'b> PartialEq<String> for NonEmptyString

source§

fn eq(&self, other: &String) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'a, 'b> PartialEq<str> for NonEmptyString

source§

fn eq(&self, other: &str) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq for NonEmptyString

source§

fn eq(&self, other: &NonEmptyString) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd for NonEmptyString

source§

fn partial_cmp(&self, other: &NonEmptyString) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl Serialize for NonEmptyString

source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>where S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl<'s> TryFrom<&'s str> for NonEmptyString

§

type Error = &'s str

The type returned in the event of a conversion error.
source§

fn try_from(value: &'s str) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<String> for NonEmptyString

§

type Error = String

The type returned in the event of a conversion error.
source§

fn try_from(value: String) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl Write for NonEmptyString

source§

fn write_str(&mut self, s: &str) -> Result

Writes a string slice into this writer, returning whether the write succeeded. Read more
source§

fn write_char(&mut self, c: char) -> Result

Writes a char into this writer, returning whether the write succeeded. Read more
1.0.0 · source§

fn write_fmt(&mut self, args: Arguments<'_>) -> Result<(), Error>

Glue for usage of the write! macro with implementors of this trait. Read more
source§

impl Eq for NonEmptyString

source§

impl StructuralEq for NonEmptyString

source§

impl StructuralPartialEq for NonEmptyString

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> DeserializeOwned for Twhere T: for<'de> Deserialize<'de>,