NEVec

Struct NEVec 

Source
pub struct NEVec<T> { /* private fields */ }
Expand description

A non-empty, growable Vector.

The first element can always be accessed in constant time. Similarly, certain functions like NEVec::first and NEVec::last always succeed:

use nonempty_collections::nev;

let s = nev!["Fëanor", "Fingolfin", "Finarfin"];
assert_eq!(&"Fëanor", s.first()); // There is always a first element.
assert_eq!(&"Finarfin", s.last()); // There is always a last element.

Implementations§

Source§

impl<T> NEVec<T>

Source

pub fn new(head: T) -> Self

Create a new non-empty list with an initial element.

Source

pub fn with_capacity(capacity: NonZeroUsize, head: T) -> Self

Creates a new NEVec with a single element and specified capacity.

Source

pub fn first(&self) -> &T

Get the first element. Never fails.

Source

pub fn first_mut(&mut self) -> &mut T

Get the mutable reference to the first element. Never fails.

§Examples
use nonempty_collections::nev;

let mut v = nev![42];
let head = v.first_mut();
*head += 1;
assert_eq!(v.first(), &43);

let mut v = nev![1, 4, 2, 3];
let head = v.first_mut();
*head *= 42;
assert_eq!(v.first(), &42);
Source

pub fn push(&mut self, e: T)

Push an element to the end of the list.

Source

pub fn pop(&mut self) -> Option<T>

Pop an element from the end of the list. Is a no-op when Self::len() is 1.

use nonempty_collections::nev;

let mut v = nev![1, 2];
assert_eq!(Some(2), v.pop());
assert_eq!(None, v.pop());
Source

pub fn remove(&mut self, index: usize) -> Option<T>

Removes and returns the element at position index within the vector, shifting all elements after it to the left.

If this NEVec contains only one element, no removal takes place and None will be returned. If there are more elements, the item at the index is removed and returned.

Note: Because this shifts over the remaining elements, it has a worst-case performance of O(n). If you don’t need the order of elements to be preserved, use swap_remove instead.

§Panics

Panics if index is out of bounds and self.len() > 1

§Examples
use nonempty_collections::nev;

let mut v = nev![1, 2, 3];
assert_eq!(v.remove(1), Some(2));
assert_eq!(nev![1, 3], v);
Source

pub fn swap_remove(&mut self, index: usize) -> Option<T>

Removes an element from the vector and returns it.

If this NEVec contains only one element, no removal takes place and None will be returned. If there are more elements, the item at the index is removed and returned.

The removed element is replaced by the last element of the vector.

This does not preserve ordering of the remaining elements, but is O(1). If you need to preserve the element order, use remove instead.

§Panics

Panics if index is out of bounds and self.len() > 1

§Examples
use nonempty_collections::nev;

let mut v = nev![1, 2, 3, 4];
assert_eq!(v.swap_remove(1), Some(2));
assert_eq!(nev![1, 4, 3], v);
Source

pub fn retain<F>(self, f: F) -> Result<Self, Vec<T>>
where F: FnMut(&T) -> bool,

Retains only the elements specified by the predicate.

In other words, remove all elements e for which f(&e) returns false. This method operates in place, visiting each element exactly once in the original order, and preserves the order of the retained elements.

If there are one or more items retained Ok(Self) is returned with the remaining items. If all items are removed, the inner Vec is returned to allowed for reuse of the claimed memory.

§Errors

Returns Err if no elements are retained.

§Examples
use nonempty_collections::nev;

let vec = nev![1, 2, 3, 4];
let vec = vec.retain(|&x| x % 2 == 0);
assert_eq!(Ok(nev![2, 4]), vec);
Source

pub fn retain_mut<F>(self, f: F) -> Result<Self, Vec<T>>
where F: FnMut(&mut T) -> bool,

Retains only the elements specified by the predicate, passing a mutable reference to it.

In other words, remove all elements e such that f(&mut e) returns false. This method operates in place, visiting each element exactly once in the original order, and preserves the order of the retained elements.

If there are one or more items retained Ok(Self) is returned with the remaining items. If all items are removed, the inner Vec is returned to allowed for reuse of the claimed memory.

§Errors

Returns Err if no elements are retained.

§Examples
use nonempty_collections::nev;

