Struct RoundVM

Source
pub struct RoundVM { /* private fields */ }
Expand description

A Round correspond to a local computation in a device. Create the context, evaluate the aggregate program and share the exports to the neighborhood.

  • context - The context of the current round.

  • status - The status of the current round.

  • export_stack - The stack of exports of the current round.

Implementations§

Source§

impl RoundVM

Source

pub fn new(context: Context) -> Self

Create a new RoundVM

§Arguments
  • context - The context of the current round.
§Returns

A RoundVM instance.

Source

pub fn export_data(&mut self) -> &mut Export

Get the first export of the stack.

§Returns

The first export of the stack, of type &mut Export.

Source

pub fn self_id(&self) -> &i32

§Returns

The id of the device, of type i32.

Source

pub fn register_root<A: 'static + Clone>(&mut self, v: A)

Register the given value for the root path.

§Arguments
  • v - The value to register.
§Generic Parameters
  • A - The type of value. It must implement the Copy trait and have a 'static lifetime.
Source

pub fn neighbor(&self) -> &Option<i32>

If the computation is folding on a neighbor, return the id of the neighbor

§Returns

An &Option<i32> containing the id of the neighbor, if present

Source

pub fn index(&self) -> i32

§Returns

The index of the current computation.

Source

pub fn previous_round_val<A: 'static + Clone + FromStr>(&self) -> Result<A>

Obtain the value of the previous round for the current device and the current path.

§Generic Parameters
  • A - The type of value. It must implement the Clone trait and have a 'static lifetime.
§Returns

An Option containing the value of the current path for the current device, if present.

Source

pub fn neighbor_val<A: 'static + Clone + FromStr>(&self) -> Result<A>

Obtain the value of the current path for the current neighbor

§Generic Parameters
  • A - The type of value. It must implement the Clone trait and have a 'static lifetime.
§Returns

A Result containing the value of the current path for the current neighbor, if present.

Source

pub fn local_sense<A: 'static>(&self, sensor_id: &SensorId) -> Option<&A>

Obtain the local value of a given sensor.

§Arguments
    • sensor_id - The id of the sensor.
§Generic Parameters
  • A - The type of value returned by the sensor. It must have a 'static lifetime.
§Returns

An Option containing the local value of the given sensor, if present.

Source

pub fn nbr_sense<A: 'static>(&self, sensor_id: &SensorId) -> Option<&A>

Obtain the value of a given sensor for the current neighbor.

§Arguments
  • sensor_id - The id of the sensor.
§Generic Parameters
  • A - The type of value returned by the sensor. It must have a 'static lifetime.
§Returns

An Option containing the value of the given sensor for the current neighbor, if present.

Source

pub fn locally<A: Clone + 'static + FromStr, F>(&mut self, expr: F) -> A
where F: Fn(&mut RoundVM) -> A,

Evaluates the given expression locally and return the result.

§Arguments
  • expr The expression to evaluate, which takes a RoundVM as argument and returns a tuple of RoundVM and A.
§Generic Parameters
  • A - The type of value returned by the expression.
  • F - The type of the closure, which must be a mutable closure that takes a RoundVM as argument and returns a tuple of RoundVM and A.
§Returns

The result of the closure expr.

Source

pub fn folded_eval<A: Clone + 'static, F>( &mut self, expr: F, id: i32, ) -> Option<A>
where F: Fn(&mut RoundVM) -> A,

Perform a folded evaluation of the given expression in the given neighbor and return the result.

§Arguments
  • expr - The expression to evaluate, which takes a RoundVM as argument and returns a tuple of RoundVM and A.
  • id - The id of the neighbor. It is of type i32.
§Generic Parameters
  • A - The type of value returned by the expression.
  • F - The type of the expression, which must be a closure that takes a RoundVM as argument and returns a tuple of RoundVM and A.
§Returns

An Option containing the result of the expression.

Source

pub fn nest<A: Clone + 'static + FromStr, F>( &mut self, slot: Slot, write: bool, inc: bool, expr: F, ) -> A
where F: Fn(&mut RoundVM) -> A,

Evaluate the given expression while also writing on the Export stack.

§Arguments
  • slot - The slot to write in the current Path.
  • write - A boolean indicating whether to write the result of the expression on the Export stack.
  • inc - A boolean indicating whether to increment the index of the current [VMStatus].
  • expr - The expression to evaluate, which takes a RoundVM as argument and returns a tuple of RoundVM and A.
§Generic Parameters
  • A - The type of value returned by the expression.
  • F - The type of the expression, which must be a closure that takes a RoundVM as argument and returns a tuple of RoundVM and A.
§Returns

A tuple of RoundVM and A.

Source

pub fn aligned_neighbours<A: 'static + FromStr + Clone>(&self) -> Vec<i32>

Get a vector of aligned neighbor identifiers.

§Returns

A vector of aligned neighbor identifiers.

Source

pub fn isolate<A, F>(&mut self, expr: F) -> A
where F: Fn(&mut RoundVM) -> A,

Isolate the current device and evaluate the given expression

§Arguments
  • expr - The closure to execute, which takes a RoundVM as argument and returns a tuple of RoundVM and A.
§Generic Parameters
  • A - The type of value returned by the closure.
  • F - The type of the closure, which must be a mutable closure takes a RoundVM as argument and returns a tuple of RoundVM and A.
§Returns

The result of the closure expr.

Source

pub fn unless_folding_on_others(&self) -> bool

Check if folding is not being performed on neighbor.

§Returns
  • true if folding is being performed on self.
  • false if folding is being performed on neighbor.
Source

pub fn only_when_folding_on_self(&self) -> bool

Check if folding is being performed on self.

§Returns
  • true if folding is being performed on self.
  • false otherwise.
Source

pub fn context(&self) -> &Context

Source

pub fn new_export_stack(&mut self)

Create a new export stack with an empty Export. This function needs to be called when a new RoundVM is created.

Trait Implementations§

Source§

impl Clone for RoundVM

Source§

fn clone(&self) -> RoundVM

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for RoundVM

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for RoundVM

§

impl !RefUnwindSafe for RoundVM

§

impl !Send for RoundVM

§

impl !Sync for RoundVM

§

impl Unpin for RoundVM

§

impl !UnwindSafe for RoundVM

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.