From d17da4359a3073aa0e8faed6112a36aeed4d2307 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20J=C3=B6rdens?= Date: Sun, 23 Jul 2023 14:49:22 +0200 Subject: [PATCH 1/5] make Serializer/Deserializer pub This is required when using serde_json_core with code that is generic over the serde implementation, i.e. code that wants to instantiate the Serializer/Deserializer, in the way done in `de::from_slice` and `ser::to_slice`. This also adds public getters for the Serializer.current_length and Deserializer.index members. Two obsolete/unused impls on the `Unreachable` have been removed. --- CHANGELOG.md | 2 ++ src/de/mod.rs | 8 +++++++- src/ser/mod.rs | 47 +++++++++-------------------------------------- 3 files changed, 18 insertions(+), 39 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8ec7a41f..1cd2fe32 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Support for serializing tuple structs. These are serialized as JSON arrays, which matches `serde_json` behaviour. +- `Serializer` and `Deserializer` are now `pub`. +- Added `Serializer::current_length()` and `Deserializer::index()` getters. ## [v0.5.0] - 2022-11-04 diff --git a/src/de/mod.rs b/src/de/mod.rs index f47f783c..0436c2be 100644 --- a/src/de/mod.rs +++ b/src/de/mod.rs @@ -79,7 +79,8 @@ pub enum Error { impl serde::de::StdError for Error {} -pub(crate) struct Deserializer<'b> { +/// The Deserializer +pub struct Deserializer<'b> { slice: &'b [u8], index: usize, } @@ -89,6 +90,11 @@ impl<'a> Deserializer<'a> { Deserializer { slice, index: 0 } } + /// Return the current index in the buffer. + pub fn index(&self) -> usize { + self.index + } + fn eat_char(&mut self) { self.index += 1; } diff --git a/src/ser/mod.rs b/src/ser/mod.rs index 3751c626..1e4ef7fb 100644 --- a/src/ser/mod.rs +++ b/src/ser/mod.rs @@ -48,7 +48,8 @@ impl fmt::Display for Error { } } -pub(crate) struct Serializer<'a> { +/// The Serializer +pub struct Serializer<'a> { buf: &'a mut [u8], current_length: usize, } @@ -86,6 +87,11 @@ impl<'a> Serializer<'a> { Ok(()) } } + + /// Return the current amount of serialized data in the buffer + pub fn current_length(&self) -> usize { + self.current_length + } } // NOTE(serialize_*signed) This is basically the numtoa implementation minus the lookup tables, @@ -475,20 +481,8 @@ impl ser::Error for Error { } } -pub(crate) enum Unreachable {} - -impl ser::SerializeTupleStruct for Unreachable { - type Ok = (); - type Error = Error; - - fn serialize_field(&mut self, _value: &T) -> Result<()> { - unreachable!() - } - - fn end(self) -> Result { - unreachable!() - } -} +/// An unreachable type to fill the SerializeTupleVariant type +pub enum Unreachable {} impl ser::SerializeTupleVariant for Unreachable { type Ok = (); @@ -503,29 +497,6 @@ impl ser::SerializeTupleVariant for Unreachable { } } -impl ser::SerializeMap for Unreachable { - type Ok = (); - type Error = Error; - - fn serialize_key(&mut self, _key: &T) -> Result<()> - where - T: ser::Serialize, - { - unreachable!() - } - - fn serialize_value(&mut self, _value: &T) -> Result<()> - where - T: ser::Serialize, - { - unreachable!() - } - - fn end(self) -> Result { - unreachable!() - } -} - #[cfg(test)] mod tests { use serde_derive::Serialize; From 9823551598181b2a821cc177cc99f39cd14dd305 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20J=C3=B6rdens?= Date: Sun, 23 Jul 2023 15:35:24 +0200 Subject: [PATCH 2/5] renames --- CHANGELOG.md | 2 +- src/de/mod.rs | 12 +++++------- src/ser/mod.rs | 13 +++++++------ 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1cd2fe32..9039f2f6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,7 +12,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Support for serializing tuple structs. These are serialized as JSON arrays, which matches `serde_json` behaviour. - `Serializer` and `Deserializer` are now `pub`. -- Added `Serializer::current_length()` and `Deserializer::index()` getters. +- Added `pub` `Serializer::end()` and `Deserializer::end()`. ## [v0.5.0] - 2022-11-04 diff --git a/src/de/mod.rs b/src/de/mod.rs index 0436c2be..7bba6783 100644 --- a/src/de/mod.rs +++ b/src/de/mod.rs @@ -86,20 +86,18 @@ pub struct Deserializer<'b> { } impl<'a> Deserializer<'a> { - fn new(slice: &'a [u8]) -> Deserializer<'_> { + /// Create a new `Deserializer` + pub fn new(slice: &'a [u8]) -> Deserializer<'_> { Deserializer { slice, index: 0 } } - /// Return the current index in the buffer. - pub fn index(&self) -> usize { - self.index - } - fn eat_char(&mut self) { self.index += 1; } - fn end(&mut self) -> Result { + /// Check whether there is any unexpected data left in the buffer + /// and return the amount of data consumed + pub fn end(&mut self) -> Result { match self.parse_whitespace() { Some(_) => Err(Error::TrailingCharacters), None => Ok(self.index), diff --git a/src/ser/mod.rs b/src/ser/mod.rs index 1e4ef7fb..641d14e8 100644 --- a/src/ser/mod.rs +++ b/src/ser/mod.rs @@ -55,13 +55,19 @@ pub struct Serializer<'a> { } impl<'a> Serializer<'a> { - fn new(buf: &'a mut [u8]) -> Self { + /// Create a new `Serializer` + pub fn new(buf: &'a mut [u8]) -> Self { Serializer { buf, current_length: 0, } } + /// Return the current amount of serialized data in the buffer + pub fn end(&self) -> usize { + self.current_length + } + fn push(&mut self, c: u8) -> Result<()> { if self.current_length < self.buf.len() { unsafe { self.push_unchecked(c) }; @@ -87,11 +93,6 @@ impl<'a> Serializer<'a> { Ok(()) } } - - /// Return the current amount of serialized data in the buffer - pub fn current_length(&self) -> usize { - self.current_length - } } // NOTE(serialize_*signed) This is basically the numtoa implementation minus the lookup tables, From 5129c918cfb90773c8124314673582f801d5c8a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20J=C3=B6rdens?= Date: Sun, 23 Jul 2023 15:37:12 +0200 Subject: [PATCH 3/5] improve docs --- src/de/mod.rs | 2 +- src/ser/mod.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/de/mod.rs b/src/de/mod.rs index 7bba6783..dcfd9bd9 100644 --- a/src/de/mod.rs +++ b/src/de/mod.rs @@ -79,7 +79,7 @@ pub enum Error { impl serde::de::StdError for Error {} -/// The Deserializer +/// A structure that deserializes Rust values from JSON in a buffer. pub struct Deserializer<'b> { slice: &'b [u8], index: usize, diff --git a/src/ser/mod.rs b/src/ser/mod.rs index 641d14e8..75153e8d 100644 --- a/src/ser/mod.rs +++ b/src/ser/mod.rs @@ -48,7 +48,7 @@ impl fmt::Display for Error { } } -/// The Serializer +/// A structure that serializes Rust values as JSON into a buffer. pub struct Serializer<'a> { buf: &'a mut [u8], current_length: usize, From 9833ab06aacf461fcd2c264c7de0a6ba43801365 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20J=C3=B6rdens?= Date: Mon, 24 Jul 2023 11:30:43 +0200 Subject: [PATCH 4/5] bump MSRV to 1.56.0 there is a MSRV bump somwhere in this dependency bump: Updating proc-macro2 v1.0.47 -> v1.0.66 Updating quote v1.0.23 -> v1.0.32 Updating serde v1.0.100 -> v1.0.175 Updating serde_derive v1.0.100 -> v1.0.175 Updating syn v1.0.109 -> v2.0.27 --- .github/workflows/ci.yml | 2 +- CHANGELOG.md | 4 ++++ Cargo.toml | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 03c31e3f..d2a78cd1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,7 +21,7 @@ jobs: include: # Test MSRV - - rust: 1.55.0 # keep in sync with manifest rust-version + - rust: 1.56.0 # keep in sync with manifest rust-version TARGET: x86_64-unknown-linux-gnu # Test nightly but don't fail diff --git a/CHANGELOG.md b/CHANGELOG.md index 9039f2f6..fe115d52 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - `Serializer` and `Deserializer` are now `pub`. - Added `pub` `Serializer::end()` and `Deserializer::end()`. +### Changed + +- Increase MSRV to 1.56.0 to work around dependency-MSRV issues (see #72) + ## [v0.5.0] - 2022-11-04 ### Changed diff --git a/Cargo.toml b/Cargo.toml index 8c28537e..aa0677ca 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,7 +4,7 @@ categories = ["no-std"] description = "serde-json for no_std programs" documentation = "https://docs.rs/serde-json-core" edition = "2018" -rust-version = "1.55.0" # keep in sync with ci +rust-version = "1.56.0" # keep in sync with ci keywords = ["serde", "json"] license = "MIT OR Apache-2.0" name = "serde-json-core" From 2313ff3e154b019c91f17a4d9ea951b0734375bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20J=C3=B6rdens?= Date: Mon, 24 Jul 2023 11:48:31 +0200 Subject: [PATCH 5/5] fix wrong MSRV in README and src/lib.rs --- Cargo.toml | 2 +- README.md | 2 +- src/lib.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index aa0677ca..64cf80b7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,7 +4,7 @@ categories = ["no-std"] description = "serde-json for no_std programs" documentation = "https://docs.rs/serde-json-core" edition = "2018" -rust-version = "1.56.0" # keep in sync with ci +rust-version = "1.56.0" # keep in sync with ci, src/lib.rs, and README keywords = ["serde", "json"] license = "MIT OR Apache-2.0" name = "serde-json-core" diff --git a/README.md b/README.md index d8ed05de..07a00f80 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ This project is developed and maintained by the [rust-embedded-community]. ## Minimum Supported Rust Version (MSRV) -This crate is guaranteed to compile on stable Rust 1.51.0 and up. It *might* +This crate is guaranteed to compile on stable Rust 1.56.0 and up. It *might* compile with older versions but that may change in any new patch release. ## License diff --git a/src/lib.rs b/src/lib.rs index c09c2b93..3ac15832 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -52,7 +52,7 @@ //! //! # Minimum Supported Rust Version (MSRV) //! -//! This crate is guaranteed to compile on stable Rust 1.51.0 and up. It *might* compile with older +//! This crate is guaranteed to compile on stable Rust 1.56.0 and up. It *might* compile with older //! versions but that may change in any new patch release. #![deny(missing_docs)]