Skip to main content

UOrd

Struct UOrd 

Source
pub struct UOrd<T, const N: usize> { /* private fields */ }
Expand description

An unordered tuple of items of type T and length N.

UOrd is implemented such that the order of elements on creation does not matter, and the UOrds created from different ordered lists will behave similarly in PartialEq, Ord, or Hash.

UOrd’s implementation maintains a sorted list of values that is not allowed to be mutated. Using interior mutability to mutate elements of a UOrd is a logic error and is not supported. Doing so is very likely to cause strange behavior.

Implementations§

Source§

impl<T, const N: usize> UOrd<T, N>
where T: Ord,

Source

pub fn new(values: [T; N]) -> Self

Create a new UOrd from an array of values.

Source

pub fn contains<Q>(&self, x: &Q) -> bool
where T: Borrow<Q>, Q: Eq + ?Sized,

Tests whether this UOrd contains the given value.

Source

pub fn replace<Q>(&self, from: &Q, to: &T) -> Self
where T: Borrow<Q> + Clone, Q: Eq + ?Sized,

Replaces any occurrence of from with to, creating a new UOrd.

Source

pub fn map<U>(self, f: impl FnMut(T) -> U) -> UOrd<U, N>
where U: Ord,

Applies the function f to each element of this UOrd, returning a new UOrd.

Source

pub fn map_each_ref<U>(&self, f: impl FnMut(&T) -> U) -> UOrd<U, N>
where U: Ord,

Applies the function f to a reference to each element of this UOrd, returning a new UOrd.

Source

pub fn try_map_opt<U>(self, f: impl FnMut(T) -> Option<U>) -> Option<UOrd<U, N>>
where U: Ord,

Available on crate feature alloc only.

Applies a fallible function f to each element of this UOrd, returning a value of type Option<UOrd<U, N>>. The provided function takes a T and must return a value of type Option<U>.

This function is temporary, and will be deprecated when try_trait_v2 is stabilized.

Source

pub fn try_map_res<U, E>( self, f: impl FnMut(T) -> Result<U, E>, ) -> Result<UOrd<U, N>, E>
where U: Ord,

Available on crate feature alloc only.

Applies a fallible function f to each element of this UOrd, returning a value of type Result<UOrd<U, N>, E>. The provided function takes a T and must return a value of type Return<U, E>.

This function is temporary, and will be deprecated when try_trait_v2 is stabilized.

Source

pub fn convert<U>(self) -> UOrd<U, N>
where T: Into<U>, U: Ord,

Converts each element of this UOrd into a given type U based on T’s Into<U> implementation.

Source

pub fn try_convert<U>(self) -> Result<UOrd<U, N>, T::Error>
where T: TryInto<U>, U: Ord,

Available on crate feature alloc only.

Fallibly converts each element of this UOrd into a given type U based on T’s TryInto<U> implementation, alternatively returning error.

Source

pub fn test_all(&self, f: impl FnMut(&T) -> bool) -> bool

Tests if all elements pass the given predicate.

Equivalent to self.iter().all(f).

Source

pub fn test_any(&self, f: impl FnMut(&T) -> bool) -> bool

Tests if any element passes the given predicate.

Equivalent to self.iter().any(f).

Source

pub fn make_proxied<P: Proxy<T>>(self) -> UOrdProxied<T, N, P>

Converts this UOrd into a UOrdProxied by wrapping its contained elements of type T in ProxyWrappers, using the provided Proxy P for comparison and equality.

Source§

impl<T, const N: usize> UOrd<T, N>

Source

pub const fn min(&self) -> &T

Gets the first (smallest) element in the internal list.

§Panics

This function will panic if N == 0.

Source

pub const fn max(&self) -> &T

Gets the last (greatest) element in the internal list.

§Panics

This function will panic if N == 0.

Source

pub fn each_ref(&self) -> UOrd<&T, N>

Borrows each element in this UOrd, returning a UOrd of those references.

Source

pub fn as_ref_array(&self) -> [&T; N]

Borrows each element in this UOrd, returning an array of those references.

Source

