Skip to main content

NonEmptyString

Struct NonEmptyString 

Source
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<Self, String>

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

Source

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.

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

Available on non-no_global_oom_handling only.
Source§

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

Available on non-no_global_oom_handling only.
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 duplicate of the value. Read more
1.0.0 (const: unstable) · 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 Eq for NonEmptyString

Source§

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

Available on non-no_global_oom_handling only.
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

Available on non-no_global_oom_handling only.
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

Available on non-no_global_oom_handling only.
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

Available on non-no_global_oom_handling only.
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

Available on non-no_global_oom_handling only.
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

Available on non-no_global_oom_handling only.
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

Available on non-no_global_oom_handling only.
Source§

fn from(c: char) -> Self

Converts to this type from the input type.
Source§

impl FromStr for NonEmptyString

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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

Source§

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 (const: unstable) · Source§

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

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

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

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

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

impl PartialEq for NonEmptyString

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

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

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

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

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

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

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

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

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

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

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

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

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

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

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

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

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
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 (const: unstable) · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

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

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 StructuralPartialEq for NonEmptyString

Source§

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

Source§

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

Source§

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

Available on non-no_global_oom_handling only.
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

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit #126799)
Performs copy-assignment from self to dest. Read more
Source§

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

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where 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 T
where T: Clone,

Source§

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 T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

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

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

Source§

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 T
where U: TryFrom<T>,

Source§

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.