let vec = nev![1, 2, 3, 4];
let vec = vec.retain_mut(|x| {
    if *x <= 3 {
        *x += 1;
        true
    } else {
        false
    }
});
assert_eq!(Ok(nev![2, 3, 4]), vec);
Source

pub fn insert(&mut self, index: usize, element: T)

Inserts an element at position index within the vector, shifting all elements after it to the right.

§Panics

Panics if index > len.

§Examples
use nonempty_collections::nev;

let mut v = nev![1, 2, 3];
v.insert(1, 4);
assert_eq!(v, nev![1, 4, 2, 3]);
v.insert(4, 5);
assert_eq!(v, nev![1, 4, 2, 3, 5]);
v.insert(0, 42);
assert_eq!(v, nev![42, 1, 4, 2, 3, 5]);
Source

pub fn len(&self) -> NonZeroUsize

Get the length of the list.

Source

pub const fn is_empty(&self) -> bool

👎Deprecated since 0.1.0: A NEVec is never empty.

A NEVec is never empty.

Source

pub fn capacity(&self) -> NonZeroUsize

Get the capacity of the list.

Source

pub fn last(&self) -> &T

Get the last element. Never fails.

Source

pub fn last_mut(&mut self) -> &mut T

Get the last element mutably.

Source

pub fn contains(&self, x: &T) -> bool
where T: PartialEq,

Check whether an element is contained in the list.

use nonempty_collections::nev;

let mut l = nev![42, 36, 58];

assert!(l.contains(&42));
assert!(!l.contains(&101));
Source

pub fn get(&self, index: usize) -> Option<&T>

Get an element by index.

Source

pub fn get_mut(&mut self, index: usize) -> Option<&mut T>

Get an element by index, mutably.

Source

pub fn truncate(&mut self, len: NonZeroUsize)

Truncate the list to a certain size.

Source

pub fn iter(&self) -> Iter<'_, T>

Returns a regular iterator over the values in this non-empty vector.

For a NonEmptyIterator see Self::nonempty_iter().

Source

pub fn iter_mut(&mut self) -> IterMut<'_, T>

Returns a regular mutable iterator over the values in this non-empty vector.

For a NonEmptyIterator see Self::nonempty_iter_mut().

Source

pub fn nonempty_iter(&self) -> Iter<'_, T>

use nonempty_collections::*;

let mut l = nev![42, 36, 58];

let mut iter = l.nonempty_iter();
let (first, mut rest_iter) = iter.next();

assert_eq!(first, &42);
assert_eq!(rest_iter.next(), Some(&36));
assert_eq!(rest_iter.next(), Some(&58));
assert_eq!(rest_iter.next(), None);
Source

pub fn nonempty_iter_mut(&mut self) -> IterMut<'_, T>

Returns an iterator that allows modifying each value.

§Examples
use nonempty_collections::*;

let mut l = nev![42, 36, 58];

for i in l.nonempty_iter_mut() {
   *i *= 10;
}

let mut iter = l.nonempty_iter();
let (first, mut rest_iter) = iter.next();

assert_eq!(first, &420);
assert_eq!(rest_iter.next(), Some(&360));
assert_eq!(rest_iter.next(), Some(&580));
assert_eq!(rest_iter.next(), None);
Source

pub fn try_from_slice(slice: &[T]) -> Option<NEVec<T>>
where T: Clone,

Creates a new non-empty vec by cloning the elements from the slice if it is non-empty, returns None otherwise.

Often we have a Vec (or slice &[T]) but want to ensure that it is NEVec before proceeding with a computation. Using try_from_slice will give us a proof that we have a NEVec in the Some branch, otherwise it allows the caller to handle the None case.

§Example use
use nonempty_collections::nev;
use nonempty_collections::NEVec;

let v_vec = NEVec::try_from_slice(&[1, 2, 3, 4, 5]);
assert_eq!(v_vec, Some(nev![1, 2, 3, 4, 5]));

let empty_vec: Option<NEVec<&u32>> = NEVec::try_from_slice(&[]);
assert!(empty_vec.is_none());
Source

pub fn try_from_vec(vec: Vec<T>) -> Option<NEVec<T>>

