Giter Site home page Giter Site logo

Comments (8)

gkorland avatar gkorland commented on June 18, 2024 2

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.

freestrings avatar freestrings commented on June 18, 2024 1

looks good.

from jsonpath.

gkorland avatar gkorland commented on June 18, 2024

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.

freestrings avatar freestrings commented on June 18, 2024

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.

gkorland avatar gkorland commented on June 18, 2024

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.

freestrings avatar freestrings commented on June 18, 2024

The second example looks better to me.

from jsonpath.

freestrings avatar freestrings commented on June 18, 2024

@gkorland

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.

gkorland avatar gkorland commented on June 18, 2024

I think I prefer to drop this issue for now

from jsonpath.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.