Struct rf_core::context::Context

source ·
pub struct Context { /* private fields */ }
Expand description

Context implementation

  • selfId The ID of the device that this context is for.

  • local_sensor The values perceived by the local sensors of the device.

  • nbr_sensor The values perceived by the sensors for each neighbor of the device.

  • exports All the export that are available to the device.

Implementations§

source§

impl Context

source

pub fn new( self_id: i32, local_sensor: HashMap<SensorId, Rc<Box<dyn Any>>>, nbr_sensor: HashMap<SensorId, HashMap<i32, Rc<Box<dyn Any>>>>, exports: HashMap<i32, Export> ) -> Self

Create new Context of a device from the given parameters.

Arguments
  • self_id - the ID of the device

  • local_sensor - The values perceived by the local sensors of the device.

  • nbr_sensor - The values perceived by the sensors for each neighbor of the device.

  • exports - All the export that are available to the device.

Returns

The new Context.

source

pub fn self_id(&self) -> &i32

source

pub fn exports(&self) -> &HashMap<i32, Export>

source

pub fn put_export(&mut self, id: i32, data: Export)

Add an export of a device to the context.

Arguments
  • id the ID of the device
  • data the export of the device
source

pub fn read_export_value<A: 'static + FromStr + Clone>( &self, id: &i32, path: &Path ) -> Result<A>

Read the value corresponding to the given path from the export of a device.

Arguments
  • id the ID of the device
  • path the path to the value
Generic Parameters
  • A the type of the value to return. It must have a 'static lifetime.
Returns

An Option of the value if it exists

source

pub fn local_sensors(&self) -> &HashMap<SensorId, Rc<Box<dyn Any>>>

source

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

Get the value of the given sensor.

Arguments
  • name the name of the sensor
Generic Parameters
  • A the type of the value to return. It must have a 'static lifetime.
Returns

An Option of the value if it exists

source

pub fn nbr_sensors(&self) -> &HashMap<SensorId, HashMap<i32, Rc<Box<dyn Any>>>>

source

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

Get the value of the given sensor for the given neighbor.

Arguments
  • sensor_id the neighbor sensor id
  • nbr_id the neighbor id
Generic Parameters
  • A the type of the value to return. It must have a 'static lifetime.
Returns

An Option of the value if it exists

Trait Implementations§

source§

impl Clone for Context

source§

fn clone(&self) -> Context

Returns a copy 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 Context

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Context

§

impl !Send for Context

§

impl !Sync for Context

§

impl Unpin for Context

§

impl !UnwindSafe for Context

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, 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,

§

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>,

§

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>,

§

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.