Skip to content

Commit 9deb2b9

Browse files
authored
make Serializer and Deserializer pub and usable (#72)
* 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. * renames * improve docs * 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 * fix wrong MSRV in README and src/lib.rs
1 parent 40d3700 commit 9deb2b9

File tree

7 files changed

+28
-46
lines changed

7 files changed

+28
-46
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121

2222
include:
2323
# Test MSRV
24-
- rust: 1.55.0 # keep in sync with manifest rust-version
24+
- rust: 1.56.0 # keep in sync with manifest rust-version
2525
TARGET: x86_64-unknown-linux-gnu
2626

2727
# Test nightly but don't fail

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1111

1212
- Support for serializing tuple structs. These are serialized as JSON arrays,
1313
which matches `serde_json` behaviour.
14+
- `Serializer` and `Deserializer` are now `pub`.
15+
- Added `pub` `Serializer::end()` and `Deserializer::end()`.
16+
17+
### Changed
18+
19+
- Increase MSRV to 1.56.0 to work around dependency-MSRV issues (see #72)
1420

1521
## [v0.5.0] - 2022-11-04
1622

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ categories = ["no-std"]
44
description = "serde-json for no_std programs"
55
documentation = "https://docs.rs/serde-json-core"
66
edition = "2018"
7-
rust-version = "1.55.0" # keep in sync with ci
7+
rust-version = "1.56.0" # keep in sync with ci, src/lib.rs, and README
88
keywords = ["serde", "json"]
99
license = "MIT OR Apache-2.0"
1010
name = "serde-json-core"

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ This project is developed and maintained by the [rust-embedded-community].
1212

1313
## Minimum Supported Rust Version (MSRV)
1414

15-
This crate is guaranteed to compile on stable Rust 1.51.0 and up. It *might*
15+
This crate is guaranteed to compile on stable Rust 1.56.0 and up. It *might*
1616
compile with older versions but that may change in any new patch release.
1717

1818
## License

src/de/mod.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,21 +79,25 @@ pub enum Error {
7979

8080
impl serde::de::StdError for Error {}
8181

82-
pub(crate) struct Deserializer<'b> {
82+
/// A structure that deserializes Rust values from JSON in a buffer.
83+
pub struct Deserializer<'b> {
8384
slice: &'b [u8],
8485
index: usize,
8586
}
8687

8788
impl<'a> Deserializer<'a> {
88-
fn new(slice: &'a [u8]) -> Deserializer<'_> {
89+
/// Create a new `Deserializer`
90+
pub fn new(slice: &'a [u8]) -> Deserializer<'_> {
8991
Deserializer { slice, index: 0 }
9092
}
9193

9294
fn eat_char(&mut self) {
9395
self.index += 1;
9496
}
9597

96-
fn end(&mut self) -> Result<usize> {
98+
/// Check whether there is any unexpected data left in the buffer
99+
/// and return the amount of data consumed
100+
pub fn end(&mut self) -> Result<usize> {
97101
match self.parse_whitespace() {
98102
Some(_) => Err(Error::TrailingCharacters),
99103
None => Ok(self.index),

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
//!
5353
//! # Minimum Supported Rust Version (MSRV)
5454
//!
55-
//! This crate is guaranteed to compile on stable Rust 1.51.0 and up. It *might* compile with older
55+
//! This crate is guaranteed to compile on stable Rust 1.56.0 and up. It *might* compile with older
5656
//! versions but that may change in any new patch release.
5757
5858
#![deny(missing_docs)]

src/ser/mod.rs

Lines changed: 11 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -48,19 +48,26 @@ impl fmt::Display for Error {
4848
}
4949
}
5050

51-
pub(crate) struct Serializer<'a> {
51+
/// A structure that serializes Rust values as JSON into a buffer.
52+
pub struct Serializer<'a> {
5253
buf: &'a mut [u8],
5354
current_length: usize,
5455
}
5556

5657
impl<'a> Serializer<'a> {
57-
fn new(buf: &'a mut [u8]) -> Self {
58+
/// Create a new `Serializer`
59+
pub fn new(buf: &'a mut [u8]) -> Self {
5860
Serializer {
5961
buf,
6062
current_length: 0,
6163
}
6264
}
6365

66+
/// Return the current amount of serialized data in the buffer
67+
pub fn end(&self) -> usize {
68+
self.current_length
69+
}
70+
6471
fn push(&mut self, c: u8) -> Result<()> {
6572
if self.current_length < self.buf.len() {
6673
unsafe { self.push_unchecked(c) };
@@ -475,20 +482,8 @@ impl ser::Error for Error {
475482
}
476483
}
477484

478-
pub(crate) enum Unreachable {}
479-
480-
impl ser::SerializeTupleStruct for Unreachable {
481-
type Ok = ();
482-
type Error = Error;
483-
484-
fn serialize_field<T: ?Sized>(&mut self, _value: &T) -> Result<()> {
485-
unreachable!()
486-
}
487-
488-
fn end(self) -> Result<Self::Ok> {
489-
unreachable!()
490-
}
491-
}
485+
/// An unreachable type to fill the SerializeTupleVariant type
486+
pub enum Unreachable {}
492487

493488
impl ser::SerializeTupleVariant for Unreachable {
494489
type Ok = ();
@@ -503,29 +498,6 @@ impl ser::SerializeTupleVariant for Unreachable {
503498
}
504499
}
505500

506-
impl ser::SerializeMap for Unreachable {
507-
type Ok = ();
508-
type Error = Error;
509-
510-
fn serialize_key<T: ?Sized>(&mut self, _key: &T) -> Result<()>
511-
where
512-
T: ser::Serialize,
513-
{
514-
unreachable!()
515-
}
516-
517-
fn serialize_value<T: ?Sized>(&mut self, _value: &T) -> Result<()>
518-
where
519-
T: ser::Serialize,
520-
{
521-
unreachable!()
522-
}
523-
524-
fn end(self) -> Result<Self::Ok> {
525-
unreachable!()
526-
}
527-
}
528-
529501
#[cfg(test)]
530502
mod tests {
531503
use serde_derive::Serialize;

0 commit comments

Comments
 (0)