Struct rustot::shadows::PersistedShadow
source · pub struct PersistedShadow<'a, S: ShadowState + DeserializeOwned, M: Mqtt, D: ShadowDAO<S>> { /* private fields */ }
Implementations
sourceimpl<'a, S, M, D> PersistedShadow<'a, S, M, D>where
S: ShadowState + DeserializeOwned,
M: Mqtt,
D: ShadowDAO<S>,
impl<'a, S, M, D> PersistedShadow<'a, S, M, D>where
S: ShadowState + DeserializeOwned,
M: Mqtt,
D: ShadowDAO<S>,
sourcepub fn new(
initial_state: S,
mqtt: &'a M,
dao: D,
auto_subscribe: bool
) -> Result<Self, Error>
pub fn new(
initial_state: S,
mqtt: &'a M,
dao: D,
auto_subscribe: bool
) -> Result<Self, Error>
Instantiate a new shadow that will be automatically persisted to NVM
based on the passed DAO
.
sourcepub fn subscribe(&self) -> Result<(), Error>
pub fn subscribe(&self) -> Result<(), Error>
Subscribes to all the topics required for keeping a shadow in sync
sourcepub fn unsubscribe(&self) -> Result<(), Error>
pub fn unsubscribe(&self) -> Result<(), Error>
Unsubscribes from all the topics required for keeping a shadow in sync
sourcepub fn should_handle_topic(&mut self, topic: &str) -> bool
pub fn should_handle_topic(&mut self, topic: &str) -> bool
Helper function to check whether a topic name is relevant for this particular shadow.
sourcepub fn handle_message(
&mut self,
topic: &str,
payload: &[u8]
) -> Result<(&S, Option<S::PatchState>), Error>
pub fn handle_message(
&mut self,
topic: &str,
payload: &[u8]
) -> Result<(&S, Option<S::PatchState>), Error>
Handle incomming publish messages from the cloud on any topics relevant for this particular shadow.
This function needs to be fed all relevant incoming MQTT payloads in order for the shadow manager to work.
sourcepub fn get_shadow(&self) -> Result<(), Error>
pub fn get_shadow(&self) -> Result<(), Error>
Initiate a GetShadow
request, updating the local state from the cloud.
sourcepub fn report_shadow(&mut self) -> Result<(), Error>
pub fn report_shadow(&mut self) -> Result<(), Error>
Initiate an UpdateShadow
request, reporting the local state to the cloud.
sourcepub fn update<F: FnOnce(&S, &mut S::PatchState)>(
&mut self,
f: F
) -> Result<(), Error>
pub fn update<F: FnOnce(&S, &mut S::PatchState)>(
&mut self,
f: F
) -> Result<(), Error>
Update the state of the shadow.
This function will update the desired state of the shadow in the cloud, and depending on whether the state update is rejected or accepted, it will automatically update the local version after response