From 6c6b39f5f6fc2ee3b6373d1a8ef18b504f4d4f3d Mon Sep 17 00:00:00 2001 From: Ryan Summers Date: Wed, 24 Jul 2024 16:26:31 +0200 Subject: [PATCH 1/3] Updating CI --- .github/workflows/ci.yml | 38 ++++++++++++++++++++++++----------- .github/workflows/clippy.yml | 20 ------------------ .github/workflows/rustfmt.yml | 23 --------------------- CHANGELOG.md | 1 + src/ser/mod.rs | 2 +- 5 files changed, 28 insertions(+), 56 deletions(-) delete mode 100644 .github/workflows/clippy.yml delete mode 100644 .github/workflows/rustfmt.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6ee57d56b..5fb9aaa35 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,7 +1,8 @@ on: push: - branches: [ staging, trying, master ] + branches: [ master ] pull_request: + branches: [ master ] name: Continuous integration @@ -30,19 +31,32 @@ jobs: TARGET: x86_64-unknown-linux-gnu steps: - - uses: actions/checkout@v2 - - uses: actions-rs/toolchain@v1 + - uses: actions/checkout@v4 + + - uses: dtolnay/rust-toolchain@stable with: - profile: minimal toolchain: ${{ matrix.rust }} target: ${{ matrix.TARGET }} - override: true - - uses: actions-rs/cargo@v1 - with: - command: build - args: --target=${{ matrix.TARGET }} - - uses: actions-rs/cargo@v1 + + - run: cargo build --target=${{ matrix.TARGET }} + + - run: cargo test --target=${{ matrix.TARGET }} --all-features if: ${{ contains(matrix.TARGET, 'x86_64') }} + + clippy: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@stable with: - command: test - args: --target=${{ matrix.TARGET }} --all-features + components: clippy + + - run: cargo clippy + + fmt: + name: Rustfmt + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@stable + - run: cargo fmt --all -- --check diff --git a/.github/workflows/clippy.yml b/.github/workflows/clippy.yml deleted file mode 100644 index adc3a6ed1..000000000 --- a/.github/workflows/clippy.yml +++ /dev/null @@ -1,20 +0,0 @@ -on: - push: - branches: [ staging, trying, master ] - pull_request: - -name: Clippy check -jobs: - clippy_check: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: stable - override: true - components: clippy - - uses: actions-rs/clippy-check@v1 - with: - token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/rustfmt.yml b/.github/workflows/rustfmt.yml deleted file mode 100644 index 9a55c0024..000000000 --- a/.github/workflows/rustfmt.yml +++ /dev/null @@ -1,23 +0,0 @@ -on: - push: - branches: [ staging, trying, master ] - pull_request: - -name: Code formatting check - -jobs: - fmt: - name: Rustfmt - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: stable - override: true - components: rustfmt - - uses: actions-rs/cargo@v1 - with: - command: fmt - args: --all -- --check diff --git a/CHANGELOG.md b/CHANGELOG.md index 13565f950..f0fa068f3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Support for optional package `defmt` which allows for easy conversion for error types when using tools like `probe-rs` for logging over debuggers. - Implement `Serializer::collect_str` +- Derive `Serialize` for `de::Error` and `ser::Error` ### Changed diff --git a/src/ser/mod.rs b/src/ser/mod.rs index aafeb0f09..746b86bea 100644 --- a/src/ser/mod.rs +++ b/src/ser/mod.rs @@ -4,8 +4,8 @@ use core::mem::MaybeUninit; use core::{fmt, str}; use serde::ser; -use serde::Serialize; use serde::ser::SerializeStruct as _; +use serde::Serialize; #[cfg(feature = "heapless")] use heapless::{String, Vec}; From e36debbacf070bf9944f3cac33d40fc33e751869 Mon Sep 17 00:00:00 2001 From: Ryan Summers Date: Wed, 24 Jul 2024 16:32:24 +0200 Subject: [PATCH 2/3] Fixing clippy --- rust-toolchain | 1 - src/de/mod.rs | 2 +- src/ser/map.rs | 8 ++++---- src/ser/mod.rs | 26 +++++++++++++------------- src/ser/seq.rs | 12 ++++++------ src/ser/struct_.rs | 8 ++++---- 6 files changed, 28 insertions(+), 29 deletions(-) delete mode 100644 rust-toolchain diff --git a/rust-toolchain b/rust-toolchain deleted file mode 100644 index 2bf5ad044..000000000 --- a/rust-toolchain +++ /dev/null @@ -1 +0,0 @@ -stable diff --git a/src/de/mod.rs b/src/de/mod.rs index d1c5048a7..f2ccbe2ba 100644 --- a/src/de/mod.rs +++ b/src/de/mod.rs @@ -758,7 +758,7 @@ where #[cfg(test)] mod tests { - use core::str::FromStr; + use serde_derive::Deserialize; #[derive(Debug, Deserialize, PartialEq)] diff --git a/src/ser/map.rs b/src/ser/map.rs index 8e010c75a..fe17a1f2e 100644 --- a/src/ser/map.rs +++ b/src/ser/map.rs @@ -22,9 +22,9 @@ impl<'a, 'b: 'a> ser::SerializeMap for SerializeMap<'a, 'b> { Ok(()) } - fn serialize_key(&mut self, key: &T) -> Result<()> + fn serialize_key(&mut self, key: &T) -> Result<()> where - T: ser::Serialize, + T: ser::Serialize + ?Sized, { if !self.first { self.ser.push(b',')?; @@ -35,9 +35,9 @@ impl<'a, 'b: 'a> ser::SerializeMap for SerializeMap<'a, 'b> { Ok(()) } - fn serialize_value(&mut self, value: &T) -> Result<()> + fn serialize_value(&mut self, value: &T) -> Result<()> where - T: ser::Serialize, + T: ser::Serialize + ?Sized, { value.serialize(&mut *self.ser)?; Ok(()) diff --git a/src/ser/mod.rs b/src/ser/mod.rs index 746b86bea..977509d7f 100644 --- a/src/ser/mod.rs +++ b/src/ser/mod.rs @@ -186,8 +186,8 @@ macro_rules! serialize_unsigned { macro_rules! serialize_signed { ($self:ident, $N:expr, $v:expr, $ixx:ident, $uxx:ident) => {{ let v = $v; - let (signed, mut v) = if v == $ixx::min_value() { - (true, $ixx::max_value() as $uxx + 1) + let (signed, mut v) = if v == $ixx::MIN { + (true, $ixx::MAX as $uxx + 1) } else if v < 0 { (true, -v as $uxx) } else { @@ -339,9 +339,9 @@ impl<'a, 'b: 'a> ser::Serializer for &'a mut Serializer<'b> { self.extend_from_slice(b"null") } - fn serialize_some(self, value: &T) -> Result + fn serialize_some(self, value: &T) -> Result where - T: ser::Serialize, + T: ser::Serialize + ?Sized, { value.serialize(self) } @@ -363,14 +363,14 @@ impl<'a, 'b: 'a> ser::Serializer for &'a mut Serializer<'b> { self.serialize_str(variant) } - fn serialize_newtype_struct(self, _name: &'static str, value: &T) -> Result + fn serialize_newtype_struct(self, _name: &'static str, value: &T) -> Result where - T: ser::Serialize, + T: ser::Serialize + ?Sized, { value.serialize(self) } - fn serialize_newtype_variant( + fn serialize_newtype_variant( self, _name: &'static str, _variant_index: u32, @@ -378,7 +378,7 @@ impl<'a, 'b: 'a> ser::Serializer for &'a mut Serializer<'b> { value: &T, ) -> Result where - T: ser::Serialize, + T: ser::Serialize + ?Sized, { self.push(b'{')?; let mut s = SerializeStruct::new(self); @@ -441,9 +441,9 @@ impl<'a, 'b: 'a> ser::Serializer for &'a mut Serializer<'b> { Ok(SerializeStructVariant::new(self)) } - fn collect_str(self, value: &T) -> Result + fn collect_str(self, value: &T) -> Result where - T: fmt::Display, + T: fmt::Display + ?Sized, { self.push(b'"')?; @@ -715,7 +715,7 @@ mod tests { assert_eq!( &*crate::to_string::<_, N>(&Temperature { - temperature: -2.3456789012345e-23 + temperature: -2.345_678_8e-23 }) .unwrap(), r#"{"temperature":-2.3456788e-23}"# @@ -871,7 +871,7 @@ mod tests { { let mut aux: String<{ N }> = String::new(); write!(aux, "{:.2}", self.0).unwrap(); - serializer.serialize_bytes(&aux.as_bytes()) + serializer.serialize_bytes(aux.as_bytes()) } } @@ -881,7 +881,7 @@ mod tests { let sd2 = SimpleDecimal(0.000); assert_eq!(&*crate::to_string::<_, N>(&sd2).unwrap(), r#"0.00"#); - let sd3 = SimpleDecimal(22222.777777); + let sd3 = SimpleDecimal(22_222.777); assert_eq!(&*crate::to_string::<_, N>(&sd3).unwrap(), r#"22222.78"#); } } diff --git a/src/ser/seq.rs b/src/ser/seq.rs index 7a4c4943d..f4f799c13 100644 --- a/src/ser/seq.rs +++ b/src/ser/seq.rs @@ -17,9 +17,9 @@ impl<'a, 'b: 'a> ser::SerializeSeq for SerializeSeq<'a, 'b> { type Ok = (); type Error = Error; - fn serialize_element(&mut self, value: &T) -> Result<()> + fn serialize_element(&mut self, value: &T) -> Result<()> where - T: ser::Serialize, + T: ser::Serialize + ?Sized, { if !self.first { self.de.push(b',')?; @@ -40,9 +40,9 @@ impl<'a, 'b: 'a> ser::SerializeTuple for SerializeSeq<'a, 'b> { type Ok = (); type Error = Error; - fn serialize_element(&mut self, value: &T) -> Result<()> + fn serialize_element(&mut self, value: &T) -> Result<()> where - T: ser::Serialize, + T: ser::Serialize + ?Sized, { ser::SerializeSeq::serialize_element(self, value) } @@ -56,9 +56,9 @@ impl<'a, 'b: 'a> ser::SerializeTupleStruct for SerializeSeq<'a, 'b> { type Ok = (); type Error = Error; - fn serialize_field(&mut self, value: &T) -> Result<()> + fn serialize_field(&mut self, value: &T) -> Result<()> where - T: ser::Serialize, + T: ser::Serialize + ?Sized, { ser::SerializeSeq::serialize_element(self, value) } diff --git a/src/ser/struct_.rs b/src/ser/struct_.rs index a6c31a8ca..6a35d347e 100644 --- a/src/ser/struct_.rs +++ b/src/ser/struct_.rs @@ -17,9 +17,9 @@ impl<'a, 'b: 'a> ser::SerializeStruct for SerializeStruct<'a, 'b> { type Ok = (); type Error = Error; - fn serialize_field(&mut self, key: &'static str, value: &T) -> Result<()> + fn serialize_field(&mut self, key: &'static str, value: &T) -> Result<()> where - T: ser::Serialize, + T: ser::Serialize + ?Sized, { // XXX if `value` is `None` we not produce any output for this field if !self.first { @@ -57,9 +57,9 @@ impl<'a, 'b: 'a> ser::SerializeStructVariant for SerializeStructVariant<'a, 'b> type Ok = (); type Error = Error; - fn serialize_field(&mut self, key: &'static str, value: &T) -> Result<()> + fn serialize_field(&mut self, key: &'static str, value: &T) -> Result<()> where - T: ser::Serialize, + T: ser::Serialize + ?Sized, { // XXX if `value` is `None` we not produce any output for this field if !self.first { From dc4a6fd6689c26b5328ea36bbb8901b4ea4e0fd4 Mon Sep 17 00:00:00 2001 From: Ryan Summers Date: Wed, 24 Jul 2024 16:38:06 +0200 Subject: [PATCH 3/3] Reverting unintended diff --- src/de/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/de/mod.rs b/src/de/mod.rs index f2ccbe2ba..d1c5048a7 100644 --- a/src/de/mod.rs +++ b/src/de/mod.rs @@ -758,7 +758,7 @@ where #[cfg(test)] mod tests { - + use core::str::FromStr; use serde_derive::Deserialize; #[derive(Debug, Deserialize, PartialEq)]