Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change serde-cbor to minicbor #69

Merged
merged 1 commit into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,11 @@ heapless = { version = "0.7.0", features = ["serde"] }
mqttrust = { version = "0.6" }
nb = "1"
serde = { version = "1.0.126", default-features = false, features = ["derive"] }
serde_cbor = { version = "^0.11", default-features = false, optional = true }
serde-json-core = { version = "0.4.0" }

minicbor = { version = "0.25", optional = true }
minicbor-serde = { version = "0.3.2", optional = true }

smlang = "0.5.0"
fugit-timer = "0.1.2"
shadow-derive = { path = "shadow_derive", version = "0.2.1" }
Expand All @@ -54,12 +57,12 @@ hex = "0.4.3"
[features]
default = ["ota_mqtt_data", "provision_cbor"]

provision_cbor = ["serde_cbor"]
provision_cbor = ["dep:minicbor", "dep:minicbor-serde"]

ota_mqtt_data = ["serde_cbor"]
ota_mqtt_data = ["dep:minicbor", "dep:minicbor-serde"]
ota_http_data = []

std = ["serde/std", "serde_cbor?/std"]
std = ["serde/std", "minicbor-serde?/std"]

defmt = ["dep:defmt", "mqttrust/defmt-impl", "heapless/defmt-impl"]

Expand Down
9 changes: 3 additions & 6 deletions rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
[toolchain]
channel = "nightly-2023-06-28"
components = [ "rust-src", "rustfmt", "llvm-tools-preview", "clippy" ]
targets = [
"x86_64-unknown-linux-gnu",
"thumbv7em-none-eabihf"
]
channel = "nightly-2024-09-06"
components = ["rust-src", "rustfmt", "llvm-tools-preview", "clippy"]
targets = ["x86_64-unknown-linux-gnu", "thumbv7em-none-eabihf"]
1 change: 1 addition & 0 deletions src/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ pub struct NoneError;
pub trait Try {
type Ok;
type Error;
#[allow(dead_code)]
fn into_result(self) -> Result<Self::Ok, Self::Error>;
}

Expand Down
2 changes: 0 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,5 @@ pub mod ota;
pub mod provisioning;
pub mod shadows;

pub use serde_cbor;

#[cfg(test)]
pub mod test;
2 changes: 1 addition & 1 deletion src/ota/data_interface/mqtt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@
}

