Skip to content

Commit ba04b10

Browse files
committed
Merge remote-tracking branch 'upstream/master'
2 parents b8fab52 + f54d47f commit ba04b10

File tree

11 files changed

+58
-84
lines changed

11 files changed

+58
-84
lines changed

.github/workflows/ci.yml

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
on:
22
push:
3-
branches: [ staging, trying, master ]
3+
branches: [ master ]
44
pull_request:
5+
branches: [ master ]
56

67
name: Continuous integration
78

@@ -30,19 +31,32 @@ jobs:
3031
TARGET: x86_64-unknown-linux-gnu
3132

3233
steps:
33-
- uses: actions/checkout@v2
34-
- uses: actions-rs/toolchain@v1
34+
- uses: actions/checkout@v4
35+
36+
- uses: dtolnay/rust-toolchain@stable
3537
with:
36-
profile: minimal
3738
toolchain: ${{ matrix.rust }}
3839
target: ${{ matrix.TARGET }}
39-
override: true
40-
- uses: actions-rs/cargo@v1
41-
with:
42-
command: build
43-
args: --target=${{ matrix.TARGET }}
44-
- uses: actions-rs/cargo@v1
40+
41+
- run: cargo build --target=${{ matrix.TARGET }}
42+
43+
- run: cargo test --target=${{ matrix.TARGET }} --all-features
4544
if: ${{ contains(matrix.TARGET, 'x86_64') }}
45+
46+
clippy:
47+
runs-on: ubuntu-latest
48+
steps:
49+
- uses: actions/checkout@v4
50+
- uses: dtolnay/rust-toolchain@stable
4651
with:
47-
command: test
48-
args: --target=${{ matrix.TARGET }} --all-features
52+
components: clippy
53+
54+
- run: cargo clippy
55+
56+
fmt:
57+
name: Rustfmt
58+
runs-on: ubuntu-latest
59+
steps:
60+
- uses: actions/checkout@v4
61+
- uses: dtolnay/rust-toolchain@stable
62+
- run: cargo fmt --all -- --check

.github/workflows/clippy.yml

Lines changed: 0 additions & 20 deletions
This file was deleted.

.github/workflows/rustfmt.yml

Lines changed: 0 additions & 23 deletions
This file was deleted.

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1212
- Support for optional package `defmt` which allows for easy conversion for
1313
error types when using tools like `probe-rs` for logging over debuggers.
1414
- Implement `Serializer::collect_str`
15+
- Derive `Serialize` for `de::Error` and `ser::Error`
1516

1617
### Changed
1718

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ optional = true
2222

2323
[dependencies.serde]
2424
default-features = false
25+
features = ["derive"]
2526
version = "1.0.100"
2627

2728
[dependencies.defmt]

rust-toolchain

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/de/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use core::str::FromStr;
44
use core::{fmt, str};
55

66
use serde::de::{self, Visitor};
7+
use serde::Serialize;
78

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

1920
/// This type represents all possible errors that can occur when deserializing JSON data
20-
#[derive(Debug, PartialEq, Eq, Clone)]
21+
#[derive(Debug, PartialEq, Eq, Clone, Serialize)]
2122
#[cfg_attr(not(feature = "custom-error-messages"), derive(Copy))]
2223
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
2324
#[non_exhaustive]

src/ser/map.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ impl<'a, 'b: 'a> ser::SerializeMap for SerializeMap<'a, 'b> {
2222
Ok(())
2323
}
2424