pub const fn as_array(&self) -> &[T; N]

Returns an immutable reference to the array of elements, which is sorted.

Source

pub const fn into_array(self) -> [T; N]

Converts this UOrd into its array of elements, which is sorted.

Source

pub fn into_tuple(self) -> <[T; N] as IntoTuple>::Tuple
where [T; N]: IntoTuple,

Converts this UOrd into a tuple of length N similarly to into_array.

Source

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

Creates an iterator over references to each element of this UOrd.

Source§

impl<T, const N: usize, P> UOrd<ProxyWrapper<T, P>, N>
where P: Proxy<T>,

Source

pub fn new_proxied(values: [T; N]) -> Self

Create a new UOrdProxied from an array of values, utilizing a custom Proxy for comparison and equality.

Source

pub fn contains_proxied<Q>(&self, x: &Q) -> bool
where T: Borrow<Q>, Q: ?Sized, for<'q> P: Proxy<&'q Q>,

Tests whether this UOrdProxied contains the given value.

Source

pub fn replace_proxied<Q>(&self, from: &Q, to: &T) -> Self
where T: Borrow<Q> + Clone, Q: ?Sized, for<'q> P: Proxy<&'q Q>,

Replaces any occurrence of from with to, creating a new UOrdProxied.

Source

pub const fn min_proxied(&self) -> &T

Gets the first (smallest) element in the internal list, stripped of its wrappers.

§Panics

This function will panic if N == 0.

Source

pub const fn max_proxied(&self) -> &T

Gets the last (greatest) element in the internal list, stripped of its wrappers.

§Panics

This function will panic if N == 0.

Source

pub fn each_ref_proxied(&self) -> UOrd<&T, N>
where T: Ord,

Borrows each element in this UOrdProxied, returning a UOrd of those references, stripped of their wrappers.

Source

pub fn as_ref_array_proxied(&self) -> [&T; N]

Borrows each element in this UOrdProxied, returning an array of those references, stripped of their wrappers.

Source

pub const fn as_array_proxied(&self) -> &[T; N]

Returns an immutable reference to the array of elements, which is sorted, and has each element stripped of their wrappers.

Source

pub const fn into_array_proxied(self) -> [T; N]

Converts this UOrdProxied into its array of elements, which is sorted, and has each element stripped of their wrappers.

Source

pub fn into_tuple_proxied(self) -> <[T; N] as IntoTuple>::Tuple
where [T; N]: IntoTuple,

Converts this UOrd into a tuple of length N similarly to into_array, and has each element stripped of their wrappers..

Source

pub fn map_proxied<U, R>(self, f: impl FnMut(T) -> U) -> UOrdProxied<U, N, R>
where R: Proxy<U>,

Applies the function f to each element of this UOrdProxied, returning a new UOrdProxied. This function also allows a proxy, R, for the new UOrdProxied to be specified.

Source

pub fn map_each_ref_proxied<U, R>( &self, f: impl FnMut(&T) -> U, ) -> UOrdProxied<U, N, R>
where R: Proxy<U>,

Applies the function f to a reference to each element of this UOrdProxied, returning a new UOrdProxied. This function also allows a proxy, R, for the new UOrdProxied to be specified.

Source

pub fn try_map_proxied_opt<U, R>( self, f: impl FnMut(T) -> Option<U>, ) -> Option<UOrdProxied<U, N, R>>
where R: Proxy<U>,

Available on crate feature alloc only.

Applies a fallible function f to each element of this UOrdProxied, returning a value of type Option<UOrdProxied<U, N, R>>. The provided function takes a T and must return a value of type Option<U>. This function also allows a proxy, R, for the new UOrdProxied to be specified.

This function is temporary, and will be deprecated when try_trait_v2 is stabilized.

Source

pub fn try_map_proxied_res<U, R, E>( self, f: impl FnMut(T) -> Result<U, E>, ) -> Result<UOrdProxied<U, N, R>, E>
where R: Proxy<U>,

Available on crate feature alloc only.