Often we have a Vec (or slice &[T]) but want to ensure that it is NEVec before proceeding with a computation. Using try_from_vec will give us a proof that we have a NEVec in the Some branch, otherwise it allows the caller to handle the None case.

This version will consume the Vec you pass in. If you would rather pass the data as a slice then use NEVec::try_from_slice.

§Example Use
use nonempty_collections::nev;
use nonempty_collections::NEVec;

let v_vec = NEVec::try_from_vec(vec![1, 2, 3, 4, 5]);
assert_eq!(v_vec, Some(nev![1, 2, 3, 4, 5]));

let empty_vec: Option<NEVec<&u32>> = NEVec::try_from_vec(vec![]);
assert!(empty_vec.is_none());
Source

pub fn split_first(&self) -> (&T, &[T])

Deconstruct a NEVec into its head and tail. This operation never fails since we are guaranteed to have a head element.

§Example Use
use nonempty_collections::nev;

let mut v = nev![1, 2, 3, 4, 5];

// Guaranteed to have the head and we also get the tail.
assert_eq!(v.split_first(), (&1, &[2, 3, 4, 5][..]));

let v = nev![1];

// Guaranteed to have the head element.
assert_eq!(v.split_first(), (&1, &[][..]));
Source

pub fn split(&self) -> (&T, &[T], &T)

Deconstruct a NEVec into its first, last, and middle elements, in that order.

If there is only one element then first == last.

§Example Use
use nonempty_collections::nev;

let mut v = nev![1, 2, 3, 4, 5];

// Guaranteed to have the last element and the elements
// preceding it.
assert_eq!(v.split(), (&1, &[2, 3, 4][..], &5));

let v = nev![1];

// Guaranteed to have the last element.
assert_eq!(v.split(), (&1, &[][..], &1));
Source

pub fn append(&mut self, other: &mut Vec<T>)

Append a Vec to the tail of the NEVec.

§Example Use
use nonempty_collections::nev;

let mut v = nev![1];
let mut vec = vec![2, 3, 4, 5];
v.append(&mut vec);

let mut expected = nev![1, 2, 3, 4, 5];
assert_eq!(v, expected);

Binary searches this sorted non-empty vector for a given element.

If the value is found then Result::Ok is returned, containing the index of the matching element. If there are multiple matches, then any one of the matches could be returned.

§Errors

If the value is not found then Result::Err is returned, containing the index where a matching element could be inserted while maintaining sorted order.

§Examples
use nonempty_collections::nev;

let v = nev![0, 1, 1, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55];
assert_eq!(v.binary_search(&0), Ok(0));
assert_eq!(v.binary_search(&13), Ok(9));
assert_eq!(v.binary_search(&4), Err(7));
assert_eq!(v.binary_search(&100), Err(13));
let r = v.binary_search(&1);
assert!(match r {
    Ok(1..=4) => true,
    _ => false,
});

If you want to insert an item to a sorted non-empty vector, while maintaining sort order:

use nonempty_collections::nev;

let mut v = nev![0, 1, 1, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55];
let num = 42;
let idx = v.binary_search(&num).unwrap_or_else(|x| x);
v.insert(idx, num);
assert_eq!(v, nev![0, 1, 1, 1, 1, 2, 3, 5, 8, 13, 21, 34, 42, 55]);
Source

