Skip to content

Commit f2677c8

Browse files
authored
Merge branch 'main' into cleanup
2 parents 16449ed + b302568 commit f2677c8

File tree

4 files changed

+26
-9
lines changed

4 files changed

+26
-9
lines changed

CHANGELOG.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## Unreleased
99

10-
### Fixed
11-
1210
### Deprecated
1311

1412
- Deprecated `ResolveError` name.
1513

14+
### Changed
15+
- Sealed the `Diagnose` trait.
16+
- Implementation of the `Default` trait for `Pointer` now doesn't constrain the lifetime.
17+
1618
## [0.7.1] 2025-02-16
1719

1820
### Changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,10 @@ use jsonptr::Pointer;
136136
use serde_json::json;
137137

138138
let ptr = Pointer::parse("/secret/universe").unwrap();
139-
let mut data = json!({"secret": { "universe": 42 }});
140-
let replaced = ptr.assign(&mut data, json!(34)).unwrap();
141-
assert_eq!(replaced, Some(json!(42)));
142-
assert_eq!(data, json!({"secret": { "universe": 34 }}));
139+
let mut data = json!({"secret": { "life": 42, "universe": 42, "everything": 42 }});
140+
let deleted = ptr.delete(&mut data);
141+
assert_eq!(deleted, Some(json!(42)));
142+
assert_eq!(data, json!({"secret": { "life": 42, "everything": 42 }}));
143143
```
144144

145145
### Error Reporting

src/diagnostic.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ pub(crate) use diagnostic_url;
165165
/// An extension trait for `Result<_, E>`, where `E` is an implementation of
166166
/// [`Diagnostic`], that converts `E` into [`Report<E>`](`Report`), yielding
167167
/// `Result<_, Report<E>>`.
168-
pub trait Diagnose<'s, T> {
168+
pub trait Diagnose<'s, T>: private::Sealed {
169169
/// The error type returned from `diagnose` and `diagnose_with`.
170170
type Error: Diagnostic;
171171

@@ -226,6 +226,11 @@ where
226226
}
227227
}
228228

229+
mod private {
230+
pub trait Sealed {}
231+
impl<T, E> Sealed for Result<T, E> {}
232+
}
233+
229234
#[cfg(test)]
230235
mod tests {
231236
use super::*;

src/pointer.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ mod slice;
3636
#[cfg_attr(not(doc), repr(transparent))]
3737
pub struct Pointer(str);
3838

39-
impl Default for &'static Pointer {
39+
impl Default for &Pointer {
4040
fn default() -> Self {
4141
Pointer::root()
4242
}
@@ -398,7 +398,7 @@ impl Pointer {
398398
/// [`Delete`]. The supplied implementations (`"json"` & `"toml"`) operate
399399
/// as follows:
400400
/// - If the `Pointer` can be resolved, the `Value` is deleted and returned.
401-
/// - If the `Pointer` fails to resolve for any reason, `Ok(None)` is returned.
401+
/// - If the `Pointer` fails to resolve for any reason, `None` is returned.
402402
/// - If the `Pointer` is root, `value` is replaced:
403403
/// - `"json"`: `serde_json::Value::Null`
404404
/// - `"toml"`: `toml::Value::Table::Default`
@@ -2333,4 +2333,14 @@ mod tests {
23332333
let unboxed = boxed.into_buf();
23342334
assert_eq!(subjectal, unboxed);
23352335
}
2336+
2337+
#[test]
2338+
fn default_lifetime_is_correct() {
2339+
// if this compiles, we're good
2340+
fn or_default(ptr: &Pointer) -> &Pointer {
2341+
Some(ptr).unwrap_or_default()
2342+
}
2343+
// just to satisfy codecov and clippy
2344+
or_default(Pointer::root());
2345+
}
23362346
}

0 commit comments

Comments
 (0)