Struct Simulation

Source
pub struct Simulation<'a, O, M> { /* private fields */ }
Available on crate feature sim only.
Expand description

Simulates MPC protocol with parties defined as state machines

Implementations§

Source§

impl<'a, O, M> Simulation<'a, O, M>
where M: Clone + 'static,

Source

pub fn empty() -> Self

Creates empty simulation containing no parties

New parties can be added via .add_party()

Source

pub fn with_capacity(n: u16) -> Self

Constructs empty simulation containing no parties, with allocated memory that can fit up to n parties without re-allocations

Source

pub fn from_async_fn<F>(n: u16, init: impl FnMut(u16, MpcParty<M>) -> F) -> Self
where F: Future<Output = O> + 'a,

Constructs a simulation with n parties from async function that defines the protocol

Each party has index 0 <= i < n and instantiated via provided init function

Async function will be converted into a state machine. Because of that, it cannot await on any futures that aren’t provided by MpcParty (that is given as an argument to this function).

Source

pub fn from_fn<S>(n: u16, init: impl FnMut(u16) -> S) -> Self
where S: StateMachine<Output = O, Msg = M> + 'a,

Construct a simulation with n parties from init function that constructs state machine for each party

Each party has index 0 <= i < n and instantiated via provided init function

Source

pub fn add_party(&mut self, party: impl StateMachine<Output = O, Msg = M> + 'a)

Adds new party into the protocol

New party will be assigned index i = n - 1 where n is amount of parties in the simulation after this party was added.

Source

pub fn add_async_party<F>(&mut self, party: impl FnOnce(MpcParty<M>) -> F)
where F: Future<Output = O> + 'a,

Adds new party, defined as an async function, into the protocol

New party will be assigned index i = n - 1 where n is amount of parties in the simulation after this party was added.

Async function will be converted into a state machine. Because of that, it cannot await on any futures that aren’t provided by MpcParty (that is given as an argument to this function).

Source

pub fn parties_amount(&self) -> usize

Returns amount of parties in the simulation

Source

pub fn run(self) -> Result<SimResult<O>, SimError>

Carries out the simulation

Auto Trait Implementations§

§

impl<'a, O, M> Freeze for Simulation<'a, O, M>

§

impl<'a, O, M> !RefUnwindSafe for Simulation<'a, O, M>

§

impl<'a, O, M> !Send for Simulation<'a, O, M>

§

impl<'a, O, M> !Sync for Simulation<'a, O, M>

§

impl<'a, O, M> Unpin for Simulation<'a, O, M>
where O: Unpin,

§

impl<'a, O, M> !UnwindSafe for Simulation<'a, O, M>

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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, 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> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more