pub fn binary_search_by<'a, F>(&'a self, f: F) -> Result<usize, usize>
where F: FnMut(&'a T) -> Ordering,

Binary searches this sorted non-empty with a comparator function.

The comparator function should implement an order consistent with the sort order of the underlying slice, returning an order code that indicates whether its argument is Less, Equal or Greater the desired target.

If the value is found then Result::Ok is returned, containing the index of the matching element. If there are multiple matches, then any one of the matches could be returned.

§Errors

If the value is not found then Result::Err is returned, containing the index where a matching element could be inserted while maintaining sorted order.

§Examples

Looks up a series of four elements. The first is found, with a uniquely determined position; the second and third are not found; the fourth could match any position from 1 to 4.

use nonempty_collections::nev;

let v = nev![0, 1, 1, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55];
let seek = 0;
assert_eq!(v.binary_search_by(|probe| probe.cmp(&seek)), Ok(0));
let seek = 13;
assert_eq!(v.binary_search_by(|probe| probe.cmp(&seek)), Ok(9));
let seek = 4;
assert_eq!(v.binary_search_by(|probe| probe.cmp(&seek)), Err(7));
let seek = 100;
assert_eq!(v.binary_search_by(|probe| probe.cmp(&seek)), Err(13));
let seek = 1;
let r = v.binary_search_by(|probe| probe.cmp(&seek));
assert!(match r {
    Ok(1..=4) => true,
    _ => false,
});
Source

pub fn binary_search_by_key<'a, B, F>( &'a self, b: &B, f: F, ) -> Result<usize, usize>
where B: Ord, F: FnMut(&'a T) -> B,

Binary searches this sorted non-empty vector with a key extraction function.

Assumes that the vector is sorted by the key.

If the value is found then Result::Ok is returned, containing the index of the matching element. If there are multiple matches, then any one of the matches could be returned.

§Errors

If the value is not found then Result::Err is returned, containing the index where a matching element could be inserted while maintaining sorted order.

§Examples

Looks up a series of four elements in a non-empty vector of pairs sorted by their second elements. The first is found, with a uniquely determined position; the second and third are not found; the fourth could match any position in [1, 4].

use nonempty_collections::nev;

let v = nev![
    (0, 0),
    (2, 1),
    (4, 1),
    (5, 1),
    (3, 1),
    (1, 2),
    (2, 3),
    (4, 5),
    (5, 8),
    (3, 13),
    (1, 21),
    (2, 34),
    (4, 55)
];

assert_eq!(v.binary_search_by_key(&0, |&(a, b)| b), Ok(0));
assert_eq!(v.binary_search_by_key(&13, |&(a, b)| b), Ok(9));
assert_eq!(v.binary_search_by_key(&4, |&(a, b)| b), Err(7));
assert_eq!(v.binary_search_by_key(&100, |&(a, b)| b), Err(13));
let r = v.binary_search_by_key(&1, |&(a, b)| b);
assert!(match r {
    Ok(1..=4) => true,
    _ => false,
});
Source

pub fn sort(&mut self)
where T: Ord,

Sorts the NEVec in place.

See also slice::sort.

§Examples
use nonempty_collections::nev;

let mut n = nev![5, 4, 3, 2, 1];
n.sort();
assert_eq!(nev![1, 2, 3, 4, 5], n);

// Naturally, sorting a sorted result should remain the same.
n.sort();
assert_eq!(nev![1, 2, 3, 4, 5], n);
Source

pub fn sort_by<F>(&mut self, f: F)
where F: FnMut(&T, &T) -> Ordering,

Like NEVec::sort, but sorts the NEVec with a given comparison function.

See also slice::sort_by.

use nonempty_collections::nev;

let mut n = nev!["Sirion", "Gelion", "Narog"];
n.sort_by(|a, b| b.cmp(&a));
assert_eq!(nev!["Sirion", "Narog", "Gelion"], n);
Source

pub fn sort_by_key<K, F>(&mut self, f: F)
where F: FnMut(&T) -> K, K: Ord,

Like NEVec::sort, but sorts the NEVec after first transforming each element into something easily comparable. Beware of expensive key functions, as the results of each call are not cached.

See also slice::sort_by_key.

use nonempty_collections::nev;

let mut n = nev![-5, 4, -3, 2, 1];
n.sort_by_key(|x| x * x);
assert_eq!(nev![1, 2, -3, 4, -5], n);

// Naturally, sorting a sorted result should remain the same.
n.sort_by_key(|x| x * x);
assert_eq!(nev![1, 2, -3, 4, -5], n);
Source

pub fn as_nonempty_slice(&self) -> NESlice<'_, T>

Yields a NESlice.

Source

pub fn dedup_by_key<F, K>(&mut self, key: F)
where F: FnMut(&mut T) -> K, K: PartialEq,

Removes all but the first of consecutive elements in the vector that resolve to the same key.

If the vector is sorted, this removes all duplicates.

§Examples
use nonempty_collections::nev;
let mut v = nev![10, 20, 21, 30, 20];

v.dedup_by_key(|i| *i / 10);

assert_eq!(nev![10, 20, 30, 20], v);
Source

pub fn dedup_by<F>(&mut self, same_bucket: F)
where F: FnMut(&mut T, &mut T) -> bool,

Removes all but the first of consecutive elements in the vector satisfying a given equality relation.

The same_bucket function is passed references to two elements from the vector and must determine if the elements compare equal. The elements are passed in opposite order from their order in the slice, so if same_bucket(a, b) returns true, a is removed.

If the vector is sorted, this removes all duplicates.

§Examples
use nonempty_collections::nev;
let mut v = nev!["foo", "Foo", "foo", "bar", "Bar", "baz", "bar"];

v.dedup_by(|a, b| a.eq_ignore_ascii_case(b));

assert_eq!(nev!["foo", "bar", "baz", "bar"], v);
Source

pub fn nonempty_chunks(&self, chunk_size: NonZeroUsize) -> NEChunks<'_, T>

Returns a non-empty iterator over chunk_size elements of the NEVec at a time, starting at the beginning of the NEVec.

use std::num::NonZeroUsize;

use nonempty_collections::*;

let v = nev![1, 2, 3, 4, 5, 6];
let n = NonZeroUsize::new(2).unwrap();
let r = v.nonempty_chunks(n).collect::<NEVec<_>>();

let a = nev![1, 2];
let b = nev![3, 4];
let c = nev![5, 6];

assert_eq!(
    r,
    nev![
        a.as_nonempty_slice(),
        b.as_nonempty_slice(),
        c.as_nonempty_slice()
    ]
);
Source

pub fn partition_point<P>(&self, pred: P) -> usize
where P: FnMut(&T) -> bool,

Returns the index of the partition point according to the given predicate (the index of the first element of the second partition).

The vector is assumed to be partitioned according to the given predicate. This means that all elements for which the predicate returns true are at the start of the vector and all elements for which the predicate returns false are at the end. For example, [7, 15, 3, 5, 4, 12, 6] is partitioned under the predicate x % 2 != 0 (all odd numbers are at the start, all even at the end).

If this vector is not partitioned, the returned result is unspecified and meaningless, as this method performs a kind of binary search.

See also NEVec::binary_search, NEVec::binary_search_by, and NEVec::binary_search_by_key.

§Examples
let v = nev![1, 2, 3, 3, 5, 6, 7];
let i = v.partition_point(|&x| x < 5);

assert_eq!(i, 4);

If all elements of the non-empty vector match the predicate, then the length of the vector will be returned:

let a = nev![2, 4, 8];
assert_eq!(a.partition_point(|&x| x < 100), a.len().get());

If you want to insert an item to a sorted vector, while maintaining sort order:

let mut s = nev![0, 1, 1, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55];
let num = 42;
let idx = s.partition_point(|&x| x < num);
s.insert(idx, num);
assert_eq!(s, nev![0, 1, 1, 1, 1, 2, 3, 5, 8, 13, 21, 34, 42, 55]);
Source§

impl<T: PartialEq> NEVec<T>

Source

pub fn dedup(&mut self)

Removes consecutive repeated elements in the vector according to the PartialEq trait implementation.

If the vector is sorted, this removes all duplicates.

§Examples
use nonempty_collections::nev;
let mut v = nev![1, 1, 1, 2, 3, 2, 2, 1];
v.dedup();
assert_eq!(nev![1, 2, 3, 2, 1], v);

Trait Implementations§

Source§

impl<T> AsMut<Vec<T>> for NEVec<T>

Source§

fn as_mut(&mut self) -> &mut Vec<T>

Converts this type into a mutable reference of the (usually inferred) input type.
Source§

impl<T> AsRef<Vec<T>> for NEVec<T>

Source§

fn as_ref(&self) -> &Vec<T>

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

impl<T: Clone> Clone for NEVec<T>

Source§

fn clone(&self) -> NEVec<T>

Returns a duplicate 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<T: Debug> Debug for NEVec<T>

Source§

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

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

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

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<T> Extend<T> for NEVec<T>

Source§

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

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)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

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

