pub struct Discriminant<T>(/* private fields */);crypto and std only.Expand description
Opaque type representing the discriminant of an enum.
See the discriminant function in this module for more information.
Implementations§
Source§impl<T> Discriminant<T>
impl<T> Discriminant<T>
Sourcepub const fn ord(&self) -> DiscriminantOrd<T>
🔬This is a nightly-only experimental API. (discriminant_ord)
pub const fn ord(&self) -> DiscriminantOrd<T>
discriminant_ord)Returns an ordering key for this Discriminant that has an unstable
implementation with regards to semantic versioning. This is not to be
confused with an [“unstable sort”].
Because all types have a publicly accessible Discriminant, regardless
of whether the order of said type is a part of its stability guarantees,
the exact ordering of the returned DiscriminantOrd cannot be relied on
for stability across crate boundaries. This is similar to the stability
of the size of a type as returned by size_of.
Discriminants from enums will be ordered based on the source declaration
and assigned values of their variants, consistent with derived implementations
of PartialOrd and Ord. All other kinds of discriminants have an
unspecified ordering, but will typically be trivially ordered as equivalent.
Users of this function should instead rely on the Ord implementation
of T wherever possible.
§Examples
#![feature(discriminant_ord)]
use std::cmp::Ordering;
use std::mem::discriminant;
enum Foo { A(i32), B(i32) }
// Equivalent variants will compare equal regardless of contained data
assert_matches!(
discriminant(&Foo::A(1)).ord().cmp(&discriminant(&Foo::A(2)).ord()),
Ordering::Equal,
);
// Non-equivalent variants will compare not-equal
assert_matches!(
discriminant(&Foo::A(1)).ord().cmp(&discriminant(&Foo::B(1)).ord()),
Ordering::Less | Ordering::Greater,
);Upstream libraries and the compiler are free to change the exact ordering of discriminants unless they are explicitly documented as stable. The below may break at any time:
// Foo::A is declared before Foo::B, but that ordering is not stable
assert_matches!(
discriminant(&Foo::A(0)).ord().cmp(&discriminant(&Foo::B(0)).ord()),
Ordering::Less,
);Trait Implementations§
1.21.0 · Source§impl<T> Clone for Discriminant<T>
impl<T> Clone for Discriminant<T>
Source§fn clone(&self) -> Discriminant<T>
fn clone(&self) -> Discriminant<T>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl<T> Copy for Discriminant<T>
1.21.0 · Source§impl<T> Debug for Discriminant<T>
impl<T> Debug for Discriminant<T>
impl<T> Eq for Discriminant<T>
1.21.0 · Source§impl<T> Hash for Discriminant<T>
impl<T> Hash for Discriminant<T>
Auto Trait Implementations§
impl<T> Forget for Discriminant<T>
impl<T> Freeze for Discriminant<T>
impl<T> Move for Discriminant<T>
impl<T> RefUnwindSafe for Discriminant<T>
impl<T> Send for Discriminant<T>
impl<T> Sync for Discriminant<T>
impl<T> Unpin for Discriminant<T>
impl<T> UnsafeUnpin for Discriminant<T>
impl<T> UnwindSafe for Discriminant<T>
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a rama_grpc::Request§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
§fn and<P, B, E>(self, other: P) -> And<T, P>
fn and<P, B, E>(self, other: P) -> And<T, P>
Policy that returns Action::Follow only if self and other return
Action::Follow. Read more