Applies a fallible function f to each element of this UOrdProxied, returning a value of type Result<UOrdProxied<U, N, R>, E>. The provided function takes a T and must return a value of type Return<U, E>. This function also allows a proxy, R, for the new UOrdProxied to be specified.

This function is temporary, and will be deprecated when try_trait_v2 is stabilized.

Source

pub fn convert_proxied<U, R>(self) -> UOrdProxied<U, N, R>
where T: Into<U>, R: Proxy<U>,

Converts each element of this UOrdProxied into a given type U based on T’s Into<U> implementation.

Source

pub fn try_convert_proxied<U, R>(self) -> Result<UOrdProxied<U, N, R>, T::Error>
where T: TryInto<U>, R: Proxy<U>,

Available on crate feature alloc only.

Fallibly converts each element of this UOrdProxied into a given type U based on T’s TryInto<U> implementation, alternatively returning error.

Source

pub fn test_all_proxied(&self, f: impl FnMut(&T) -> bool) -> bool

Tests if all elements pass the given predicate.

Equivalent to self.iter_proxied().all(f).

Source

pub fn test_any_proxied(&self, f: impl FnMut(&T) -> bool) -> bool

Tests if any element passes the given predicate.

Equivalent to self.iter_proxied().any(f).

Source

pub fn make_unproxied(self) -> UOrd<T, N>
where T: Ord,

Converts this UOrdProxied into a UOrd, unwrapping the contained ProxyWrappers, using the default implementation of Ord on T for comparison and equality.

Source

pub fn iter_proxied(&self) -> UOrdProxiedIter<'_, T, N, P>

Creates an iterator over references to each element of this UOrdProxied, stripped of their wrappers.

Source

pub fn into_iter_proxied(self) -> UOrdProxiedIntoIter<T, N, P>

Creates an iterator over each element of this UOrdProxied, stripped of their wrappers.

Source§

impl<T> UOrd<T, 2>
where T: Ord,

Source

pub fn is_distinct(&self) -> bool

Returns true if this pair was distinct (the values in it were not equal to each other) otherwise returns false.

Source

pub fn other<Q>(&self, x: &Q) -> Option<&T>
where T: Borrow<Q>, Q: Eq + ?Sized,

If this unordered pair contains the given value, this function will return the other value. If this unordered pair did not contain the given value, this will return None.

Note that this function does not care about the distinctness of the pair, and will still return the other value, even if it was equal to the input value. If you need this behavior, see UOrd::other_distinct.

Source

pub fn other_distinct<Q>(&self, x: &Q) -> Option<&T>
where T: Borrow<Q>, Q: Eq + ?Sized,

If this unordered pair contains the given value, this function will return the other value. If this unordered pair did not contain the given value, this will return None.

Additionally, this function will return None if the two items in this pair were equal, guaranteeing that the output value is never equal to the input value in the case of an indistinct pair.

Source§

impl<T, P> UOrd<ProxyWrapper<T, P>, 2>
where P: Proxy<T>,

Source

pub fn other_proxied<Q>(&self, x: &Q) -> Option<&T>
where T: Borrow<Q>, Q: ?Sized, for<'q> P: Proxy<&'q Q>,

If this unordered pair contains the given value, this function will return the other value. If this unordered pair did not contain the given value, this will return None.

Note that this function does not care about the distinctness of the pair, and will still return the other value, even if it was equal to the input value. If you need this behavior, see UOrdProxied::other_distinct_proxied.

Source

pub fn other_distinct_proxied<Q>(&self, x: &Q) -> Option<&T>
where T: Borrow<Q>, Q: ?Sized, for<'q> P: Proxy<&'q Q>,

If this unordered pair contains the given value, this function will return the other value. If this unordered pair did not contain the given value, this will return None.

Additionally, this function will return None if the two items in this pair were equal, guaranteeing that the output value is never equal to the input value in the case of an indistinct pair.

Trait Implementations§

Source§

impl<T, const N: usize> Clone for UOrd<T, N>
where T: Clone,

Source§

fn clone(&self) -> Self

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, const N: usize> Debug for UOrd<T, N>

Source§

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

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