25-
fn serialize_key<T: ?Sized>(&mut self, key: &T) -> Result<()>
25+
fn serialize_key<T>(&mut self, key: &T) -> Result<()>
2626
where
27-
T: ser::Serialize,
27+
T: ser::Serialize + ?Sized,
2828
{
2929
if !self.first {
3030
self.ser.push(b',')?;
@@ -35,9 +35,9 @@ impl<'a, 'b: 'a> ser::SerializeMap for SerializeMap<'a, 'b> {
3535
Ok(())
3636
}
3737

38-
fn serialize_value<T: ?Sized>(&mut self, value: &T) -> Result<()>
38+
fn serialize_value<T>(&mut self, value: &T) -> Result<()>
3939
where
40-
T: ser::Serialize,
40+
T: ser::Serialize + ?Sized,
4141
{
4242
value.serialize(&mut *self.ser)?;
4343
Ok(())

src/ser/mod.rs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use core::{fmt, str};
55

66
use serde::ser;
77
use serde::ser::SerializeStruct as _;
8+
use serde::Serialize;
89

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

2324
/// This type represents all possible errors that can occur when serializing JSON data
24-
#[derive(Debug, PartialEq, Eq, Copy, Clone)]
25+
#[derive(Debug, PartialEq, Eq, Copy, Clone, Serialize)]
2526
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
2627
#[non_exhaustive]
2728
pub enum Error {
@@ -185,8 +186,8 @@ macro_rules! serialize_unsigned {
185186
macro_rules! serialize_signed {
186187
($self:ident, $N:expr, $v:expr, $ixx:ident, $uxx:ident) => {{
187188
let v = $v;
188-
let (signed, mut v) = if v == $ixx::min_value() {
189-
(true, $ixx::max_value() as $uxx + 1)
189+
let (signed, mut v) = if v == $ixx::MIN {
190+
(true, $ixx::MAX as $uxx + 1)
190191
} else if v < 0 {
191192
(true, -v as $uxx)
192193
} else {
@@ -338,9 +339,9 @@ impl<'a, 'b: 'a> ser::Serializer for &'a mut Serializer<'b> {
338339
self.extend_from_slice(b"null")
339340
}
340341

341-
fn serialize_some<T: ?Sized>(self, value: &T) -> Result<Self::Ok>
342+
fn serialize_some<T>(self, value: &T) -> Result<Self::Ok>
342343
where
343-
T: ser::Serialize,
344+
T: ser::Serialize + ?Sized,
344345
{
345346
value.serialize(self)
346347
}
@@ -362,22 +363,22 @@ impl<'a, 'b: 'a> ser::Serializer for &'a mut Serializer<'b> {
362363
self.serialize_str(variant)
363364
}
364365

365-
fn serialize_newtype_struct<T: ?Sized>(self, _name: &'static str, value: &T) -> Result<Self::Ok>
366+
fn serialize_newtype_struct<T>(self, _name: &'static str, value: &T) -> Result<Self::Ok>
366367
where
367-
T: ser::Serialize,
368+
T: ser::Serialize + ?Sized,
368369
{
369370
value.serialize(self)
370371
}
371372

372-
fn serialize_newtype_variant<T: ?Sized>(
373+
fn serialize_newtype_variant<T>(
373374
self,
374375
_name: &'static str,
375376
_variant_index: u32,
376377
variant: &'static str,
377378
value: &T,
378379
) -> Result<Self::Ok>
379380
where
380-
T: ser::Serialize,
381+
T: ser::Serialize + ?Sized,
381382
{
382383
self.push(b'{')?;
383384
let mut s = SerializeStruct::new(self);
@@ -440,9 +441,9 @@ impl<'a, 'b: 'a> ser::Serializer for &'a mut Serializer<'b> {
440441
Ok(SerializeStructVariant::new(self))
441442
}
442443

443-
fn collect_str<T: ?Sized>(self, value: &T) -> Result<Self::Ok>
444+
fn collect_str<T>(self, value: &T) -> Result<Self::Ok>
444445
where
445-
T: fmt::Display,
446+
T: fmt::Display + ?Sized,
446447
{
447448
self.push(b'"')?;
448449

@@ -714,7 +715,7 @@ mod tests {
714715

715716
assert_eq!(
716717
&*crate::to_string::<_, N>(&Temperature {
717-
temperature: -2.3456788e-23
718+
temperature: -2.345_678_8e-23
718719
})
719720
.unwrap(),
720721
r#"{"temperature":-2.3456788e-23}"#
@@ -880,7 +881,7 @@ mod tests {
880881
let sd2 = SimpleDecimal(0.000);
881882
assert_eq!(&*crate::to_string::<_, N>(&sd2).unwrap(), r#"0.00"#);
882883

883-
let sd3 = SimpleDecimal(22222.78);
884+
let sd3 = SimpleDecimal(22_222.777);
884885
assert_eq!(&*crate::to_string::<_, N>(&sd3).unwrap(), r#"22222.78"#);
885886
}
886887
}

src/ser/seq.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ impl<'a, 'b: 'a> ser::SerializeSeq for SerializeSeq<'a, 'b> {
1717
type Ok = ();
1818
type Error = Error;
1919

20-
fn serialize_element<T: ?Sized>(&mut self, value: &T) -> Result<()>
20+
fn serialize_element<T>(&mut self, value: &T) -> Result<()>
2121
where
22-
T: ser::Serialize,
22+
T: ser::Serialize + ?Sized,
2323
{
2424
if !self.first {
2525
self.de.push(b',')?;
@@ -40,9 +40,9 @@ impl<'a, 'b: 'a> ser::SerializeTuple for SerializeSeq<'a, 'b> {
4040
type Ok = ();
4141
type Error = Error;
4242

43-
fn serialize_element<T: ?Sized>(&mut self, value: &T) -> Result<()>
43+
fn serialize_element<T>(&mut self, value: &T) -> Result<()>
4444
where
45-
T: ser::Serialize,
45+
T: ser::Serialize + ?Sized,
4646
{
4747
ser::SerializeSeq::serialize_element(self, value)
4848
}
@@ -56,9 +56,9 @@ impl<'a, 'b: 'a> ser::SerializeTupleStruct for SerializeSeq<'a, 'b> {
5656
type Ok = ();
5757
type Error = Error;
5858

59-
fn serialize_field<T: ?Sized>(&mut self, value: &T) -> Result<()>
59+
fn serialize_field<T>(&mut self, value: &T) -> Result<()>
6060
where
61-
T: ser::Serialize,
61+
T: ser::Serialize + ?Sized,
6262
{
6363
ser::SerializeSeq::serialize_element(self, value)
6464
}

src/ser/struct_.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ impl<'a, 'b: 'a> ser::SerializeStruct for SerializeStruct<'a, 'b> {
1717
type Ok = ();
1818
type Error = Error;
1919

20-
fn serialize_field<T: ?Sized>(&mut self, key: &'static str, value: &T) -> Result<()>
20+
fn serialize_field<T>(&mut self, key: &'static str, value: &T) -> Result<()>
2121
where
22-
T: ser::Serialize,
22+
T: ser::Serialize + ?Sized,
2323
{
2424
// XXX if `value` is `None` we not produce any output for this field
2525
if !self.first {
@@ -57,9 +57,9 @@ impl<'a, 'b: 'a> ser::SerializeStructVariant for SerializeStructVariant<'a, 'b>
5757
type Ok = ();
5858
type Error = Error;
5959

60-
fn serialize_field<T: ?Sized>(&mut self, key: &'static str, value: &T) -> Result<()>
60+
fn serialize_field<T>(&mut self, key: &'static str, value: &T) -> Result<()>
6161
where
62-
T: ser::Serialize,
62+
T: ser::Serialize + ?Sized,
6363
{
6464
// XXX if `value` is `None` we not produce any output for this field
6565
if !self.first {

0 commit comments

Comments
 (0)