Struct schroedinger_box::SchroedingerBox
[−]
[src]
pub struct SchroedingerBox<Cat> { /* fields omitted */ }
A box that contains many values, but collapses into one when opened (read from) for the first time.
Example
let cat_is_alive = SchroedingerBox::new(vec![true, false]); // Here the cat is both dead and alive, but when we observe it... let state = *cat_is_alive; // ...it collapses into one of the possible states with equal probability. assert_eq!(state, *cat_is_alive);
Methods
impl<Cat> SchroedingerBox<Cat>
[src]
fn new(states: Vec<Cat>) -> SchroedingerBox<Cat>
Creates a new SchroedingerBox
from a set of states.
When the box is first opened, the contents’ superposition will collapse into one of the given states with equal probability.
Panic
Panics if states.len() == 0
.
fn from_probabilities(states: Vec<(u64, Cat)>) -> SchroedingerBox<Cat>
Creates a new SchroedingerBox
from a set of states, each with a probability.
When the box is first opened, the contents’ superposition will collapse into one of the given states with each state’s probability determined by the probabilities given.
The probablity for a state is represented by a ratio of an integer to the total sum of the
probabilities; e.g., a set of states and probabilities [(1, true), (5, false)]
would be
false
five sixths of the time and true
one sixth of the time.
Panic
Panics if states.len() == 0
.
fn into_inner(self) -> Cat
Moves the value inside a SchroedingerBox
out, consuming the box and collapsing any
superposition into a definite state if needed.
Trait Implementations
impl<Cat> Deref for SchroedingerBox<Cat>
[src]
type Target = Cat
The resulting type after dereferencing
fn deref(&self) -> &Cat
Obtains a reference to the value inside a SchroedingerBox
, collapsing any superposition
into a definite state if needed.
impl<Cat> DerefMut for SchroedingerBox<Cat>
[src]
fn deref_mut(&mut self) -> &mut Cat
Obtains a mutable reference to the value inside a SchroedingerBox
, collapsing any
superposition into a definite state if needed.
impl<Cat> Debug for SchroedingerBox<Cat> where
Cat: Debug,
[src]
Cat: Debug,
impl<Cat> Display for SchroedingerBox<Cat> where
Cat: Display,
[src]
Cat: Display,
impl<Cat> PartialEq for SchroedingerBox<Cat> where
Cat: PartialEq,
[src]
Cat: PartialEq,
fn eq(&self, other: &SchroedingerBox<Cat>) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &Rhs) -> bool
1.0.0
This method tests for !=
.
impl<Cat> Eq for SchroedingerBox<Cat> where
Cat: Eq,
[src]
Cat: Eq,
impl<Cat> PartialOrd for SchroedingerBox<Cat> where
Cat: PartialOrd,
[src]
Cat: PartialOrd,
fn partial_cmp(&self, other: &SchroedingerBox<Cat>) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
fn lt(&self, other: &Rhs) -> bool
1.0.0
This method tests less than (for self
and other
) and is used by the <
operator. Read more
fn le(&self, other: &Rhs) -> bool
1.0.0
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
fn gt(&self, other: &Rhs) -> bool
1.0.0
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
fn ge(&self, other: &Rhs) -> bool
1.0.0
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
impl<Cat> Ord for SchroedingerBox<Cat> where
Cat: Ord,
[src]
Cat: Ord,
fn cmp(&self, other: &SchroedingerBox<Cat>) -> Ordering
This method returns an Ordering
between self
and other
. Read more
impl<Cat> Default for SchroedingerBox<Cat> where
Cat: Default,
[src]
Cat: Default,
fn default() -> SchroedingerBox<Cat>
Returns the "default value" for a type. Read more
impl<Cat> Clone for SchroedingerBox<Cat> where
Cat: Clone,
[src]
Cat: Clone,
fn clone(&self) -> SchroedingerBox<Cat>
Clones a SchroedingerBox
.
This collapses any superposition into a single state.
fn clone_from(&mut self, source: &Self)
1.0.0
Performs copy-assignment from source
. Read more
impl<Cat> Hash for SchroedingerBox<Cat> where
Cat: Hash,
[src]
Cat: Hash,