Struct dialectic::backend::Choice [−][src]
A Choice
represents a selection between several protocols offered by offer!
.
It wraps an ordinary non-negative number, with the guarantee that it is strictly less than the
type level number N
.
Unless you are implementing a backend
, you do not need to interact with
Choice
s directly. However, all backends must implement Transmit<Choice<N>, Val>
and Receive<Choice<N>>
for all N
in order to support the Choose
and Offer
constructs.
Examples
It’s possible to construct a Choice
from all u8
strictly less than its type parameter N
:
use std::convert::TryInto; use dialectic::backend::Choice; let zero: Choice<3> = 0_u8.try_into()?; let one: Choice<3> = 1_u8.try_into()?; let two: Choice<3> = 2_u8.try_into()?; assert_eq!(zero, 0_u8); assert_eq!(one, 1_u8); assert_eq!(two, 2_u8);
But we cannot construct a Choice
from a u8
equal to or greater than its type parameter
N
:
let attempted_three: Result<Choice<3>, _> = 3_u8.try_into(); let attempted_four: Result<Choice<3>, _> = 4_u8.try_into(); assert!(attempted_three.is_err()); assert!(attempted_four.is_err());
Note that this means Choice<0>
is unrepresentable, because you cannot choose something from a
set of zero things:
for i in 0 ..= u8::MAX { let attempt: Result<Choice<0>, _> = i.try_into(); assert!(attempt.is_err()); }
Trait Implementations
impl<const N: usize> Clone for Choice<N>
[src]
impl<const N: usize> Copy for Choice<N>
[src]
impl<const N: usize> Debug for Choice<N>
[src]
impl<M: Unary, const N: usize> Default for Choice<N> where
Number<N>: ToUnary<AsUnary = S<M>>,
[src]
Number<N>: ToUnary<AsUnary = S<M>>,
impl<'de, const N: usize> Deserialize<'de> for Choice<N>
[src]
fn deserialize<D>(deserializer: D) -> Result<Choice<N>, D::Error> where
D: Deserializer<'de>,
[src]
D: Deserializer<'de>,
impl<const N: usize> Eq for Choice<N>
[src]
impl<const N: usize> Hash for Choice<N>
[src]
fn hash<__H: Hasher>(&self, state: &mut __H)
[src]
pub fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl<const N: usize> Ord for Choice<N>
[src]
fn cmp(&self, other: &Choice<N>) -> Ordering
[src]
#[must_use]pub fn max(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn min(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn clamp(self, min: Self, max: Self) -> Self
1.50.0[src]
impl<const N: usize> PartialEq<Choice<N>> for Choice<N>
[src]
impl<const N: usize> PartialEq<u8> for Choice<N>
[src]
impl<const N: usize> PartialOrd<Choice<N>> for Choice<N>
[src]
fn partial_cmp(&self, other: &Choice<N>) -> Option<Ordering>
[src]
#[must_use]pub fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn le(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
impl<const N: usize> Serialize for Choice<N>
[src]
impl<const N: usize> StructuralEq for Choice<N>
[src]
impl<const N: usize> StructuralPartialEq for Choice<N>
[src]
impl<const N: usize> TryFrom<u8> for Choice<N>
[src]
Auto Trait Implementations
impl<const N: usize> RefUnwindSafe for Choice<N>
impl<const N: usize> Send for Choice<N>
impl<const N: usize> Sync for Choice<N>
impl<const N: usize> Unpin for Choice<N>
impl<const N: usize> UnwindSafe for Choice<N>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<'a, T, S> As<'a, Val, T> for S where
S: Into<T>,
[src]
S: Into<T>,
pub fn as_convention(this: S) -> T
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<'a, T> By<'a, Mut> for T where
T: 'a,
[src]
T: 'a,
impl<'a, T> By<'a, Ref> for T where
T: 'a,
[src]
T: 'a,
impl<'a, T> By<'a, Val> for T
[src]
type Type = T
The type of Self
when called by Convention
.
impl<'a, T> Convert<'a, Mut, Mut> for T where
T: 'a,
[src]
T: 'a,
impl<'a, T> Convert<'a, Mut, Ref> for T where
T: 'a,
[src]
T: 'a,
impl<'a, T> Convert<'a, Mut, Val> for T where
T: 'a + Clone,
[src]
T: 'a + Clone,
impl<'a, T> Convert<'a, Ref, Ref> for T where
T: 'a,
[src]
T: 'a,
impl<'a, T> Convert<'a, Ref, Val> for T where
T: 'a + Clone,
[src]
T: 'a + Clone,
impl<'a, T> Convert<'a, Val, Val> for T
[src]
impl<T> DeserializeOwned for T where
T: for<'de> Deserialize<'de>,
[src]
T: for<'de> Deserialize<'de>,
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,