Skip to content

Commit 612634c

Browse files
authored
Merge branch 'main' into migrate-errors
2 parents df39beb + b302568 commit 612634c

File tree

4 files changed

+26
-7
lines changed

4 files changed

+26
-7
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2222
change. To access equivalent functionality, use the `Diagnostic` API
2323
integration.
2424

25+
### Changed
26+
- Sealed the `Diagnose` trait.
27+
- Implementation of the `Default` trait for `Pointer` now doesn't constrain the lifetime.
28+
2529
## [0.7.1] 2025-02-16
2630

2731
### 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
@@ -163,7 +163,7 @@ pub(crate) use diagnostic_url;
163163
/// An extension trait for `Result<_, E>`, where `E` is an implementation of
164164
/// [`Diagnostic`], that converts `E` into [`Report<E>`](`Report`), yielding
165165
/// `Result<_, Report<E>>`.
166-
pub trait Diagnose<'s, T> {
166+
pub trait Diagnose<'s, T>: private::Sealed {
167167
/// The error type returned from `diagnose` and `diagnose_with`.
168168
type Error: Diagnostic;
169169

@@ -224,6 +224,11 @@ where
224224
}
225225
}
226226

227+
mod private {
228+
pub trait Sealed {}
229+
impl<T, E> Sealed for Result<T, E> {}
230+
}
231+
227232
#[cfg(test)]
228233
mod tests {
229234
#[test]

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`
@@ -2342,4 +2342,14 @@ mod tests {
23422342
let unboxed = boxed.into_buf();
23432343
assert_eq!(subjectal, unboxed);
23442344
}
2345+
2346+
#[test]
2347+
fn default_lifetime_is_correct() {
2348+
// if this compiles, we're good
2349+
fn or_default(ptr: &Pointer) -> &Pointer {
2350+
Some(ptr).unwrap_or_default()
2351+
}
2352+
// just to satisfy codecov and clippy
2353+
or_default(Pointer::root());
2354+
}
23452355
}

0 commit comments

Comments
 (0)