63 lines
1.5 KiB
Rust
63 lines
1.5 KiB
Rust
#![feature(structural_match)]
|
|
|
|
pub use whatlang::Lang;
|
|
|
|
#[cfg(feature = "accounts")]
|
|
pub mod accounts;
|
|
#[cfg(feature = "carts")]
|
|
pub mod carts;
|
|
#[cfg(feature = "emails")]
|
|
pub mod emails;
|
|
pub mod mqtt;
|
|
#[cfg(feature = "orders")]
|
|
pub mod orders;
|
|
#[cfg(feature = "payments")]
|
|
pub mod payments;
|
|
pub mod rpc;
|
|
#[cfg(feature = "search")]
|
|
pub mod search;
|
|
#[cfg(feature = "stocks")]
|
|
pub mod stocks;
|
|
#[cfg(feature = "tokens")]
|
|
pub mod tokens;
|
|
|
|
pub trait DeserializePayload {
|
|
fn deserialize_payload<T: serde::de::DeserializeOwned>(self, bytes: bytes::Bytes) -> Option<T>;
|
|
}
|
|
|
|
#[derive(Clone)]
|
|
pub struct AsyncClient(pub rumqttc::AsyncClient);
|
|
|
|
impl AsyncClient {
|
|
pub(crate) async fn publish<Topic: Into<String>, T: serde::Serialize>(
|
|
&self,
|
|
topic: Topic,
|
|
qos: rumqttc::QoS,
|
|
retain: bool,
|
|
t: T,
|
|
) -> Result<(), rumqttc::ClientError> {
|
|
match bincode::serialize(&t) {
|
|
Ok(v) => {
|
|
let bytes = bytes::Bytes::from(v);
|
|
self.0.publish_bytes(topic, qos, retain, bytes).await
|
|
}
|
|
Err(e) => {
|
|
tracing::error!("{}", e);
|
|
Ok(())
|
|
}
|
|
}
|
|
}
|
|
|
|
pub(crate) async fn publish_or_log<Topic: Into<String>, T: serde::Serialize>(
|
|
&self,
|
|
topic: Topic,
|
|
qos: rumqttc::QoS,
|
|
retain: bool,
|
|
t: T,
|
|
) {
|
|
if let Err(e) = self.publish(topic, qos, retain, t).await {
|
|
tracing::error!("{}", e);
|
|
}
|
|
}
|
|
}
|