Skip to main content

NonEmpty

Struct NonEmpty 

Source
pub(crate) struct NonEmpty<T: Container>(T::Element, T);
Expand description

Small helper to ensure some container type is not empty.

Tuple Fields§

§0: T::Element§1: T

Implementations§

Source§

impl<A> NonEmpty<Vec<A>>

Source

pub(crate) fn new<I>(fst: A, rest: I) -> Self
where I: IntoIterator<Item = A>,

Source

pub(crate) fn assert_non_empty_vec<I>(it: I) -> Self
where I: IntoIterator<Item = A>,

Source

pub(crate) fn last(&self) -> &A

Source

pub(crate) fn get(&self, i: usize) -> Option<&A>

Source

pub(crate) fn iter(&self) -> impl Iterator<Item = &A>

Source§

impl<K: Ord, V> NonEmpty<BTreeMap<K, V>>

Source

pub(crate) fn assert_non_empty_map<I>(it: I) -> Self
where I: IntoIterator<Item = (K, V)>,

Source

pub(crate) fn first(&self) -> (&K, &V)

Source

pub(crate) fn last(&self) -> (&K, &V)

Source

pub(crate) fn get(&self, k: &K) -> Option<&V>

Source

pub(crate) fn iter(&self) -> impl Iterator<Item = (&K, &V)>

Trait Implementations§

Source§

impl<T: Debug + Container> Debug for NonEmpty<T>
where T::Element: Debug,

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T> Freeze for NonEmpty<T>
where <T as Container>::Element: Freeze, T: Freeze,

§

impl<T> RefUnwindSafe for NonEmpty<T>

§

impl<T> Send for NonEmpty<T>
where <T as Container>::Element: Send, T: Send,

§

impl<T> Sync for NonEmpty<T>
where <T as Container>::Element: Sync, T: Sync,

§

impl<T> Unpin for NonEmpty<T>
where <T as Container>::Element: Unpin, T: Unpin,

§

impl<T> UnsafeUnpin for NonEmpty<T>

§

impl<T> UnwindSafe for NonEmpty<T>

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Same for T

Source§

type Output = T

Should always be Self
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.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more