impl<'de, T, const N: usize> Deserialize<'de> for UOrd<T, N>
where T: Deserialize<'de> + Ord,

Available on crate feature serde only.
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: Display, const N: usize> Display for UOrd<T, N>

Source§

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

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

impl<T, const N: usize> From<[T; N]> for UOrd<T, N>
where T: Ord,

Source§

fn from(value: [T; N]) -> Self

Converts to this type from the input type.
Source§

impl<T> From<(T,)> for UOrd<T, 1>
where T: Ord,

Source§

fn from(value: (T,)) -> UOrd<T, 1>

Converts to this type from the input type.
Source§

impl<T> From<(T, T)> for UOrd<T, 2>
where T: Ord,

Source§

fn from(value: (T, T)) -> UOrd<T, 2>

Converts to this type from the input type.
Source§

impl<T> From<(T, T, T)> for UOrd<T, 3>
where T: Ord,

Source§

fn from(value: (T, T, T)) -> UOrd<T, 3>

Converts to this type from the input type.
Source§

impl<T> From<(T, T, T, T)> for UOrd<T, 4>
where T: Ord,

Source§

fn from(value: (T, T, T, T)) -> UOrd<T, 4>

Converts to this type from the input type.
Source§

impl<T> From<(T, T, T, T, T)> for UOrd<T, 5>
where T: Ord,

Source§

fn from(value: (T, T, T, T, T)) -> UOrd<T, 5>

Converts to this type from the input type.
Source§

impl<T> From<(T, T, T, T, T, T)> for UOrd<T, 6>
where T: Ord,

Source§

fn from(value: (T, T, T, T, T, T)) -> UOrd<T, 6>

Converts to this type from the input type.
Source§

impl<T> From<(T, T, T, T, T, T, T)> for UOrd<T, 7>
where T: Ord,

Source§

fn from(value: (T, T, T, T, T, T, T)) -> UOrd<T, 7>

Converts to this type from the input type.
Source§

impl<T> From<(T, T, T, T, T, T, T, T)> for UOrd<T, 8>
where T: Ord,

Source§

fn from(value: (T, T, T, T, T, T, T, T)) -> UOrd<T, 8>

Converts to this type from the input type.
Source§

impl<T> From<(T, T, T, T, T, T, T, T, T)> for UOrd<T, 9>
where T: Ord,

Source§

fn from(value: (T, T, T, T, T, T, T, T, T)) -> UOrd<T, 9>

Converts to this type from the input type.
Source§

impl<T> From<(T, T, T, T, T, T, T, T, T, T)> for UOrd<T, 10>
where T: Ord,

Source§

fn from(value: (T, T, T, T, T, T, T, T, T, T)) -> UOrd<T, 10>

Converts to this type from the input type.
Source§

impl<T> From<(T, T, T, T, T, T, T, T, T, T, T)> for UOrd<T, 11>
where T: Ord,

Source§

fn from(value: (T, T, T, T, T, T, T, T, T, T, T)) -> UOrd<T, 11>

Converts to this type from the input type.
Source§

impl<T> From<(T, T, T, T, T, T, T, T, T, T, T, T)> for UOrd<T, 12>
where T: Ord,

Source§

fn from(value: (T, T, T, T, T, T, T, T, T, T, T, T)) -> UOrd<T, 12>

Converts to this type from the input type.
Source§

impl<T> From<UOrd<T, 1>> for (T,)

Source§

fn from(value: UOrd<T, 1>) -> (T,)

Converts to this type from the input type.
Source§

impl<T> From<UOrd<T, 10>> for (T, T, T, T, T, T, T, T, T, T)

Source§

fn from(value: UOrd<T, 10>) -> (T, T, T, T, T, T, T, T, T, T)

Converts to this type from the input type.
Source§

impl<T> From<UOrd<T, 11>> for (T, T, T, T, T, T, T, T, T, T, T)

Source§

fn from(value: UOrd<T, 11>) -> (T, T, T, T, T, T, T, T, T, T, T)

Converts to this type from the input type.
Source§

impl<T> From<UOrd<T, 12>> for (T, T, T, T, T, T, T, T, T, T, T, T)

