Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
sammhicks committed Jul 24, 2024
2 parents b8fab52 + f54d47f commit ba04b10
Show file tree
Hide file tree
Showing 11 changed files with 58 additions and 84 deletions.
38 changes: 26 additions & 12 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
on:
push:
branches: [ staging, trying, master ]
branches: [ master ]
pull_request:
branches: [ master ]

name: Continuous integration

Expand Down Expand Up @@ -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
20 changes: 0 additions & 20 deletions .github/workflows/clippy.yml

This file was deleted.

23 changes: 0 additions & 23 deletions .github/workflows/rustfmt.yml

This file was deleted.

1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ optional = true

[dependencies.serde]
default-features = false
features = ["derive"]
version = "1.0.100"

[dependencies.defmt]
Expand Down
1 change: 0 additions & 1 deletion rust-toolchain

This file was deleted.

3 changes: 2 additions & 1 deletion src/de/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use core::str::FromStr;
use core::{fmt, str};

use serde::de::{self, Visitor};
use serde::Serialize;

use self::enum_::{UnitVariantAccess, VariantAccess};
use self::map::MapAccess;
Expand All @@ -17,7 +18,7 @@ mod seq;
pub type Result<T> = core::result::Result<T, Error>;

/// This type represents all possible errors that can occur when deserializing JSON data
#[derive(Debug, PartialEq, Eq, Clone)]
#[derive(Debug, PartialEq, Eq, Clone, Serialize)]
#[cfg_attr(not(feature = "custom-error-messages"), derive(Copy))]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[non_exhaustive]
Expand Down
8 changes: 4 additions & 4 deletions src/ser/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ impl<'a, 'b: 'a> ser::SerializeMap for SerializeMap<'a, 'b> {
Ok(())
}

