Skip to content

Commit

Permalink
removes acidentally enabled default features miette and toml
Browse files Browse the repository at this point in the history
  • Loading branch information
chanced committed Feb 16, 2025
1 parent 561224b commit bdacf80
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 19 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@ 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]
## [0.7.1] 2025-02-16

### Changed

- Removes accidentally enabled default features `"miette"` and `"toml"`

## [0.7.0] 2025-02-13

### Added

Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 8 additions & 17 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ license = "MIT OR Apache-2.0"
name = "jsonptr"
repository = "https://github.com/chanced/jsonptr"
rust-version = "1.79.0"
version = "0.7.0"
version = "0.7.1"

[dependencies]
miette = { version = "7.4.0", optional = true, features = ["fancy"] }
Expand All @@ -31,20 +31,11 @@ quickcheck_macros = "1.0.0"
syn = { version = "1.0.109", optional = true }

[features]
assign = []
default = [
"std",
"serde",
"json",
"toml", # TODO: remove
"resolve",
"assign",
"delete",
"miette", # TODO: remove
]
delete = ["resolve"]
json = ["dep:serde_json", "serde"]
miette = ["dep:miette", "std"]
assign = []
default = ["std", "serde", "json", "resolve", "assign", "delete"]
delete = ["resolve"]
json = ["dep:serde_json", "serde"]
miette = ["dep:miette", "std"]
resolve = []
std = ["serde/std", "serde_json?/std"]
toml = ["dep:toml", "serde", "std"]
std = ["serde/std", "serde_json?/std"]
toml = ["dep:toml", "serde", "std"]
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ flags](#feature-flags).

## Usage

### Parsing and General Usage

To parse a [`Pointer`] from a string, use either [`Pointer::parse`], for
potentially fallible parsing, or the `const fn` `from_static` to produce a
`&'static Pointer` from a string that is known to be valid.
Expand All @@ -46,6 +48,8 @@ let ptr = Pointer::parse("/examples/0/name").unwrap();
let static_ptr = Pointer::from_static("/examples/0/name");
assert_eq!(ptr, static_ptr);

assert_eq!(ptr.get(1..).unwrap(), Pointer::parse("/0/name").unwrap());

let parent = ptr.parent().unwrap();
assert_eq!(parent, Pointer::parse("/examples/0").unwrap());

Expand All @@ -70,6 +74,8 @@ buf.push_back("/");
assert_eq!(buf.as_str(), "/~0/pointer/examples/0/name/~1");
```

### Token Iteration

Iterating over the tokens or components of a pointer:

```rust
Expand All @@ -88,6 +94,8 @@ assert_eq!(components.next(), Some(Component::Token(Token::new("to"))));
assert_eq!(components.next(), Some(Component::Token(Token::new("value"))));
```

### Resolving Values

To get a value at the location of a pointer, use either the [`Resolve`] and
[`ResolveMut`] traits or [`Pointer::resolve`] and [`Pointer::resolve_mut`]
methods. See the [`resolve`] mod for more information.
Expand All @@ -102,6 +110,8 @@ let bar = ptr.resolve(&data).unwrap();
assert_eq!(bar, &json!(34));
```

### Assigning Values

Values can be set, with path expansion, using the either the [`Assign`] trait or
[`Pointer::assign`]. See [`assign`] for more information.

Expand All @@ -116,6 +126,8 @@ assert_eq!(replaced, Some(json!(42)));
assert_eq!(data, json!({"secret": { "universe": 34 }}));
```

### Deleting Values

Values can be removed with the either the [`Delete`] trait or
[`Pointer::delete`]. See [`delete`] for more information.

Expand All @@ -130,6 +142,30 @@ assert_eq!(replaced, Some(json!(42)));
assert_eq!(data, json!({"secret": { "universe": 34 }}));
```

### Error Reporting

Any error produced by function calls into methods of traits or types of this
crate can be converted into a [`Report`] which contains the original error
and the [`String`] which failed to parse or the [`PointerBuf`] which failed to
resolve or assign.

```rust
use jsonptr::{Pointer, Diagnose};
let ptr_str = "foo/bar";
let err /* Result<&Pointer, Report<ParseError>> */ = Pointer::parse(ptr_str).diagnose(ptr_str).unwrap_err();
assert!(err.original().is_no_leading_slash());
```

In the case of [`PointerBuf::parse`], the [`ParseError`] is always wrapped in a
[`Report`] so that the input `String` is not dropped.

```rust
use jsonptr::{PointerBuf};
let ptr_str = "foo/bar";
let err /* Result<&PointerBuf, Report<ParseError>> */ = PointerBuf::parse(ptr_str).unwrap_err();
assert!(err.original().is_no_leading_slash());
```

## Feature Flags

| Flag | Description | Enables | Default |
Expand All @@ -141,6 +177,7 @@ assert_eq!(data, json!({"secret": { "universe": 34 }}));
| `"assign"` | Enables the [`assign`] module and related pointer methods, providing a means to assign a value to a specific location within a document | ||
| `"resolve"` | Enables the [`resolve`] module and related pointer methods, providing a means to resolve a value at a specific location within a document | ||
| `"delete"` | Enables the [`delete`] module and related pointer methods, providing a means to delete a value at a specific location within a document | `"resolve"` ||
| `"miette"` | Enables integration with [`miette`](https://docs.rs/miette) for error reporting | `"std"` | |

<div class="rustdoc-hidden">

Expand Down
1 change: 1 addition & 0 deletions src/diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ mod tests {
}

#[test]
#[cfg(feature = "miette")]
fn parse_error() {
let invalid = "/foo/bar/invalid~3~encoding/cannot/reach";
let report = Pointer::parse(invalid).diagnose(invalid).unwrap_err();
Expand Down
1 change: 1 addition & 0 deletions src/pointer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2345,6 +2345,7 @@ mod tests {
}

#[test]
#[cfg(feature = "miette")]
fn quick_miette_spike() {
let err = PointerBuf::parse("hello-world").unwrap_err();
println!("{:?}", miette::Report::from(err));
Expand Down

0 comments on commit bdacf80

Please sign in to comment.