impl<T> From<(T, Vec<T>)> for NEVec<T>

Source§

fn from((head, tail): (T, Vec<T>)) -> Self

Turns a pair of an element and a Vec into a NEVec.

Source§

impl<T> From<NEVec<T>> for Vec<T>

Source§

fn from(nonempty: NEVec<T>) -> Vec<T>

Turns a non-empty list into a Vec.

Source§

impl<T> FromNonEmptyIterator<T> for NEVec<T>

use nonempty_collections::*;

let v0 = nev![1, 2, 3];
let v1: NEVec<_> = v0.nonempty_iter().cloned().collect();
assert_eq!(v0, v1);
Source§

fn from_nonempty_iter<I>(iter: I) -> Self
where I: IntoNonEmptyIterator<Item = T>,

Creates a value from a NonEmptyIterator.
Source§

impl<T: Hash> Hash for NEVec<T>

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<T> Index<usize> for NEVec<T>

Source§

fn index(&self, index: usize) -> &T

use nonempty_collections::nev;

let v = nev![1, 2, 3, 4, 5];

assert_eq!(v[0], 1);
assert_eq!(v[1], 2);
assert_eq!(v[3], 4);
Source§

type Output = T

The returned type after indexing.
Source§

impl<T> IndexMut<usize> for NEVec<T>

