From 8c5f0ad7d1a723f59b138c44515dc89e7fc411cf Mon Sep 17 00:00:00 2001 From: Lucas Schwiderski Date: Thu, 21 Mar 2024 13:38:50 +0100 Subject: [PATCH 01/11] Add documentation --- Justfile | 11 ++++++++ README.adoc | 13 --------- README.md | 69 ++++++++++++++++++++++++++++++++++++++++++++++ README.tpl | 3 ++ src/de.rs | 5 +++- src/error.rs | 3 ++ src/lib.rs | 68 +++++++++++++++++++++++++++++++++++++++++++++ src/ser.rs | 5 ++++ tests/serialize.rs | 2 +- 9 files changed, 164 insertions(+), 15 deletions(-) delete mode 100644 README.adoc create mode 100644 README.md create mode 100644 README.tpl diff --git a/Justfile b/Justfile index c052f9a..6e40be1 100644 --- a/Justfile +++ b/Justfile @@ -1,12 +1,23 @@ project := "serde_sjson" default := "run" +build *ARGS: + cargo build {{ARGS}} + cargo readme > README.md + run *ARGS: cargo run -- {{ARGS}} test *ARGS: cargo test {{ARGS}} +doc: + cargo doc --no-deps + cargo readme > README.md + +serve-doc port='8000': doc + python3 -m http.server {{port}} --directory target/doc + coverage *ARGS: RUSTFLAGS="-C instrument-coverage" cargo test --tests {{ARGS}} || true cargo profdata -- merge -sparse default*.profraw -o {{project}}.profdata diff --git a/README.adoc b/README.adoc deleted file mode 100644 index 56a9faf..0000000 --- a/README.adoc +++ /dev/null @@ -1,13 +0,0 @@ -= Serde SJSON -:idprefix: -:idseparator: -:toc: macro -:toclevels: 1 -:!toc-title: -:caution-caption: :fire: -:important-caption: :exclamtion: -:note-caption: :paperclip: -:tip-caption: :bulb: -:warning-caption: :warning: - -A __ser__ialization/__de__serialization library for __Simplified JSON__, specifically, the Bitsquid/Stingray flavor. diff --git a/README.md b/README.md new file mode 100644 index 0000000..7b60d9e --- /dev/null +++ b/README.md @@ -0,0 +1,69 @@ +# serde_sjson + +A **ser**ialization/**de**serialization library for Simplified JSON, +the Bitsquid/Stingray flavor of JSON. + +## Usage + +### Serializing + +```rust +use serde::Serialize; +use serde_sjson::Result; + +#[derive(Serialize)] +struct Person { + name: String, + age: u8, + friends: Vec, +} + +fn main() -> Result<()> { + let data = Person { + name: String::from("Marc"), + age: 21, + friends: vec![String::from("Jessica"), String::from("Paul")], + }; + + let s = serde_sjson::to_string(&data)?; + + println!("{}", s); + + Ok(()) +} +``` + +### Deserializing + +```rust +use serde::Deserialize; +use serde_sjson::Result; + +#[derive(Deserialize)] +struct Person { + name: String, + age: u8, + friends: Vec, +} + +fn main() -> Result<()> { + let sjson = r#" + name = Marc + age = 21 + friends = [ + Jessica + Paul + ]"#; + + let data: Person = serde_sjson::from_str(sjson)?; + + println!( + "{} is {} years old and has {} friends.", + data.name, + data.age, + data.friends.len() + ); + + Ok(()) +} +``` diff --git a/README.tpl b/README.tpl new file mode 100644 index 0000000..0d9b104 --- /dev/null +++ b/README.tpl @@ -0,0 +1,3 @@ +# {{crate}} + +{{readme}} diff --git a/src/de.rs b/src/de.rs index 8d35613..b28e116 100644 --- a/src/de.rs +++ b/src/de.rs @@ -5,6 +5,7 @@ use serde::Deserialize; use crate::error::{Error, ErrorCode, Result}; use crate::parser::*; +/// A container for deserializing Rust values from SJSON. pub struct Deserializer<'de> { input: Span<'de>, is_top_level: bool, @@ -12,7 +13,7 @@ pub struct Deserializer<'de> { impl<'de> Deserializer<'de> { #![allow(clippy::should_implement_trait)] - pub fn from_str(input: &'de str) -> Self { + pub(crate) fn from_str(input: &'de str) -> Self { Self { input: Span::from(input), is_top_level: true, @@ -65,6 +66,8 @@ impl<'de> Deserializer<'de> { } } +/// Deserializes an SJSON string to a Rust value. +#[inline] pub fn from_str<'a, T>(input: &'a str) -> Result where T: Deserialize<'a>, diff --git a/src/error.rs b/src/error.rs index feee003..9673524 100644 --- a/src/error.rs +++ b/src/error.rs @@ -2,8 +2,11 @@ use std::{fmt, io}; use crate::parser::Token; +/// An alias for a `Result` with `serde_sjson::Error`. pub type Result = std::result::Result; +/// A type encapsulating the different errors that might occurr +/// during serialization or deserialization. #[derive(PartialEq)] pub struct Error { inner: Box, diff --git a/src/lib.rs b/src/lib.rs index ea30715..afac0e7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,3 +1,71 @@ +//! A **ser**ialization/**de**serialization library for Simplified JSON, +//! the Bitsquid/Stingray flavor of JSON. +//! +//! # Usage +//! +//! ## Serializing +//! +//! ``` +//! use serde::Serialize; +//! use serde_sjson::Result; +//! +//! #[derive(Serialize)] +//! struct Person { +//! name: String, +//! age: u8, +//! friends: Vec, +//! } +//! +//! fn main() -> Result<()> { +//! let data = Person { +//! name: String::from("Marc"), +//! age: 21, +//! friends: vec![String::from("Jessica"), String::from("Paul")], +//! }; +//! +//! let s = serde_sjson::to_string(&data)?; +//! +//! println!("{}", s); +//! +//! Ok(()) +//! } +//! ``` +//! +//! ## Deserializing +//! +//! ``` +//! use serde::Deserialize; +//! use serde_sjson::Result; +//! +//! #[derive(Deserialize)] +//! struct Person { +//! name: String, +//! age: u8, +//! friends: Vec, +//! } +//! +//! fn main() -> Result<()> { +//! let sjson = r#" +//! name = Marc +//! age = 21 +//! friends = [ +//! Jessica +//! Paul +//! ]"#; +//! +//! let data: Person = serde_sjson::from_str(sjson)?; +//! +//! println!( +//! "{} is {} years old and has {} friends.", +//! data.name, +//! data.age, +//! data.friends.len() +//! ); +//! +//! Ok(()) +//! } +//! ``` + mod de; mod error; mod parser; diff --git a/src/ser.rs b/src/ser.rs index 532f78f..7efd83b 100644 --- a/src/ser.rs +++ b/src/ser.rs @@ -7,12 +7,14 @@ use crate::error::{Error, ErrorCode, Result}; // TODO: Make configurable const INDENT: [u8; 2] = [0x20, 0x20]; +/// A container for serializing Rust values into SJSON. pub struct Serializer { // The current indentation level level: usize, writer: W, } +/// Serializes a value into a generic `io::Write`. #[inline] pub fn to_writer(writer: &mut W, value: &T) -> Result<()> where @@ -23,6 +25,7 @@ where value.serialize(&mut serializer) } +/// Serializes a value into a byte vector. #[inline] pub fn to_vec(value: &T) -> Result> where @@ -33,6 +36,7 @@ where Ok(vec) } +/// Serializes a value into a string. #[inline] pub fn to_string(value: &T) -> Result where @@ -51,6 +55,7 @@ impl Serializer where W: io::Write, { + /// Creates a new `Serializer`. pub fn new(writer: W) -> Self { Self { level: 0, writer } } diff --git a/tests/serialize.rs b/tests/serialize.rs index 7afb926..380fec0 100644 --- a/tests/serialize.rs +++ b/tests/serialize.rs @@ -1,4 +1,4 @@ -use serde_sjson::{to_string, Error}; +use serde_sjson::to_string; #[test] fn serialize_null() { From 5a2855f0aeb4a65b51bcf52113d8faabbc3a0e52 Mon Sep 17 00:00:00 2001 From: Lucas Schwiderski Date: Thu, 21 Mar 2024 13:39:52 +0100 Subject: [PATCH 02/11] Improve package metadata --- Cargo.toml | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 3526b48..a394beb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,15 +1,27 @@ [package] name = "serde_sjson" version = "1.1.0" +authors = ["Lucas Schwiderski"] +categories = ["encoding", "parser-implementations"] +description = "An SJSON serialization file format" +documentation = "https://docs.rs/serde_sjson" edition = "2021" keywords = ["serde", "serialization", "sjson"] -description = "An SJSON serialization file format" -categories = ["encoding", "parser-implementations"] +license-file = "LICENSE" +repository = "https://github.com/sclu1034/serde_sjson" +exclude = [ + ".github/", + ".ci/", + "Justfile" +] [dependencies] -nom = "7.1.3" -nom_locate = "4.1.0" -serde = { version = "1.0.154", default-features = false } +nom = "7" +nom_locate = "4.1" +serde = { version = "1.0", default-features = false } [dev-dependencies] -serde = { version = "1.0.154", features = ["derive"] } +serde = { version = "1.0.194", features = ["derive"] } + +[badges] +maintenance = { status = "passively-maintained" } From 478a085ffe30b2afcd3f438c83d24fda803e593c Mon Sep 17 00:00:00 2001 From: Lucas Schwiderski Date: Thu, 21 Mar 2024 13:42:10 +0100 Subject: [PATCH 03/11] Add initial GitHub Actions CI --- .github/workflows/ci.yml | 109 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..860f849 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,109 @@ +name: Simple build & test + +on: + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] + +env: + CARGO_TERM_COLOR: always + +jobs: + tests: + name: ${{ matrix.make.name }} (${{ matrix.os }}) + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, macos-latest] + rust: [stable, nightly] + task: + - name: Clippy + cmd: "cargo clippy -D warnings" + - name: Test + cmd: "cargo test" + - name: Format + cmd: "cargo fmt --all --check" + - name: Build + cmd: "cargo build --frozen --release" + include: + - os: ubuntu-latest + sccache-path: /home/runner/.cache/sccache + - os: macos-latest + sccache-path: /Users/runner/Library/Caches/Mozilla.sccache + exclude: + - os: macos-latest + rust: stable + task: + name: Clippy + - os: macos-latest + rust: nightly + task: + name: Clippy + - os: macos-latest + rust: stable + task: + name: Format + - os: macos-latest + rust: nightly + task: + name: Format + env: + RUST_BACKTRACE: full + RUSTC_WRAPPER: sccache + RUSTV: ${{ matrix.rust }} + SCCACHE_CACHE_SIZE: 2G + SCCACHE_DIR: ${{ matrix.sccache-path }} + steps: + - uses: actions/checkout@v3 + - name: Install sccache (ubuntu-latest) + if: matrix.os == 'ubuntu-latest' + env: + LINK: https://github.com/mozilla/sccache/releases/download + SCCACHE_VERSION: 0.2.13 + run: | + SCCACHE_FILE=sccache-$SCCACHE_VERSION-x86_64-unknown-linux-musl + mkdir -p $HOME/.local/bin + curl -L "$LINK/$SCCACHE_VERSION/$SCCACHE_FILE.tar.gz" | tar xz + mv -f $SCCACHE_FILE/sccache $HOME/.local/bin/sccache + echo "$HOME/.local/bin" >> $GITHUB_PATH + - name: Install sccache (macos-latest) + if: matrix.os == 'macos-latest' + run: | + brew update + brew install sccache + - name: Install Rust ${{ matrix.rust }} + uses: actions-rs/toolchain@v1 + with: + toolchain: ${{ matrix.rust }} + profile: minimal + override: true + - name: Cache cargo registry + uses: actions/cache@v2 + with: + path: | + ~/.cargo/registry + ~/.cargo/git + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} + restore-keys: | + ${{ runner.os }}-cargo- + - name: Save sccache + uses: actions/cache@v2 + with: + path: ${{ matrix.sccache-path }} + key: ${{ runner.os }}-sccache-${{ hashFiles('**/Cargo.lock') }} + restore-keys: | + ${{ runner.os }}-sccache- + - name: Start sccache server + run: sccache --start-server + - name: Install rustfmt + if: matrix.task.name == 'Format' + run: rustup component add rustfmt + - name: ${{ matrix.task.name }} + run: ${{ matrix.task.cmd }} + - name: Print sccache stats + run: sccache --show-stats + - name: Stop sccache server + run: sccache --stop-server + continue-on-error: true From 1b3d16c479ea1bee2b6ccbea072a1af2b63135ca Mon Sep 17 00:00:00 2001 From: Lucas Schwiderski Date: Thu, 21 Mar 2024 13:41:09 +0100 Subject: [PATCH 04/11] Add publishing command --- CHANGELOG.adoc => CHANGELOG.md | 50 ++++++++++++++++++---------------- Justfile | 3 ++ release.toml | 5 ++++ 3 files changed, 34 insertions(+), 24 deletions(-) rename CHANGELOG.adoc => CHANGELOG.md (51%) create mode 100644 release.toml diff --git a/CHANGELOG.adoc b/CHANGELOG.md similarity index 51% rename from CHANGELOG.adoc rename to CHANGELOG.md index 364a378..3f72905 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.md @@ -1,65 +1,67 @@ -= Changelog -:toc: -:toclevels: 1 -:idprefix: -:idseparator: - +# Changelog -== [Unreleased] + -== [v1.1.0] - 2024-03-21 +## [Unreleased] - ReleaseDate -=== Added +### Added + +- publishing to [crates.io](https://crates.io) + +## [v1.1.0] - 2024-03-21 + +### Added - implement serializing into generic `io::Write` -=== Fixed +### Fixed - fix parsing CRLF -== [v1.0.0] - 2023-03-10 +## [v1.0.0] - 2023-03-10 -=== Added +### Added - implement literal strings -=== Fixed +### Fixed - fix serializing strings containing `:` - fix serializing certain escaped characters -== [v0.2.4] - 2023-03-01 +## [v0.2.4] - 2023-03-01 -=== Fixed +### Fixed - fix incorrect parsing of unquoted strings -== [v0.2.3] - 2023-02-24 +## [v0.2.3] - 2023-02-24 -=== Fixed +### Fixed - support backslashes in delimited strings -== [v0.2.2] - 2023-02-18 +## [v0.2.2] - 2023-02-18 -=== Fixed +### Fixed - fix deserialization failing on arrays and objects in some cases -== [v0.2.1] - 2022-12-28 +## [v0.2.1] - 2022-12-28 -=== Fixed +### Fixed - fix serializing Unicode -== [v0.2.0] - 2022-11-25 +## [v0.2.0] - 2022-11-25 -=== Added +### Added * parsing & deserialization -== [v0.1.0] - 2022-11-18 +## [v0.1.0] - 2022-11-18 -=== Added +### Added * initial release * serialization diff --git a/Justfile b/Justfile index 6e40be1..131d0e5 100644 --- a/Justfile +++ b/Justfile @@ -18,6 +18,9 @@ doc: serve-doc port='8000': doc python3 -m http.server {{port}} --directory target/doc +release version execute='': + cargo release --sign --allow-branch master {{ if execute != "" { '-x' } else { '' } }} {{version}} + coverage *ARGS: RUSTFLAGS="-C instrument-coverage" cargo test --tests {{ARGS}} || true cargo profdata -- merge -sparse default*.profraw -o {{project}}.profdata diff --git a/release.toml b/release.toml new file mode 100644 index 0000000..df0c8c9 --- /dev/null +++ b/release.toml @@ -0,0 +1,5 @@ +pre-release-replacements = [ + {file="CHANGELOG.md", search="Unreleased", replace="{{version}}"}, + {file="CHANGELOG.md", search="ReleaseDate", replace="{{date}}"}, + {file="CHANGELOG.md", search="", replace="\n\n## [Unreleased] - ReleaseDate", exactly=1}, +] From a5117b272dfc78c3a60c3e52f8f2212ac53290ec Mon Sep 17 00:00:00 2001 From: Lucas Schwiderski Date: Thu, 21 Mar 2024 13:52:57 +0100 Subject: [PATCH 05/11] chore: Release serde_sjson version 1.2.0 --- CHANGELOG.md | 2 ++ Cargo.toml | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3f72905..dd2bf82 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ ## [Unreleased] - ReleaseDate +## [1.2.0] - 2024-03-21 + ### Added - publishing to [crates.io](https://crates.io) diff --git a/Cargo.toml b/Cargo.toml index a394beb..d1551a7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "serde_sjson" -version = "1.1.0" +version = "1.2.0" authors = ["Lucas Schwiderski"] categories = ["encoding", "parser-implementations"] description = "An SJSON serialization file format" From 8439ef0cd59ecf20fba9426d41a272707172cd30 Mon Sep 17 00:00:00 2001 From: Lucas Schwiderski Date: Mon, 21 Apr 2025 19:07:46 +0200 Subject: [PATCH 06/11] Update nom to new major version --- CHANGELOG.md | 4 ++++ Cargo.toml | 6 ++--- src/parser.rs | 63 +++++++++++++++++++++++++++++---------------------- 3 files changed, 43 insertions(+), 30 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dd2bf82..0669846 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ ## [Unreleased] - ReleaseDate +### Changed + +- update [nom](https://crates.io/crates/nom) to v8 + ## [1.2.0] - 2024-03-21 ### Added diff --git a/Cargo.toml b/Cargo.toml index d1551a7..0868559 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,12 +16,12 @@ exclude = [ ] [dependencies] -nom = "7" -nom_locate = "4.1" +nom = "8" +nom_locate = "5" serde = { version = "1.0", default-features = false } [dev-dependencies] -serde = { version = "1.0.194", features = ["derive"] } +serde = { version = "1.0", features = ["derive"] } [badges] maintenance = { status = "passively-maintained" } diff --git a/src/parser.rs b/src/parser.rs index 573d1ce..b471e31 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -4,8 +4,8 @@ use nom::character::complete::{char, digit1, none_of, not_line_ending, one_of}; use nom::combinator::{cut, eof, map, map_res, opt, recognize, value}; use nom::multi::many1_count; use nom::number::complete::double; -use nom::sequence::{delimited, preceded, terminated, tuple}; -use nom::{IResult, Slice}; +use nom::sequence::{delimited, preceded, terminated}; +use nom::{IResult, Input as _, Parser as _}; use nom_locate::LocatedSpan; pub(crate) type Span<'a> = LocatedSpan<&'a str>; @@ -35,23 +35,25 @@ fn whitespace(input: Span) -> IResult { } fn null(input: Span) -> IResult { - value((), tag("null"))(input) + value((), tag("null")).parse(input) } fn separator(input: Span) -> IResult { map(alt((tag(","), tag("\n"), tag("\r\n"))), |val: Span| { *val.fragment() - })(input) + }) + .parse(input) } fn bool(input: Span) -> IResult { - alt((value(true, tag("true")), value(false, tag("false"))))(input) + alt((value(true, tag("true")), value(false, tag("false")))).parse(input) } fn integer(input: Span) -> IResult { - map_res(recognize(tuple((opt(char('-')), digit1))), |val: Span| { + map_res(recognize((opt(char('-')), digit1)), |val: Span| { val.fragment().parse::() - })(input) + }) + .parse(input) } fn float(input: Span) -> IResult { @@ -61,14 +63,16 @@ fn float(input: Span) -> IResult { fn identifier(input: Span) -> IResult { map(recognize(many1_count(none_of("\" \t\n=:"))), |val: Span| { *val.fragment() - })(input) + }) + .parse(input) } fn literal_string(input: Span) -> IResult { map( delimited(tag("\"\"\""), take_until("\"\"\""), tag("\"\"\"")), |val: Span| *val.fragment(), - )(input) + ) + .parse(input) } fn string_content(input: Span) -> IResult { @@ -84,49 +88,51 @@ fn string_content(input: Span) -> IResult { } '\n' if !escaped => { let err = nom::error::Error { - input: input.slice(j..), + input: input.take_from(j), code: nom::error::ErrorKind::Char, }; return Err(nom::Err::Error(err)); } '"' if !escaped => { - return Ok((input.slice(j..), &buf[0..j])); + return Ok((input.take_from(j), &buf[0..j])); } _ => escaped = false, } } let err = nom::error::Error { - input: input.slice((i + 1)..), + input: input.take_from(i + 1), code: nom::error::ErrorKind::Char, }; Err(nom::Err::Failure(err)) } fn delimited_string(input: Span) -> IResult { - preceded(char('"'), cut(terminated(string_content, char('"'))))(input) + preceded(char('"'), cut(terminated(string_content, char('"')))).parse(input) } fn string(input: Span) -> IResult { - alt((identifier, literal_string, delimited_string))(input) + alt((identifier, literal_string, delimited_string)).parse(input) } fn line_comment(input: Span) -> IResult { map( preceded(tag("//"), alt((not_line_ending, eof))), |val: Span| *val.fragment(), - )(input) + ) + .parse(input) } fn block_comment(input: Span) -> IResult { map( delimited(tag("/*"), take_until("*/"), tag("*/")), |val: Span| *val.fragment(), - )(input) + ) + .parse(input) } fn comment(input: Span) -> IResult { - alt((line_comment, block_comment))(input) + alt((line_comment, block_comment)).parse(input) } fn optional(input: Span) -> IResult { @@ -135,7 +141,7 @@ fn optional(input: Span) -> IResult { let empty = value((), tag("")); let content = value((), many1_count(alt((whitespace, comment)))); - alt((content, empty))(input) + alt((content, empty)).parse(input) } pub(crate) fn parse_next_token(input: Span) -> IResult { @@ -159,45 +165,48 @@ pub(crate) fn parse_next_token(input: Span) -> IResult { map(float, Token::Float), map(string, |val| Token::String(val.to_string())), )), - )(input) + ) + .parse(input) } pub(crate) fn parse_trailing_characters(input: Span) -> IResult { - value((), optional)(input) + value((), optional).parse(input) } pub(crate) fn parse_null(input: Span) -> IResult { - preceded(optional, value(Token::Null, null))(input) + preceded(optional, value(Token::Null, null)).parse(input) } pub(crate) fn parse_separator(input: Span) -> IResult { preceded( opt(horizontal_whitespace), value(Token::Separator, separator), - )(input) + ) + .parse(input) } pub(crate) fn parse_bool(input: Span) -> IResult { - preceded(optional, map(bool, Token::Boolean))(input) + preceded(optional, map(bool, Token::Boolean)).parse(input) } pub(crate) fn parse_integer(input: Span) -> IResult { - preceded(optional, map(integer, Token::Integer))(input) + preceded(optional, map(integer, Token::Integer)).parse(input) } pub(crate) fn parse_float(input: Span) -> IResult { - preceded(optional, map(float, Token::Float))(input) + preceded(optional, map(float, Token::Float)).parse(input) } pub(crate) fn parse_identifier(input: Span) -> IResult { preceded( optional, map(identifier, |val| Token::String(val.to_string())), - )(input) + ) + .parse(input) } pub(crate) fn parse_string(input: Span) -> IResult { - preceded(optional, map(string, |val| Token::String(val.to_string())))(input) + preceded(optional, map(string, |val| Token::String(val.to_string()))).parse(input) } #[cfg(test)] From 34c34e83b5842a508b6d198a31ee7688b8aa8f5f Mon Sep 17 00:00:00 2001 From: Lucas Schwiderski Date: Mon, 21 Apr 2025 18:53:14 +0200 Subject: [PATCH 07/11] Fix clippy warnings --- src/de.rs | 2 +- src/ser.rs | 64 +++++++++++++++++++++++++++--------------------------- 2 files changed, 33 insertions(+), 33 deletions(-) diff --git a/src/de.rs b/src/de.rs index b28e116..067ada1 100644 --- a/src/de.rs +++ b/src/de.rs @@ -81,7 +81,7 @@ where } } -impl<'de, 'a> serde::de::Deserializer<'de> for &'a mut Deserializer<'de> { +impl<'de> serde::de::Deserializer<'de> for &mut Deserializer<'de> { type Error = Error; fn deserialize_any(self, visitor: V) -> Result diff --git a/src/ser.rs b/src/ser.rs index 7efd83b..b77799d 100644 --- a/src/ser.rs +++ b/src/ser.rs @@ -84,7 +84,7 @@ where } } -impl<'a, W> serde::ser::Serializer for &'a mut Serializer +impl serde::ser::Serializer for &mut Serializer where W: io::Write, { @@ -216,9 +216,9 @@ where self.serialize_unit() } - fn serialize_some(self, value: &T) -> Result + fn serialize_some(self, value: &T) -> Result where - T: serde::Serialize, + T: serde::Serialize + ?Sized, { self.ensure_top_level_struct()?; @@ -245,9 +245,9 @@ where 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: serde::Serialize, + T: serde::Serialize + ?Sized, { self.ensure_top_level_struct()?; @@ -255,7 +255,7 @@ where } // Serialize an externally tagged enum: `{ NAME = VALUE }`. - fn serialize_newtype_variant( + fn serialize_newtype_variant( self, _name: &'static str, _variant_index: u32, @@ -263,7 +263,7 @@ where value: &T, ) -> Result where - T: serde::Serialize, + T: serde::Serialize + ?Sized, { self.ensure_top_level_struct()?; @@ -345,24 +345,24 @@ where Ok(self) } - fn collect_str(self, value: &T) -> Result + fn collect_str(self, value: &T) -> Result where - T: std::fmt::Display, + T: std::fmt::Display + ?Sized, { self.serialize_str(&value.to_string()) } } -impl<'a, W> serde::ser::SerializeSeq for &'a mut Serializer +impl serde::ser::SerializeSeq for &mut Serializer where W: io::Write, { type Ok = (); type Error = Error; - fn serialize_element(&mut self, value: &T) -> Result<()> + fn serialize_element(&mut self, value: &T) -> Result<()> where - T: Serialize, + T: Serialize + ?Sized, { self.add_indent()?; value.serialize(&mut **self)?; @@ -376,16 +376,16 @@ where } } -impl<'a, W> serde::ser::SerializeTuple for &'a mut Serializer +impl serde::ser::SerializeTuple for &mut Serializer where W: io::Write, { type Ok = (); type Error = Error; - fn serialize_element(&mut self, value: &T) -> Result<()> + fn serialize_element(&mut self, value: &T) -> Result<()> where - T: Serialize, + T: Serialize + ?Sized, { self.add_indent()?; value.serialize(&mut **self)?; @@ -399,16 +399,16 @@ where } } -impl<'a, W> serde::ser::SerializeTupleStruct for &'a mut Serializer +impl serde::ser::SerializeTupleStruct for &mut Serializer where W: io::Write, { type Ok = (); type Error = Error; - fn serialize_field(&mut self, value: &T) -> Result<()> + fn serialize_field(&mut self, value: &T) -> Result<()> where - T: Serialize, + T: Serialize + ?Sized, { self.add_indent()?; value.serialize(&mut **self)?; @@ -422,16 +422,16 @@ where } } -impl<'a, W> serde::ser::SerializeTupleVariant for &'a mut Serializer +impl serde::ser::SerializeTupleVariant for &mut Serializer where W: io::Write, { type Ok = (); type Error = Error; - fn serialize_field(&mut self, value: &T) -> Result<()> + fn serialize_field(&mut self, value: &T) -> Result<()> where - T: Serialize, + T: Serialize + ?Sized, { self.add_indent()?; value.serialize(&mut **self)?; @@ -454,24 +454,24 @@ where } } -impl<'a, W> serde::ser::SerializeMap for &'a mut Serializer +impl serde::ser::SerializeMap for &mut Serializer where W: io::Write, { type Ok = (); type Error = Error; - fn serialize_key(&mut self, key: &T) -> Result<()> + fn serialize_key(&mut self, key: &T) -> Result<()> where - T: Serialize, + T: Serialize + ?Sized, { self.add_indent()?; key.serialize(&mut **self) } - fn serialize_value(&mut self, value: &T) -> Result<()> + fn serialize_value(&mut self, value: &T) -> Result<()> where - T: Serialize, + T: Serialize + ?Sized, { // It doesn't make a difference where the `=` is added. But doing it here // means `serialize_key` is only a call to a different function, which should @@ -491,16 +491,16 @@ where } } -impl<'a, W> serde::ser::SerializeStruct for &'a mut Serializer +impl serde::ser::SerializeStruct for &mut Serializer where W: io::Write, { 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: Serialize, + T: Serialize + ?Sized, { self.add_indent()?; key.serialize(&mut **self)?; @@ -521,16 +521,16 @@ where } } -impl<'a, W> serde::ser::SerializeStructVariant for &'a mut Serializer +impl serde::ser::SerializeStructVariant for &mut Serializer where W: std::io::Write, { 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: Serialize, + T: Serialize + ?Sized, { self.add_indent()?; key.serialize(&mut **self)?; From cf896a1c42b8c4bd024da49b197ec6bf2ee6b62f Mon Sep 17 00:00:00 2001 From: Lucas Schwiderski Date: Mon, 21 Apr 2025 22:34:38 +0200 Subject: [PATCH 08/11] Improve release script --- Justfile | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/Justfile b/Justfile index 131d0e5..51d3da0 100644 --- a/Justfile +++ b/Justfile @@ -11,6 +11,10 @@ run *ARGS: test *ARGS: cargo test {{ARGS}} +check: + cargo clippy -- -D warnings + cargo test + doc: cargo doc --no-deps cargo readme > README.md @@ -18,8 +22,13 @@ doc: serve-doc port='8000': doc python3 -m http.server {{port}} --directory target/doc -release version execute='': - cargo release --sign --allow-branch master {{ if execute != "" { '-x' } else { '' } }} {{version}} +release version execute='': check build doc + git fetch --all + [ "$(git rev-parse master)" = "$(git rev-parse origin/master)" ] \ + || (echo "error: master and origin/master differ" >&2; exit 1) + git branch -f release master + git checkout release + cargo release --sign --allow-branch release {{ if execute != "" { '-x' } else { '' } }} {{version}} coverage *ARGS: RUSTFLAGS="-C instrument-coverage" cargo test --tests {{ARGS}} || true From d22797d6439712387ce1834047ea9d319388ff1f Mon Sep 17 00:00:00 2001 From: Lucas Schwiderski Date: Mon, 21 Apr 2025 22:41:31 +0200 Subject: [PATCH 09/11] Fix more clippy warnings --- src/de.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/de.rs b/src/de.rs index 067ada1..afbb9b3 100644 --- a/src/de.rs +++ b/src/de.rs @@ -421,7 +421,7 @@ impl<'a, 'de: 'a> Separated<'a, 'de> { } } -impl<'de, 'a> serde::de::SeqAccess<'de> for Separated<'a, 'de> { +impl<'de> serde::de::SeqAccess<'de> for Separated<'_, 'de> { type Error = Error; fn next_element_seed(&mut self, seed: T) -> Result> @@ -443,7 +443,7 @@ impl<'de, 'a> serde::de::SeqAccess<'de> for Separated<'a, 'de> { } } -impl<'de, 'a> serde::de::MapAccess<'de> for Separated<'a, 'de> { +impl<'de> serde::de::MapAccess<'de> for Separated<'_, 'de> { type Error = Error; fn next_key_seed(&mut self, seed: K) -> Result> @@ -487,7 +487,7 @@ impl<'a, 'de> Enum<'a, 'de> { } } -impl<'de, 'a> EnumAccess<'de> for Enum<'a, 'de> { +impl<'de> EnumAccess<'de> for Enum<'_, 'de> { type Error = Error; type Variant = Self; @@ -505,7 +505,7 @@ impl<'de, 'a> EnumAccess<'de> for Enum<'a, 'de> { } } -impl<'de, 'a> VariantAccess<'de> for Enum<'a, 'de> { +impl<'de> VariantAccess<'de> for Enum<'_, 'de> { type Error = Error; fn unit_variant(self) -> Result<()> { From 72508752b67616481f70909bd8d7da52bef58d82 Mon Sep 17 00:00:00 2001 From: Lucas Schwiderski Date: Mon, 21 Apr 2025 22:45:13 +0200 Subject: [PATCH 10/11] Simplify release script --- Justfile | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Justfile b/Justfile index 51d3da0..51ceb16 100644 --- a/Justfile +++ b/Justfile @@ -26,9 +26,7 @@ release version execute='': check build doc git fetch --all [ "$(git rev-parse master)" = "$(git rev-parse origin/master)" ] \ || (echo "error: master and origin/master differ" >&2; exit 1) - git branch -f release master - git checkout release - cargo release --sign --allow-branch release {{ if execute != "" { '-x' } else { '' } }} {{version}} + cargo release --sign --allow-branch master {{ if execute != "" { '-x' } else { '' } }} {{version}} coverage *ARGS: RUSTFLAGS="-C instrument-coverage" cargo test --tests {{ARGS}} || true From 02b621fa64d683768c337846afa92481ea6383e5 Mon Sep 17 00:00:00 2001 From: Lucas Schwiderski Date: Mon, 21 Apr 2025 22:47:52 +0200 Subject: [PATCH 11/11] chore: Release serde_sjson version 1.2.1 --- CHANGELOG.md | 2 ++ Cargo.toml | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0669846..c76f9fa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ ## [Unreleased] - ReleaseDate +## [1.2.1] - 2025-04-21 + ### Changed - update [nom](https://crates.io/crates/nom) to v8 diff --git a/Cargo.toml b/Cargo.toml index 0868559..9b49a39 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "serde_sjson" -version = "1.2.0" +version = "1.2.1" authors = ["Lucas Schwiderski"] categories = ["encoding", "parser-implementations"] description = "An SJSON serialization file format"