Source§

fn from(value: UOrd<T, 12>) -> (T, T, T, T, T, T, T, T, T, T, T, T)

Converts to this type from the input type.
Source§

impl<T> From<UOrd<T, 2>> for (T, T)

Source§

fn from(value: UOrd<T, 2>) -> (T, T)

Converts to this type from the input type.
Source§

impl<T> From<UOrd<T, 3>> for (T, T, T)

Source§

fn from(value: UOrd<T, 3>) -> (T, T, T)

Converts to this type from the input type.
Source§

impl<T> From<UOrd<T, 4>> for (T, T, T, T)

Source§

fn from(value: UOrd<T, 4>) -> (T, T, T, T)

Converts to this type from the input type.
Source§

impl<T> From<UOrd<T, 5>> for (T, T, T, T, T)

Source§

fn from(value: UOrd<T, 5>) -> (T, T, T, T, T)

Converts to this type from the input type.
Source§

impl<T> From<UOrd<T, 6>> for (T, T, T, T, T, T)

Source§

fn from(value: UOrd<T, 6>) -> (T, T, T, T, T, T)

Converts to this type from the input type.
Source§

impl<T> From<UOrd<T, 7>> for (T, T, T, T, T, T, T)

Source§

fn from(value: UOrd<T, 7>) -> (T, T, T, T, T, T, T)

Converts to this type from the input type.
Source§

impl<T> From<UOrd<T, 8>> for (T, T, T, T, T, T, T, T)

Source§

fn from(value: UOrd<T, 8>) -> (T, T, T, T, T, T, T, T)

Converts to this type from the input type.
Source§

impl<T> From<UOrd<T, 9>> for (T, T, T, T, T, T, T, T, T)

Source§

fn from(value: UOrd<T, 9>) -> (T, T, T, T, T, T, T, T, T)

Converts to this type from the input type.
Source§

impl<T, const N: usize> From<UOrd<T, N>> for [T; N]

Source§

fn from(value: UOrd<T, N>) -> Self

Converts to this type from the input type.
Source§

impl<T, const N: usize> Hash for UOrd<T, N>
where T: Hash,

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<'a, T, const N: usize> IntoIterator for &'a UOrd<T, N>

Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator over references to each element of this UOrd.

Source§

type Item = &'a T

The type of the elements being iterated over.
Source§

type IntoIter = UOrdIter<'a, T, N>

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

impl<T, const N: usize> IntoIterator for UOrd<T, N>

Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator over each element of this UOrd.

Source§

type Item = T

The type of the elements being iterated over.
Source§

type IntoIter = UOrdIntoIter<T, N>

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

impl<T, const N: usize> Ord for UOrd<T, N>
where T: Ord,

Source§

fn cmp(&self, other: &Self) -> 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, const N: usize> PartialEq for UOrd<T, N>
where T: Ord,

Source§

fn eq(&self, other: &Self) -> 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, const N: usize> PartialOrd for UOrd<T, N>
where T: Ord,

Source§

fn partial_cmp(&self, other: &Self) -> 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, const N: usize> Serialize for UOrd<T, N>
where T: Serialize,

Available on crate feature serde only.
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, const N: usize> Copy for UOrd<T, N>
where T: Copy,

Source§

impl<T, const N: usize> Eq for UOrd<T, N>
where T: Ord,

Auto Trait Implementations§

§

impl<T, const N: usize> Freeze for UOrd<T, N>
where T: Freeze,

§

impl<T, const N: usize> RefUnwindSafe for UOrd<T, N>
where T: RefUnwindSafe,

§

impl<T, const N: usize> Send for UOrd<T, N>
where T: Send,

§

impl<T, const N: usize> Sync for UOrd<T, N>
where T: Sync,

§

impl<T, const N: usize> Unpin for UOrd<T, N>
where T: Unpin,

§

impl<T, const N: usize> UnsafeUnpin for UOrd<T, N>
where T: UnsafeUnpin,

§

impl<T, const N: usize> UnwindSafe for UOrd<T, N>
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<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.
Source§

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