pub fn register(
        &mut self,
        topic: &str,
        handler: Handler<Context, Stack::Error, MESSAGE_SIZE>,
    ) -> Result<bool, Error<Stack::Error>> {
        let added = self
            .machine
            .context_mut()
            .handlers
            .insert(
                String::from(topic),
                HandlerMeta {
                    handler,
                    republished: false,
                },
            )
            .map(|prev| prev.is_none())
            .map_err(|_| Error::RegisterFailed)?;

        // Force a republish of the newly-registered command after adding it. We ignore failures of
        // event processing here since that would imply we are adding the handler before we've even
        // gotten to the republish state.
        self.machine
            .process_event(sm::Events::PendingRepublish)
            .ok();

        Ok(added)
    }
/// Associate a handler to be called when receiving the specified request.
///
/// # Args
/// * `topic` - The request to register the provided handler with.
/// * `handler` - The handler function to be called when the request occurs.
Associate a handler to be called when receiving the specified request.
Associate a handler to be called when receiving the specified request .
pub fn register(
        &mut self,
        topic: &str,
        handler: Handler<Context, Stack::Error, MESSAGE_SIZE>,
    ) -> Result<bool, Error<Stack::Error>> {
        let added = self
            .machine
            .context_mut()
            .handlers
            .insert(
                String::from(topic),
                HandlerMeta {
                    handler,
                    republished: false,
                },
            )
            .map(|prev| prev.is_none())
            .map_err(|_| Error::RegisterFailed)?;
        // Force a republish of the newly-registered command after adding it. We ignore failures of
        // event processing here since that would imply we are adding the handler before we've even
        // gotten to the republish state.
        self.machine
            .process_event(sm::Events::PendingRepublish)
            .ok();
        Ok(added)
    }
pub fn register ( & mut self , topic : & str , handler : Handler < Context , Stack :: Error , MESSAGE_SIZE > , ) -> Result < bool , Error < Stack :: Error > > { let added = self . machine . context_mut ( ) . handlers . insert ( String :: from ( topic ) , HandlerMeta { handler , republished : false , } , ) . map ( | prev | prev . is_none ( ) ) . map_err ( | _ | Error :: RegisterFailed ) ? ; // Force a republish of the newly-registered command after adding it. We ignore failures of // event processing here since that would imply we are adding the handler before we've even // gotten to the republish state. self . machine . process_event ( sm :: Events :: PendingRepublish ) . ok ( ) ; Ok ( added ) }
Associate a handler to be called when receiving the specified request.
Associate a handler to be called when receiving the specified request .
&mut self
topic
&str
handler
Handler<Context, Stack::Error, MESSAGE_SIZE>
&mut self
topic
&str
handler
Handler<Context, Stack::Error, MESSAGE_SIZE>
args
`topic` - The request to register the provided handler with.
`handler` - The handler function to be called when the request occurs.
` topic ` - The request to register the provided handler with . ` handler ` - The handler function to be called when the request occurs .