impl<'a> Topic<'a> {
pub fn from_str(s: &'a str) -> Option<Self> {
let tt = s.splitn(8, '/').collect::<heapless::Vec<&str, 8>>();
Some(match (tt.get(0), tt.get(1), tt.get(2), tt.get(3)) {

Check warning on line 53 in src/ota/data_interface/mqtt.rs

View workflow job for this annotation

GitHub Actions / clippy

accessing first element with `tt.get(0)`

warning: accessing first element with `tt.get(0)` --> src/ota/data_interface/mqtt.rs:53:21 | 53 | Some(match (tt.get(0), tt.get(1), tt.get(2), tt.get(3)) { | ^^^^^^^^^ help: try: `tt.first()` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#get_first
(Some(&"$aws"), Some(&"things"), _, Some(&"streams")) => {
// This is a stream topic! Figure out which
match (tt.get(4), tt.get(5), tt.get(6), tt.get(7)) {
Expand Down Expand Up @@ -181,7 +181,7 @@
payload: &'c mut [u8],
) -> Result<FileBlock<'c>, OtaError> {
Ok(
serde_cbor::de::from_mut_slice::<cbor::GetStreamResponse>(payload)
minicbor_serde::from_slice::<cbor::GetStreamResponse>(payload)
.map_err(|_| OtaError::Encoding)?
.into(),
)
Expand Down
7 changes: 4 additions & 3 deletions src/ota/encoding/cbor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,14 @@
pub client_token: Option<&'a str>,
}

pub fn to_slice<T>(value: &T, slice: &mut [u8]) -> Result<usize, ()>

Check warning on line 75 in src/ota/encoding/cbor.rs

View workflow job for this annotation

GitHub Actions / clippy

this returns a `Result<_, ()>`

warning: this returns a `Result<_, ()>` --> src/ota/encoding/cbor.rs:75:1 | 75 | pub fn to_slice<T>(value: &T, slice: &mut [u8]) -> Result<usize, ()> | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: use a custom `Error` type instead = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#result_unit_err = note: `#[warn(clippy::result_unit_err)]` on by default
where
T: serde::ser::Serialize,
{
let mut serializer = serde_cbor::ser::Serializer::new(serde_cbor::ser::SliceWrite::new(slice));
let mut serializer =
minicbor_serde::Serializer::new(minicbor::encode::write::Cursor::new(slice));
value.serialize(&mut serializer).map_err(|_| ())?;
Ok(serializer.into_inner().bytes_written())
Ok(serializer.into_encoder().writer().position())
}

impl<'a> From<GetStreamResponse<'a>> for FileBlock<'a> {
Expand Down Expand Up @@ -170,7 +171,7 @@
0, 0, 0, 0, 0, 0, 255,
];

let response: GetStreamResponse = serde_cbor::de::from_mut_slice(payload).unwrap();
let response: GetStreamResponse = minicbor_serde::from_slice(payload).unwrap();

assert_eq!(
response,
Expand Down
10 changes: 8 additions & 2 deletions src/provisioning/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,14 @@ impl From<serde_json_core::de::Error> for Error {
}
}

impl From<serde_cbor::Error> for Error {
fn from(_e: serde_cbor::Error) -> Self {
impl From<minicbor_serde::error::DecodeError> for Error {
fn from(_e: minicbor_serde::error::DecodeError) -> Self {
Self::DeserializeCbor
}
}

impl<E> From<minicbor_serde::error::EncodeError<E>> for Error {
fn from(_: minicbor_serde::error::EncodeError<E>) -> Self {
Self::Overflow
}
}
21 changes: 10 additions & 11 deletions src/provisioning/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,17 +111,18 @@ where
parameters,
};

let payload = &mut [0u8; 1024];
let mut payload = [0u8; 1024];

let payload_len = match self.payload_format {
#[cfg(feature = "provision_cbor")]
PayloadFormat::Cbor => {
let mut serializer =
serde_cbor::ser::Serializer::new(serde_cbor::ser::SliceWrite::new(payload));
let mut serializer = minicbor_serde::Serializer::new(
minicbor::encode::write::Cursor::new(&mut payload[..]),
);
register_request.serialize(&mut serializer)?;
serializer.into_inner().bytes_written()
serializer.into_encoder().writer().position()
}
PayloadFormat::Json => serde_json_core::to_slice(&register_request, payload)?,
PayloadFormat::Json => serde_json_core::to_slice(&register_request, &mut payload)?,
};

self.mqtt.publish(
Expand Down Expand Up @@ -151,7 +152,7 @@ where
let response = match format {
#[cfg(feature = "provision_cbor")]
PayloadFormat::Cbor => {
serde_cbor::de::from_mut_slice::<CreateKeysAndCertificateResponse>(payload)?
minicbor_serde::from_slice::<CreateKeysAndCertificateResponse>(payload)?
}
PayloadFormat::Json => {
serde_json_core::from_slice::<CreateKeysAndCertificateResponse>(payload)?.0
Expand All @@ -173,7 +174,7 @@ where
let response = match format {
#[cfg(feature = "provision_cbor")]
PayloadFormat::Cbor => {
serde_cbor::de::from_mut_slice::<CreateCertificateFromCsrResponse>(payload)?
minicbor_serde::from_slice::<CreateCertificateFromCsrResponse>(payload)?
}
PayloadFormat::Json => {
serde_json_core::from_slice::<CreateCertificateFromCsrResponse>(payload)?.0
Expand All @@ -195,7 +196,7 @@ where
let response = match format {
#[cfg(feature = "provision_cbor")]
PayloadFormat::Cbor => {
serde_cbor::de::from_mut_slice::<RegisterThingResponse<'_, P>>(payload)?
minicbor_serde::from_slice::<RegisterThingResponse<'_, P>>(payload)?
}
PayloadFormat::Json => {
serde_json_core::from_slice::<RegisterThingResponse<'_, P>>(payload)?.0
Expand All @@ -217,9 +218,7 @@ where
) => {
let response = match format {
#[cfg(feature = "provision_cbor")]
PayloadFormat::Cbor => {
serde_cbor::de::from_mut_slice::<ErrorResponse>(payload)?
}
PayloadFormat::Cbor => minicbor_serde::from_slice::<ErrorResponse>(payload)?,
PayloadFormat::Json => serde_json_core::from_slice::<ErrorResponse>(payload)?.0,
};

Expand Down
18 changes: 8 additions & 10 deletions src/shadows/dao.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@

impl<S: Serialize + DeserializeOwned> ShadowDAO<S> for () {
fn read(&mut self) -> Result<S, Error> {
Err(Error::NoPersistance)
Err(Error::NoPersistence)
}

fn write(&mut self, _state: &S) -> Result<(), Error> {
Err(Error::NoPersistance)
Err(Error::NoPersistence)
}
}

Expand Down Expand Up @@ -58,10 +58,8 @@
}

Ok(
serde_cbor::de::from_mut_slice::<S>(
&mut buf[U32_SIZE..len as usize + U32_SIZE],
)
.map_err(|_| Error::InvalidPayload)?,
minicbor_serde::from_slice::<S>(&mut buf[U32_SIZE..len as usize + U32_SIZE])

Check warning on line 61 in src/shadows/dao.rs

View workflow job for this annotation

GitHub Actions / clippy

the function `minicbor_serde::from_slice<S>` doesn't need a mutable reference

warning: the function `minicbor_serde::from_slice<S>` doesn't need a mutable reference --> src/shadows/dao.rs:61:53 | 61 | minicbor_serde::from_slice::<S>(&mut buf[U32_SIZE..len as usize + U32_SIZE]) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_mut_passed = note: `#[warn(clippy::unnecessary_mut_passed)]` on by default
.map_err(|_| Error::InvalidPayload)?,
)
}
_ => Err(Error::InvalidPayload),
Expand All @@ -73,14 +71,14 @@

let buf = &mut [0u8; S::MAX_PAYLOAD_SIZE + U32_SIZE];

let mut serializer = serde_cbor::ser::Serializer::new(serde_cbor::ser::SliceWrite::new(
let mut serializer = minicbor_serde::Serializer::new(minicbor::encode::write::Cursor::new(
&mut buf[U32_SIZE..],
))
.packed_format();
));

state
.serialize(&mut serializer)
.map_err(|_| Error::InvalidPayload)?;
let len = serializer.into_inner().bytes_written();
let len = serializer.into_encoder().writer().position();

if len > S::MAX_PAYLOAD_SIZE {
return Err(Error::Overflow);
Expand Down
2 changes: 1 addition & 1 deletion src/shadows/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use super::data_types::ErrorResponse;
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum Error {
Overflow,
NoPersistance,
NoPersistence,
DaoRead,
DaoWrite,
InvalidPayload,
Expand Down
8 changes: 4 additions & 4 deletions src/shadows/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@

debug!(
"[{:?}] Updating reported shadow value. Update_desired: {:?}",
S::NAME.unwrap_or_else(|| CLASSIC_SHADOW),

Check warning on line 97 in src/shadows/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

unnecessary closure used to substitute value for `Option::None`

warning: unnecessary closure used to substitute value for `Option::None` --> src/shadows/mod.rs:97:13 | 97 | S::NAME.unwrap_or_else(|| CLASSIC_SHADOW), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_lazy_evaluations help: use `unwrap_or` instead | 97 | S::NAME.unwrap_or(CLASSIC_SHADOW), | ~~~~~~~~~~~~~~~~~~~~~~~~~
update_desired
);

Expand Down Expand Up @@ -194,17 +194,17 @@
self.handler.should_handle_topic(topic)
}

/// Handle incomming publish messages from the cloud on any topics relevant
/// Handle incoming 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.
#[must_use]
pub fn handle_message(
&mut self,
topic: &str,
payload: &[u8],
) -> Result<(S, Option<S::PatchState>), Error> {

Check warning on line 207 in src/shadows/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

this function has a `#[must_use]` attribute with no message, but returns a type already marked as `#[must_use]`

warning: this function has a `#[must_use]` attribute with no message, but returns a type already marked as `#[must_use]` --> src/shadows/mod.rs:203:5 | 203 | / pub fn handle_message( 204 | | &mut self, 205 | | topic: &str, 206 | | payload: &[u8], 207 | | ) -> Result<(S, Option<S::PatchState>), Error> { | |__________________________________________________^ | = help: either add some descriptive message or remove the attribute = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#double_must_use = note: `#[warn(clippy::double_must_use)]` on by default
let (topic, thing_name, shadow_name) =
Topic::from_str(topic).ok_or(Error::WrongShadowName)?;

Expand All @@ -224,10 +224,10 @@
serde_json_core::from_slice::<AcceptedResponse<S::PatchState>>(payload)
.map_err(|_| Error::InvalidPayload)
.and_then(|(response, _)| {
if let Some(_) = response.state.delta {

Check warning on line 227 in src/shadows/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

redundant pattern matching, consider using `is_some()`

warning: redundant pattern matching, consider using `is_some()` --> src/shadows/mod.rs:227:32 | 227 | if let Some(_) = response.state.delta { | -------^^^^^^^----------------------- help: try: `if response.state.delta.is_some()` | = note: this will change drop order of the result, as well as all temporaries = note: add `#[allow(clippy::redundant_pattern_matching)]` if this is important = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_pattern_matching = note: `#[warn(clippy::redundant_pattern_matching)]` on by default
debug!(
"[{:?}] Received delta state",
S::NAME.unwrap_or_else(|| CLASSIC_SHADOW)

Check warning on line 230 in src/shadows/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

unnecessary closure used to substitute value for `Option::None`

warning: unnecessary closure used to substitute value for `Option::None` --> src/shadows/mod.rs:230:33 | 230 | ... S::NAME.unwrap_or_else(|| CLASSIC_SHADOW) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_lazy_evaluations help: use `unwrap_or` instead | 230 | S::NAME.unwrap_or(CLASSIC_SHADOW) | ~~~~~~~~~~~~~~~~~~~~~~~~~
);
self.handler.change_shadow_value(
&mut state,
Expand All @@ -235,7 +235,7 @@
Some(false),
)?;
Ok(response.state.delta)
} else if let Some(_) = response.state.reported {

Check warning on line 238 in src/shadows/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

redundant pattern matching, consider using `is_some()`

warning: redundant pattern matching, consider using `is_some()` --> src/shadows/mod.rs:238:39 | 238 | } else if let Some(_) = response.state.reported { | -------^^^^^^^-------------------------- help: try: `if response.state.reported.is_some()` | = note: this will change drop order of the result, as well as all temporaries = note: add `#[allow(clippy::redundant_pattern_matching)]` if this is important = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_pattern_matching
self.handler.change_shadow_value(
&mut state,
response.state.reported.clone(),
Expand All @@ -253,7 +253,7 @@
if error.code == 404 && matches!(topic, Topic::GetRejected) {
debug!(
"[{:?}] Thing has no shadow document. Creating with defaults...",
S::NAME.unwrap_or_else(|| CLASSIC_SHADOW)

Check warning on line 256 in src/shadows/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

unnecessary closure used to substitute value for `Option::None`

warning: unnecessary closure used to substitute value for `Option::None` --> src/shadows/mod.rs:256:29 | 256 | ... S::NAME.unwrap_or_else(|| CLASSIC_SHADOW) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_lazy_evaluations help: use `unwrap_or` instead | 256 | S::NAME.unwrap_or(CLASSIC_SHADOW) | ~~~~~~~~~~~~~~~~~~~~~~~~~
);
self.report_shadow()?;
} else {
Expand All @@ -276,16 +276,16 @@
// message body.
debug!(
"[{:?}] Received shadow delta event.",
S::NAME.unwrap_or_else(|| CLASSIC_SHADOW),

Check warning on line 279 in src/shadows/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

unnecessary closure used to substitute value for `Option::None`

warning: unnecessary closure used to substitute value for `Option::None` --> src/shadows/mod.rs:279:21 | 279 | S::NAME.unwrap_or_else(|| CLASSIC_SHADOW), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_lazy_evaluations help: use `unwrap_or` instead | 279 | S::NAME.unwrap_or(CLASSIC_SHADOW), | ~~~~~~~~~~~~~~~~~~~~~~~~~
);

serde_json_core::from_slice::<DeltaResponse<S::PatchState>>(payload)
.map_err(|_| Error::InvalidPayload)
.and_then(|(delta, _)| {
if let Some(_) = delta.state {

Check warning on line 285 in src/shadows/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

redundant pattern matching, consider using `is_some()`

warning: redundant pattern matching, consider using `is_some()` --> src/shadows/mod.rs:285:32 | 285 | if let Some(_) = delta.state { | -------^^^^^^^-------------- help: try: `if delta.state.is_some()` | = note: this will change drop order of the result, as well as all temporaries = note: add `#[allow(clippy::redundant_pattern_matching)]` if this is important = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_pattern_matching
debug!(
"[{:?}] Delta reports new desired value. Changing local value...",
S::NAME.unwrap_or_else(|| CLASSIC_SHADOW),

Check warning on line 288 in src/shadows/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

unnecessary closure used to substitute value for `Option::None`

warning: unnecessary closure used to substitute value for `Option::None` --> src/shadows/mod.rs:288:33 | 288 | ... S::NAME.unwrap_or_else(|| CLASSIC_SHADOW), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_lazy_evaluations help: use `unwrap_or` instead | 288 | S::NAME.unwrap_or(CLASSIC_SHADOW), | ~~~~~~~~~~~~~~~~~~~~~~~~~
);
}
self.handler.change_shadow_value(
Expand All @@ -302,7 +302,7 @@

debug!(
"[{:?}] Finished updating reported shadow value.",
S::NAME.unwrap_or_else(|| CLASSIC_SHADOW)

Check warning on line 305 in src/shadows/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

unnecessary closure used to substitute value for `Option::None`

warning: unnecessary closure used to substitute value for `Option::None` --> src/shadows/mod.rs:305:21 | 305 | S::NAME.unwrap_or_else(|| CLASSIC_SHADOW) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_lazy_evaluations help: use `unwrap_or` instead | 305 | S::NAME.unwrap_or(CLASSIC_SHADOW) | ~~~~~~~~~~~~~~~~~~~~~~~~~
);

None
Expand Down Expand Up @@ -343,10 +343,10 @@
/// and depending on whether the state update is rejected or accepted, it
/// will automatically update the local version after response
///
/// The returned `bool` from the update closure will determine wether the
/// The returned `bool` from the update closure will determine whether the
/// update is persisted using the `DAO`, or just updated in the cloud. This
/// can be handy for activity or status field updates that are not relevant
/// to store persistant on the device, but are required to be part of the
/// to store persistent on the device, but are required to be part of the
/// same cloud shadow.
pub fn update<F: FnOnce(&S, &mut S::PatchState) -> bool>(&mut self, f: F) -> Result<(), Error> {
let mut desired = S::PatchState::default();
Expand Down Expand Up @@ -404,17 +404,17 @@
self.handler.unsubscribe()
}

/// Handle incomming publish messages from the cloud on any topics relevant
/// Handle incoming 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.
#[must_use]
pub fn handle_message(
&mut self,
topic: &str,
payload: &[u8],
) -> Result<(&S, Option<S::PatchState>), Error> {

Check warning on line 417 in src/shadows/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

this function has a `#[must_use]` attribute with no message, but returns a type already marked as `#[must_use]`

warning: this function has a `#[must_use]` attribute with no message, but returns a type already marked as `#[must_use]` --> src/shadows/mod.rs:413:5 | 413 | / pub fn handle_message( 414 | | &mut self, 415 | | topic: &str, 416 | | payload: &[u8], 417 | | ) -> Result<(&S, Option<S::PatchState>), Error> { | |___________________________________________________^ | = help: either add some descriptive message or remove the attribute = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#double_must_use
let (topic, thing_name, shadow_name) =
Topic::from_str(topic).ok_or(Error::WrongShadowName)?;

Expand All @@ -432,17 +432,17 @@
serde_json_core::from_slice::<AcceptedResponse<S::PatchState>>(payload)
.map_err(|_| Error::InvalidPayload)
.and_then(|(response, _)| {
if let Some(_) = response.state.delta {

Check warning on line 435 in src/shadows/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

redundant pattern matching, consider using `is_some()`

warning: redundant pattern matching, consider using `is_some()` --> src/shadows/mod.rs:435:32 | 435 | if let Some(_) = response.state.delta { | -------^^^^^^^----------------------- help: try: `if response.state.delta.is_some()` | = note: this will change drop order of the result, as well as all temporaries = note: add `#[allow(clippy::redundant_pattern_matching)]` if this is important = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_pattern_matching
debug!(
"[{:?}] Received delta state",
S::NAME.unwrap_or_else(|| CLASSIC_SHADOW)

Check warning on line 438 in src/shadows/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

unnecessary closure used to substitute value for `Option::None`

warning: unnecessary closure used to substitute value for `Option::None` --> src/shadows/mod.rs:438:33 | 438 | ... S::NAME.unwrap_or_else(|| CLASSIC_SHADOW) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_lazy_evaluations help: use `unwrap_or` instead | 438 | S::NAME.unwrap_or(CLASSIC_SHADOW) | ~~~~~~~~~~~~~~~~~~~~~~~~~
);
self.handler.change_shadow_value(
&mut self.state,
response.state.delta.clone(),
Some(false),
)?;
} else if let Some(_) = response.state.reported {

Check warning on line 445 in src/shadows/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

redundant pattern matching, consider using `is_some()`

warning: redundant pattern matching, consider using `is_some()` --> src/shadows/mod.rs:445:39 | 445 | } else if let Some(_) = response.state.reported { | -------^^^^^^^-------------------------- help: try: `if response.state.reported.is_some()` | = note: this will change drop order of the result, as well as all temporaries = note: add `#[allow(clippy::redundant_pattern_matching)]` if this is important = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_pattern_matching
self.handler.change_shadow_value(
&mut self.state,
response.state.reported,
Expand All @@ -458,7 +458,7 @@
if error.code == 404 && matches!(topic, Topic::GetRejected) {
debug!(
"[{:?}] Thing has no shadow document. Creating with defaults...",
S::NAME.unwrap_or_else(|| CLASSIC_SHADOW)

Check warning on line 461 in src/shadows/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

unnecessary closure used to substitute value for `Option::None`

warning: unnecessary closure used to substitute value for `Option::None` --> src/shadows/mod.rs:461:29 | 461 | ... S::NAME.unwrap_or_else(|| CLASSIC_SHADOW) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_lazy_evaluations help: use `unwrap_or` instead | 461 | S::NAME.unwrap_or(CLASSIC_SHADOW) | ~~~~~~~~~~~~~~~~~~~~~~~~~
);
self.report_shadow()?;
} else {
Expand All @@ -481,16 +481,16 @@
// message body.
debug!(
"[{:?}] Received shadow delta event.",
S::NAME.unwrap_or_else(|| CLASSIC_SHADOW),

Check warning on line 484 in src/shadows/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

unnecessary closure used to substitute value for `Option::None`

warning: unnecessary closure used to substitute value for `Option::None` --> src/shadows/mod.rs:484:21 | 484 | S::NAME.unwrap_or_else(|| CLASSIC_SHADOW), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_lazy_evaluations help: use `unwrap_or` instead | 484 | S::NAME.unwrap_or(CLASSIC_SHADOW), | ~~~~~~~~~~~~~~~~~~~~~~~~~
);

serde_json_core::from_slice::<DeltaResponse<S::PatchState>>(payload)
.map_err(|_| Error::InvalidPayload)
.and_then(|(delta, _)| {
if let Some(_) = delta.state {

Check warning on line 490 in src/shadows/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

redundant pattern matching, consider using `is_some()`

warning: redundant pattern matching, consider using `is_some()` --> src/shadows/mod.rs:490:32 | 490 | if let Some(_) = delta.state { | -------^^^^^^^-------------- help: try: `if delta.state.is_some()` | = note: this will change drop order of the result, as well as all temporaries = note: add `#[allow(clippy::redundant_pattern_matching)]` if this is important = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_pattern_matching
debug!(
"[{:?}] Delta reports new desired value. Changing local value...",
S::NAME.unwrap_or_else(|| CLASSIC_SHADOW),

Check warning on line 493 in src/shadows/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

unnecessary closure used to substitute value for `Option::None`

warning: unnecessary closure used to substitute value for `Option::None` --> src/shadows/mod.rs:493:33 | 493 | ... S::NAME.unwrap_or_else(|| CLASSIC_SHADOW), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_lazy_evaluations help: use `unwrap_or` instead | 493 | S::NAME.unwrap_or(CLASSIC_SHADOW), | ~~~~~~~~~~~~~~~~~~~~~~~~~
);
}
self.handler.change_shadow_value(
Expand All @@ -507,7 +507,7 @@

debug!(
"[{:?}] Finished updating reported shadow value.",
S::NAME.unwrap_or_else(|| CLASSIC_SHADOW)

Check warning on line 510 in src/shadows/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

unnecessary closure used to substitute value for `Option::None`

warning: unnecessary closure used to substitute value for `Option::None` --> src/shadows/mod.rs:510:21 | 510 | S::NAME.unwrap_or_else(|| CLASSIC_SHADOW) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_lazy_evaluations help: use `unwrap_or` instead | 510 | S::NAME.unwrap_or(CLASSIC_SHADOW) | ~~~~~~~~~~~~~~~~~~~~~~~~~
);

None
Expand Down Expand Up @@ -565,7 +565,7 @@
write!(
f,
"[{:?}] = {:?}",
S::NAME.unwrap_or_else(|| CLASSIC_SHADOW),

Check warning on line 568 in src/shadows/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

unnecessary closure used to substitute value for `Option::None`

warning: unnecessary closure used to substitute value for `Option::None` --> src/shadows/mod.rs:568:13 | 568 | S::NAME.unwrap_or_else(|| CLASSIC_SHADOW), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_lazy_evaluations help: use `unwrap_or` instead | 568 | S::NAME.unwrap_or(CLASSIC_SHADOW), | ~~~~~~~~~~~~~~~~~~~~~~~~~
self.get()
)
}
Expand Down
Loading