Source§

fn index_mut(&mut self, index: usize) -> &mut T

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

impl<'a, T> IntoIterator for &'a NEVec<T>

Source§

type Item = &'a T

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'a, T>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<'a, T> IntoIterator for &'a mut NEVec<T>

Source§

type Item = &'a mut T

The type of the elements being iterated over.
Source§

type IntoIter = IterMut<'a, T>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<T> IntoIterator for NEVec<T>

Source§

type Item = T

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<<NEVec<T> as IntoIterator>::Item>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<'a, T> IntoNonEmptyIterator for &'a NEVec<T>

Source§

type IntoNEIter = Iter<'a, T>

Which kind of NonEmptyIterator are we turning this into?
Source§

fn into_nonempty_iter(self) -> Self::IntoNEIter

Creates a NonEmptyIterator from a value.
Source§

impl<T> IntoNonEmptyIterator for NEVec<T>

Source§

type IntoNEIter = IntoIter<T>

Which kind of NonEmptyIterator are we turning this into?
Source§

fn into_nonempty_iter(self) -> Self::IntoNEIter

Creates a NonEmptyIterator from a value.
Source§

impl<T: Ord> Ord for NEVec<T>

Source§

fn cmp(&self, other: &NEVec<T>) -> Ordering

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

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

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

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

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

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

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

impl<T: PartialEq> PartialEq for NEVec<T>

Source§

fn eq(&self, other: &NEVec<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T: PartialOrd> PartialOrd for NEVec<T>

Source§

fn partial_cmp(&self, other: &NEVec<T>) -> 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

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

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

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<T> Serialize for NEVec<T>
where T: Clone + Serialize,

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<T> Singleton for NEVec<T>

Source§

fn singleton(item: T) -> NEVec<T>

use nonempty_collections::{NEVec, Singleton, nev};

let v = NEVec::singleton(1);
assert_eq!(nev![1], v);
Source§

type Item = T

Source§

impl<T> TryFrom<Vec<T>> for NEVec<T>

Source§

type Error = Error

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

fn try_from(vec: Vec<T>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<T: Eq> Eq for NEVec<T>

Source§

impl<T> StructuralPartialEq for NEVec<T>

Auto Trait Implementations§

§

impl<T> Freeze for NEVec<T>

§

impl<T> RefUnwindSafe for NEVec<T>
where T: RefUnwindSafe,

§

impl<T> Send for NEVec<T>
where T: Send,

§

impl<T> Sync for NEVec<T>
where T: Sync,

§

impl<T> Unpin for NEVec<T>
where T: Unpin,

§

impl<T> UnwindSafe for NEVec<T>
where T: UnwindSafe,

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)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Comparable<K> for Q
where Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn compare(&self, key: &K) -> Ordering

Compare self to key and return their ordering.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> IntoIteratorExt for T
where T: IntoIterator,

Source§

fn try_into_nonempty_iter(self) -> Option<<T as IntoIteratorExt>::IntoIter>

Converts self into a non-empty iterator or returns None if the iterator is empty.

Source§

type Item = <T as IntoIterator>::Item

The type of the elements being iterated over.
Source§

type IntoIter = NonEmptyIterAdapter<Peekable<<T as IntoIterator>::IntoIter>>

Which kind of NonEmptyIterator are we turning this into?
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, 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.
Source§

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