@@ -35,6 +35,8 @@ flags](#feature-flags).
3535
3636## Usage
3737
38+ ### Parsing and General Usage
39+
3840To parse a [ ` Pointer ` ] from a string, use either [ ` Pointer::parse ` ] , for
3941potentially fallible parsing, or the ` const fn ` ` from_static ` to produce a
4042` &'static Pointer ` from a string that is known to be valid.
@@ -46,6 +48,8 @@ let ptr = Pointer::parse("/examples/0/name").unwrap();
4648let static_ptr = Pointer :: from_static (" /examples/0/name" );
4749assert_eq! (ptr , static_ptr );
4850
51+ assert_eq! (ptr . get (1 .. ). unwrap (), Pointer :: parse (" /0/name" ). unwrap ());
52+
4953let parent = ptr . parent (). unwrap ();
5054assert_eq! (parent , Pointer :: parse (" /examples/0" ). unwrap ());
5155
@@ -70,6 +74,8 @@ buf.push_back("/");
7074assert_eq! (buf . as_str (), " /~0/pointer/examples/0/name/~1" );
7175```
7276
77+ ### Token Iteration
78+
7379Iterating over the tokens or components of a pointer:
7480
7581``` rust
@@ -88,6 +94,8 @@ assert_eq!(components.next(), Some(Component::Token(Token::new("to"))));
8894assert_eq! (components . next (), Some (Component :: Token (Token :: new (" value" ))));
8995```
9096
97+ ### Resolving Values
98+
9199To get a value at the location of a pointer, use either the [ ` Resolve ` ] and
92100[ ` ResolveMut ` ] traits or [ ` Pointer::resolve ` ] and [ ` Pointer::resolve_mut ` ]
93101methods. See the [ ` resolve ` ] mod for more information.
@@ -102,6 +110,8 @@ let bar = ptr.resolve(&data).unwrap();
102110assert_eq! (bar , & json! (34 ));
103111```
104112
113+ ### Assigning Values
114+
105115Values can be set, with path expansion, using the either the [ ` Assign ` ] trait or
106116[ ` Pointer::assign ` ] . See [ ` assign ` ] for more information.
107117
@@ -116,6 +126,8 @@ assert_eq!(replaced, Some(json!(42)));
116126assert_eq! (data , json! ({" secret" : { " universe" : 34 }}));
117127```
118128
129+ ### Deleting Values
130+
119131Values can be removed with the either the [ ` Delete ` ] trait or
120132[ ` Pointer::delete ` ] . See [ ` delete ` ] for more information.
121133
@@ -130,6 +142,30 @@ assert_eq!(replaced, Some(json!(42)));
130142assert_eq! (data , json! ({" secret" : { " universe" : 34 }}));
131143```
132144
145+ ### Error Reporting
146+
147+ Any error produced by function calls into methods of traits or types of this
148+ crate can be converted into a [ ` Report ` ] which contains the original error
149+ and the [ ` String ` ] which failed to parse or the [ ` PointerBuf ` ] which failed to
150+ resolve or assign.
151+
152+ ``` rust
153+ use jsonptr :: {Pointer , Diagnose };
154+ let ptr_str = " foo/bar" ;
155+ let err /* Result<&Pointer, Report<ParseError>> */ = Pointer :: parse (ptr_str ). diagnose (ptr_str ). unwrap_err ();
156+ assert! (err . original (). is_no_leading_slash ());
157+ ```
158+
159+ In the case of [ ` PointerBuf::parse ` ] , the [ ` ParseError ` ] is always wrapped in a
160+ [ ` Report ` ] so that the input ` String ` is not dropped.
161+
162+ ``` rust
163+ use jsonptr :: {PointerBuf };
164+ let ptr_str = " foo/bar" ;
165+ let err /* Result<&PointerBuf, Report<ParseError>> */ = PointerBuf :: parse (ptr_str ). unwrap_err ();
166+ assert! (err . original (). is_no_leading_slash ());
167+ ```
168+
133169## Feature Flags
134170
135171| Flag | Description | Enables | Default |
@@ -141,6 +177,7 @@ assert_eq!(data, json!({"secret": { "universe": 34 }}));
141177| ` "assign" ` | Enables the [ ` assign ` ] module and related pointer methods, providing a means to assign a value to a specific location within a document | | ✓ |
142178| ` "resolve" ` | Enables the [ ` resolve ` ] module and related pointer methods, providing a means to resolve a value at a specific location within a document | | ✓ |
143179| ` "delete" ` | Enables the [ ` delete ` ] module and related pointer methods, providing a means to delete a value at a specific location within a document | ` "resolve" ` | ✓ |
180+ | ` "miette" ` | Enables integration with [ ` miette ` ] ( https://docs.rs/miette ) for error reporting | ` "std" ` | |
144181
145182<div class =" rustdoc-hidden " >
146183
0 commit comments