Comments (8)
May be an Option
of a Result
?
https://doc.rust-lang.org/rust-by-example/error/multiple_error_types/option_result.html
pub fn try_replace_with<F>(value: Value, path: &str, fun: &mut F) -> Result<Value, JsonPathError>
where
F: FnMut(&Value) -> Option<Result<Value, JsonPathError>>,
from jsonpath.
looks good.
from jsonpath.
On the same topic I think it can also be useful to just do nothing.
Meaning if the callback code decides it doesn't want to make any effect it should be able to indicates it.
Currently, if the callback wants to maintain the same value it needs to clone it and return the cloned value.
That is how we've done it https://github.com/RedisLabsModules/RedisDoc/blob/4dc407d4682ce4b5569342c7136e7cffec68c153/src/redisjson.rs#L144
from jsonpath.
How about Option
instead of Result
?
None: skip,
Some: replace
pub fn try_replace_with<F>(value: Value, path: &str, fun: &mut F) -> Result<Value, JsonPathError>
where
F: FnMut(&Value) -> Option<Value>,
from jsonpath.
Second thought maybe we should F to get the Value and not a reference.
pub fn try_replace_with<F>(value: Value, path: &str, fun: &mut F) -> Result<Value, JsonPathError>
where
F: FnMut(Value) -> Result<Value, JsonPathError>,
This way it will be able to return the same Value if no change needed or the and Error
from jsonpath.
The second example looks better to me.
from jsonpath.
Since the Value
has been moved to F
, in order to abort all changes, it need the cloned Value
too. i think that rollback this commit 8b85ec9 or drop this issue.
Do you have a better idea?
from jsonpath.
I think I prefer to drop this issue for now
from jsonpath.
Related Issues (20)
- More flexible API HOT 1
- Allow gettting parse result when using `compile` HOT 7
- Util / TextDecoder is not a constructor
- is support root node is array? HOT 1
- New release on crates.io? HOT 2
- Support Tilde HOT 5
- Modify code to use a generic underline json value HOT 6
- Improve Parser and Tokenizer performance HOT 2
- Dot notation path containing a colon character fails to match HOT 5
- Crash on jsonpath accesing null address HOT 1
- Add support for contains operator HOT 1
- Nested filter are ignored HOT 1
- Add support for the parent operator `^`
- Export required traits for parsing a json path HOT 1
- panic: index out of bounds in `SelectorMut::replace_with` HOT 3
- Filter with OR expression fails with non-existing value
- Parser should throw an error on surplus text following the closing angle bracket of an array index
- Crash using Filter with $ HOT 1
- Fails to match with nested query selector
- Duplicate results no filter HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jsonpath.