Struct dialectic::backend::Choice[][src]

#[repr(transparent)]pub struct Choice<const N: usize> { /* fields omitted */ }

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 Choices 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]

impl<'de, const N: usize> Deserialize<'de> for Choice<N>[src]

impl<const N: usize> Eq for Choice<N>[src]

impl<const N: usize> Hash for Choice<N>[src]

impl<const N: usize> Ord for Choice<N>[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]

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]

type Error = OutOfBoundsChoiceError

The type returned in the event of a conversion error.

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]

impl<'a, T, S> As<'a, Val, T> for S where
    S: Into<T>, 
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<'a, T> By<'a, Mut> for T where
    T: 'a, 
[src]

type Type = &'a mut T

The type of Self when called by Convention.

impl<'a, T> By<'a, Ref> for T where
    T: 'a, 
[src]

type Type = &'a T

The type of Self when called by Convention.

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]

impl<'a, T> Convert<'a, Mut, Ref> for T where
    T: 'a, 
[src]

impl<'a, T> Convert<'a, Mut, Val> for T where
    T: 'a + Clone
[src]

impl<'a, T> Convert<'a, Ref, Ref> for T where
    T: 'a, 
[src]

impl<'a, T> Convert<'a, Ref, Val> for T where
    T: 'a + Clone
[src]

impl<'a, T> Convert<'a, Val, Val> for T[src]

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

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.