Struct miniconf::MqttClient
source · [−]pub struct MqttClient<Settings, Stack, Clock, const MESSAGE_SIZE: usize> where
Settings: Miniconf + Clone,
Stack: TcpClientStack,
Clock: Clock, { /* private fields */ }Expand description
MQTT settings interface.
Implementations
sourceimpl<Settings, Stack, Clock, const MESSAGE_SIZE: usize> MqttClient<Settings, Stack, Clock, MESSAGE_SIZE> where
Settings: Miniconf + Clone,
Stack: TcpClientStack,
Clock: Clock + Clone,
impl<Settings, Stack, Clock, const MESSAGE_SIZE: usize> MqttClient<Settings, Stack, Clock, MESSAGE_SIZE> where
Settings: Miniconf + Clone,
Stack: TcpClientStack,
Clock: Clock + Clone,
sourcepub fn new(
stack: Stack,
client_id: &str,
prefix: &str,
broker: IpAddr,
clock: Clock,
settings: Settings
) -> Result<Self, Error<Stack::Error>>
pub fn new(
stack: Stack,
client_id: &str,
prefix: &str,
broker: IpAddr,
clock: Clock,
settings: Settings
) -> Result<Self, Error<Stack::Error>>
Construct a new MQTT settings interface.
Args
stack- The network stack to use for communication.client_id- The ID of the MQTT client. May be an empty string for auto-assigning.prefix- The MQTT device prefix to use for this device.broker- The IP address of the MQTT broker to use.clock- The clock for managing the MQTT connection.settings- The initial settings values.
sourcepub fn handled_update<F, E>(
&mut self,
handler: F
) -> Result<bool, Error<Stack::Error>> where
F: FnMut(&str, &mut Settings, &Settings) -> Result<(), E>,
E: AsRef<str>,
pub fn handled_update<F, E>(
&mut self,
handler: F
) -> Result<bool, Error<Stack::Error>> where
F: FnMut(&str, &mut Settings, &Settings) -> Result<(), E>,
E: AsRef<str>,
Update the MQTT interface and service the network. Pass any settings changes to the handler supplied.
Args
handler- A closure called with updated settings that can be used to apply current settings or validate the configuration. Arguments are (path, old_settings, new_settings).
Example
#[derive(miniconf::Miniconf, Clone)]
struct Settings {
threshold: u32,
}
// let mut client = miniconf::MqttClient::new(...);
client.handled_update(|path, old_settings, new_settings| {
if new_settings.threshold > 5 {
return Err("Requested threshold too high");
}
*old_settings = new_settings.clone();
Ok(())
}).unwrap();Returns
True if the settings changed. False otherwise.
sourcepub fn update(&mut self) -> Result<bool, Error<Stack::Error>>
pub fn update(&mut self) -> Result<bool, Error<Stack::Error>>
Update the settings from the network stack without any specific handling.
Returns
True if the settings changed. False otherwise
sourcepub fn force_republish(&mut self)
pub fn force_republish(&mut self)
Force republication of the current settings.
Note
This is intended to be used if modification of a setting had side effects that affected another setting.
Auto Trait Implementations
impl<Settings, Stack, Clock, const MESSAGE_SIZE: usize> !RefUnwindSafe for MqttClient<Settings, Stack, Clock, MESSAGE_SIZE>
impl<Settings, Stack, Clock, const MESSAGE_SIZE: usize> Send for MqttClient<Settings, Stack, Clock, MESSAGE_SIZE> where
Clock: Send,
Settings: Send,
Stack: Send,
<Clock as Clock>::T: Send,
<Stack as TcpClientStack>::TcpSocket: Send,
impl<Settings, Stack, Clock, const MESSAGE_SIZE: usize> !Sync for MqttClient<Settings, Stack, Clock, MESSAGE_SIZE>
impl<Settings, Stack, Clock, const MESSAGE_SIZE: usize> Unpin for MqttClient<Settings, Stack, Clock, MESSAGE_SIZE> where
Clock: Unpin,
Settings: Unpin,
Stack: Unpin,
<Clock as Clock>::T: Unpin,
<Stack as TcpClientStack>::TcpSocket: Unpin,
impl<Settings, Stack, Clock, const MESSAGE_SIZE: usize> UnwindSafe for MqttClient<Settings, Stack, Clock, MESSAGE_SIZE> where
Clock: UnwindSafe,
Settings: UnwindSafe,
Stack: UnwindSafe,
<Clock as Clock>::T: UnwindSafe,
<Stack as TcpClientStack>::TcpSocket: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more