fn serialize_key<T: ?Sized>(&mut self, key: &T) -> Result<()>
fn serialize_key<T>(&mut self, key: &T) -> Result<()>
where
T: ser::Serialize,
T: ser::Serialize + ?Sized,
{
if !self.first {
self.ser.push(b',')?;
Expand All @@ -35,9 +35,9 @@ impl<'a, 'b: 'a> ser::SerializeMap for SerializeMap<'a, 'b> {
Ok(())
}

fn serialize_value<T: ?Sized>(&mut self, value: &T) -> Result<()>
fn serialize_value<T>(&mut self, value: &T) -> Result<()>
where
T: ser::Serialize,
T: ser::Serialize + ?Sized,
{
value.serialize(&mut *self.ser)?;
Ok(())
Expand Down
27 changes: 14 additions & 13 deletions src/ser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use core::{fmt, str};

use serde::ser;
use serde::ser::SerializeStruct as _;
use serde::Serialize;

#[cfg(feature = "heapless")]
use heapless::{String, Vec};
Expand All @@ -21,7 +22,7 @@ mod struct_;
pub type Result<T> = ::core::result::Result<T, Error>;

/// This type represents all possible errors that can occur when serializing JSON data
#[derive(Debug, PartialEq, Eq, Copy, Clone)]
#[derive(Debug, PartialEq, Eq, Copy, Clone, Serialize)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[non_exhaustive]
pub enum Error {
Expand Down Expand Up @@ -185,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 {
Expand Down Expand Up @@ -338,9 +339,9 @@ impl<'a, 'b: 'a> ser::Serializer for &'a mut Serializer<'b> {
self.extend_from_slice(b"null")
}

fn serialize_some<T: ?Sized>(self, value: &T) -> Result<Self::Ok>
fn serialize_some<T>(self, value: &T) -> Result<Self::Ok>
where
T: ser::Serialize,
T: ser::Serialize + ?Sized,
{
value.serialize(self)
}
Expand All @@ -362,22 +363,22 @@ impl<'a, 'b: 'a> ser::Serializer for &'a mut Serializer<'b> {
self.serialize_str(variant)
}

fn serialize_newtype_struct<T: ?Sized>(self, _name: &'static str, value: &T) -> Result<Self::Ok>
fn serialize_newtype_struct<T>(self, _name: &'static str, value: &T) -> Result<Self::Ok>
where
T: ser::Serialize,
T: ser::Serialize + ?Sized,
{
value.serialize(self)
}

fn serialize_newtype_variant<T: ?Sized>(
fn serialize_newtype_variant<T>(
self,
_name: &'static str,
_variant_index: u32,
variant: &'static str,
value: &T,
) -> Result<Self::Ok>
where
T: ser::Serialize,
T: ser::Serialize + ?Sized,
{
self.push(b'{')?;
let mut s = SerializeStruct::new(self);
Expand Down Expand Up @@ -440,9 +441,9 @@ impl<'a, 'b: 'a> ser::Serializer for &'a mut Serializer<'b> {
Ok(SerializeStructVariant::new(self))
}

fn collect_str<T: ?Sized>(self, value: &T) -> Result<Self::Ok>
fn collect_str<T>(self, value: &T) -> Result<Self::Ok>
where
T: fmt::Display,
T: fmt::Display + ?Sized,
{
self.push(b'"')?;

Expand Down Expand Up @@ -714,7 +715,7 @@ mod tests {

assert_eq!(
&*crate::to_string::<_, N>(&Temperature {
temperature: -2.3456788e-23
temperature: -2.345_678_8e-23
})
.unwrap(),
r#"{"temperature":-2.3456788e-23}"#
Expand Down Expand Up @@ -880,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.78);
let sd3 = SimpleDecimal(22_222.777);
assert_eq!(&*crate::to_string::<_, N>(&sd3).unwrap(), r#"22222.78"#);
}
}
12 changes: 6 additions & 6 deletions src/ser/seq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ impl<'a, 'b: 'a> ser::SerializeSeq for SerializeSeq<'a, 'b> {
type Ok = ();
type Error = Error;

fn serialize_element<T: ?Sized>(&mut self, value: &T) -> Result<()>
fn serialize_element<T>(&mut self, value: &T) -> Result<()>
where
T: ser::Serialize,
T: ser::Serialize + ?Sized,
{
if !self.first {
self.de.push(b',')?;
Expand All @@ -40,9 +40,9 @@ impl<'a, 'b: 'a> ser::SerializeTuple for SerializeSeq<'a, 'b> {
type Ok = ();
type Error = Error;

fn serialize_element<T: ?Sized>(&mut self, value: &T) -> Result<()>
fn serialize_element<T>(&mut self, value: &T) -> Result<()>
where
T: ser::Serialize,
T: ser::Serialize + ?Sized,
{
ser::SerializeSeq::serialize_element(self, value)
}
Expand All @@ -56,9 +56,9 @@ impl<'a, 'b: 'a> ser::SerializeTupleStruct for SerializeSeq<'a, 'b> {
type Ok = ();
type Error = Error;

fn serialize_field<T: ?Sized>(&mut self, value: &T) -> Result<()>
fn serialize_field<T>(&mut self, value: &T) -> Result<()>
where
T: ser::Serialize,
T: ser::Serialize + ?Sized,
{
ser::SerializeSeq::serialize_element(self, value)
}
Expand Down
8 changes: 4 additions & 4 deletions src/ser/struct_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ impl<'a, 'b: 'a> ser::SerializeStruct for SerializeStruct<'a, 'b> {
type Ok = ();
type Error = Error;

fn serialize_field<T: ?Sized>(&mut self, key: &'static str, value: &T) -> Result<()>
fn serialize_field<T>(&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 {
Expand Down Expand Up @@ -57,9 +57,9 @@ impl<'a, 'b: 'a> ser::SerializeStructVariant for SerializeStructVariant<'a, 'b>
type Ok = ();
type Error = Error;

fn serialize_field<T: ?Sized>(&mut self, key: &'static str, value: &T) -> Result<()>
fn serialize_field<T>(&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 {
Expand Down

0 comments on commit ba04b10

Please sign in to comment.