pub struct Context { /* private fields */ }Expand description
Context implementation
-
selfIdThe ID of the device that this context is for. -
local_sensorThe values perceived by the local sensors of the device. -
nbr_sensorThe values perceived by the sensors for each neighbor of the device. -
exportsAll the export that are available to the device.
Implementations§
source§impl Context
impl Context
sourcepub fn new(
self_id: i32,
local_sensor: LocalSensors,
nbr_sensor: NbrSensors,
exports: Exports
) -> Self
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.
pub fn self_id(&self) -> &i32
pub fn exports(&self) -> &Exports
sourcepub fn put_export(&mut self, id: i32, data: Export)
pub fn put_export(&mut self, id: i32, data: Export)
Add an export of a device to the context.
Arguments
idthe ID of the devicedatathe export of the device
sourcepub fn read_export_value<A: 'static + FromStr + Clone>(
&self,
id: &i32,
path: &Path
) -> Result<A>
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
idthe ID of the devicepaththe path to the value
Generic Parameters
Athe type of the value to return. It must have a'staticlifetime.
Returns
An Option of the value if it exists
pub fn local_sensors(&self) -> &LocalSensors
sourcepub fn local_sense<A: 'static>(&self, local_sensor_id: &SensorId) -> Option<&A>
pub fn local_sense<A: 'static>(&self, local_sensor_id: &SensorId) -> Option<&A>
Get the value of the given sensor.
Arguments
namethe name of the sensor
Generic Parameters
Athe type of the value to return. It must have a'staticlifetime.
Returns
An Option of the value if it exists
pub fn nbr_sensors(&self) -> &NbrSensors
sourcepub fn nbr_sense<A: 'static>(
&self,
sensor_id: &SensorId,
nbr_id: &i32
) -> Option<&A>
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_idthe neighbor sensor idnbr_idthe neighbor id
Generic Parameters
Athe type of the value to return. It must have a'staticlifetime.
Returns
An Option of the value if it exists