Skip to content

Commit 9b21164

Browse files
committed
feat: Implement some useful traits on Location
Signed-off-by: Dmitry Dygalo <[email protected]>
1 parent f94b36d commit 9b21164

File tree

5 files changed

+30
-5
lines changed

5 files changed

+30
-5
lines changed

.github/workflows/ci.yml

+10
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,16 @@ jobs:
2929

3030
- uses: Swatinem/rust-cache@v2
3131

32+
# (dd): These packages bumped their MSRV with a patch release.
33+
# As per my understanding cargo will be able to automatically
34+
# resolve the proper version with the resolver v3 which is MSRV-aware.
35+
# With the current MSRV it is not possible to force the resolver to find
36+
# proper versions, hence they are pinned manually here. The end users
37+
# will be able to do the same on their side (which is a bad UX though),
38+
# but apparently there is nothing can be done on the `jsonschema` side
39+
# beside bumping MSRV to 1.85 and upgrading to the new resolver.
40+
- run: cargo update -p [email protected] --precise 0.7.4
41+
- run: cargo update -p [email protected] --precise 0.1.5
3242
- run: cargo build -p jsonschema
3343

3444
test-stable:

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## [Unreleased]
44

5+
### Added
6+
7+
- `Hash`, `PartialOrd`, `Ord` and `serde::Serialize` for `Location`.
8+
59
## [0.29.0] - 2025-02-08
610

711
### Breaking Changes

crates/jsonschema-referencing/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ workspace = true
2929

3030
[dev-dependencies]
3131
benchmark = { path = "../benchmark/" }
32-
codspeed-criterion-compat = { version = "2.7", default-features = false }
32+
codspeed-criterion-compat = { version = "2.9", default-features = false }
3333
criterion = { version = "0.5", default-features = false }
3434
referencing_testsuite = { package = "jsonschema-referencing-testsuite", path = "../jsonschema-referencing-testsuite/" }
3535
test-case = "3.3.1"

crates/jsonschema-referencing/benches/registry.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
use codspeed_criterion_compat::{criterion_group, criterion_main, BenchmarkId, Criterion};
1+
use codspeed_criterion_compat::{
2+
criterion_group, criterion_main, BatchSize, BenchmarkId, Criterion,
3+
};
24
use referencing::{Draft, Registry, SPECIFICATIONS};
35

46
static DRAFT4: &[u8] = include_bytes!("../../benchmark/data/subresources/draft4.json");
@@ -28,7 +30,7 @@ fn bench_subresources(c: &mut Criterion) {
2830
Registry::try_new("http://example.com/schema.json", resource)
2931
.expect("Invalid registry input")
3032
},
31-
criterion::BatchSize::SmallInput,
33+
BatchSize::SmallInput,
3234
);
3335
});
3436
}
@@ -57,7 +59,7 @@ fn bench_subresources(c: &mut Criterion) {
5759
|(resource, registry)| {
5860
registry.try_with_resource("http://example.com/schema.json", resource)
5961
},
60-
criterion::BatchSize::SmallInput,
62+
BatchSize::SmallInput,
6163
);
6264
},
6365
);

crates/jsonschema/src/paths.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,18 @@ impl From<usize> for LocationSegment<'_> {
136136
}
137137

138138
/// A cheap to clone JSON pointer that represents location with a JSON value.
139-
#[derive(Debug, Clone, PartialEq, Eq)]
139+
#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
140140
pub struct Location(Arc<String>);
141141

142+
impl serde::Serialize for Location {
143+
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
144+
where
145+
S: serde::Serializer,
146+
{
147+
serializer.serialize_str(&self.0)
148+
}
149+
}
150+
142151
impl Location {
143152
/// Create a new, empty `Location`.
144153
pub fn new() -> Self {

0 commit comments

Comments
 (0)