From 3256f06a0680583d0a132fbb340db23e47963a7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20S=C3=A1=20de=20Mello?= Date: Mon, 17 Feb 2025 20:26:57 +0000 Subject: [PATCH 1/4] clean up misc from retro-review of #101 --- src/delete.rs | 2 +- src/diagnostic.rs | 2 +- src/pointer.rs | 19 +++++-------------- src/resolve.rs | 2 +- 4 files changed, 8 insertions(+), 17 deletions(-) diff --git a/src/delete.rs b/src/delete.rs index 2909b5e..8084652 100644 --- a/src/delete.rs +++ b/src/delete.rs @@ -7,7 +7,7 @@ //! provided implementations (`"json"` & `"toml"`) operating as follows: //! - If the [`Pointer`] can be resolved, then the [`Value`](`Delete::Value`) is //! deleted and returned as `Some(value)`. -//! - If the [`Pointer`] fails to resolve for any reason, `Ok(None)` is +//! - If the [`Pointer`] fails to resolve for any reason, `None` is //! returned. //! - If the [`Pointer`] is root, `value` is replaced: //! - `"json"` - `serde_json::Value::Null` diff --git a/src/diagnostic.rs b/src/diagnostic.rs index 71d4643..d0ebb47 100644 --- a/src/diagnostic.rs +++ b/src/diagnostic.rs @@ -32,7 +32,7 @@ pub struct Label { impl Label { /// Creates a new instance of a [`Label`] from its parts - pub fn new(text: String, offset: usize, len: usize) -> Self { + pub(crate) fn new(text: String, offset: usize, len: usize) -> Self { Self { text, offset, len } } } diff --git a/src/pointer.rs b/src/pointer.rs index 48c60b5..e97cfce 100644 --- a/src/pointer.rs +++ b/src/pointer.rs @@ -1149,20 +1149,6 @@ impl core::fmt::Display for PointerBuf { } } -/// Indicates that a [`Pointer`] was unable to be parsed due to not containing -/// a leading slash (`'/'`). -#[derive(Debug, PartialEq, Eq, Clone, Copy)] -pub struct NoLeadingSlash; - -impl fmt::Display for NoLeadingSlash { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!( - f, - "json pointer must start with a slash ('/') and is not empty" - ) - } -} - /// Indicates that a `Pointer` was malformed and unable to be parsed. #[derive(Debug, PartialEq)] pub enum ParseError { @@ -1359,6 +1345,11 @@ const fn validate(value: &str) -> Result<&str, ParseError> { Ok(value) } +/// Validates that a sequence of bytes is a valid RFC 6901 Pointer. +/// +/// # Panics +/// +/// Caller must ensure the sequence is non-empty, and that offset is in range. const fn validate_bytes(bytes: &[u8], offset: usize) -> Result<(), ParseError> { if bytes[0] != b'/' && offset == 0 { return Err(ParseError::NoLeadingSlash); diff --git a/src/resolve.rs b/src/resolve.rs index 5dba4fd..aa1fdb2 100644 --- a/src/resolve.rs +++ b/src/resolve.rs @@ -76,8 +76,8 @@ pub trait ResolveMut { fn resolve_mut(&mut self, ptr: &Pointer) -> Result<&mut Self::Value, Self::Error>; } -// TODO: should ResolveError be deprecated? /// Alias for [`Error`]. +#[deprecated(since = "0.7.2", note = "renamed to `Error`")] pub type ResolveError = Error; /// Indicates that the `Pointer` could not be resolved. From 19520560519e83a3e9a0042aaf840224473d8e28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20S=C3=A1=20de=20Mello?= Date: Sun, 23 Feb 2025 22:01:34 +0000 Subject: [PATCH 2/4] changelog --- CHANGELOG.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 15dd2c6..b2d1e18 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,16 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## Unreleased + +### Fixed + +- Made `Label` type crate-private. + +### Deprecated + +- Deprecated `ResolveError` name. + ## [0.7.1] 2025-02-16 ### Changed From 4ff3c1eac71f7b736b52c4cec1786cde64ef2165 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Mello?= <3285133+asmello@users.noreply.github.com> Date: Sun, 2 Mar 2025 12:16:04 +0000 Subject: [PATCH 3/4] make `Label::new` public again, add comment --- src/diagnostic.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/diagnostic.rs b/src/diagnostic.rs index d0ebb47..5da266c 100644 --- a/src/diagnostic.rs +++ b/src/diagnostic.rs @@ -21,8 +21,7 @@ pub trait Diagnostic: Sized { fn labels(&self, subject: &Self::Subject) -> Option>>; } -/// A label for a span within a json pointer or malformed string. -/// +/// A label for a span within a JSON Pointer or malformed string. #[derive(Debug, PartialEq, Eq, Clone)] pub struct Label { text: String, @@ -32,7 +31,10 @@ pub struct Label { impl Label { /// Creates a new instance of a [`Label`] from its parts - pub(crate) fn new(text: String, offset: usize, len: usize) -> Self { + // NOTE: this is deliberately public, so that users can use + // the `Assign` and `Resolve` traits with custom types and errors, + // and then implement `Diagnostic` for those errors. + pub fn new(text: String, offset: usize, len: usize) -> Self { Self { text, offset, len } } } From 16449ed0ec143d8f9861d53b785cfb58a253c0d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Mello?= <3285133+asmello@users.noreply.github.com> Date: Sun, 2 Mar 2025 12:16:50 +0000 Subject: [PATCH 4/4] Update CHANGELOG.md --- CHANGELOG.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b2d1e18..fa71667 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,8 +9,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed -- Made `Label` type crate-private. - ### Deprecated - Deprecated `ResolveError` name.