Struct 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: LocalSensors, nbr_sensor: NbrSensors, exports: Exports, ) -> 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) -> &Exports

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) -> &LocalSensors

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) -> &NbrSensors

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 Freeze for Context

§

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