Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get_concurrent values #930

Closed
wants to merge 2 commits into from
Closed

get_concurrent values #930

wants to merge 2 commits into from

Conversation

KM8Oz
Copy link

@KM8Oz KM8Oz commented Sep 11, 2022

/// Similar to `get` method but fast to get deep json Value
    /// ```
    /// # use serde_json::json;
    ///
    /// let object = json!({ "A": { "B": { "C": "foo" } } }); // true
    ///
    /// assert_eq!(*array.get_concurrent("A.B.C").unwrap(), json!("foo")); // true
    /// assert_eq!(*array.get_concurrent("A.B.C.D").unwrap(), json!("foo")); // true also
    /// ```
    pub fn get_concurrent(&self, list: &str) -> Option<Value> {
        let rest: Value = Value::default();
        for item in list.split(".").into_iter() {
            let rest = match self.0.get(item) {
                Some(m) => Some(m),
                None => Some(&self.0),
            };
        }
        Some(rest)
    }

@kangalio
Copy link

I suspect this won't be merged as-is. It is a rather opinionated feature for such a fundamental crate.

Also, it's not ready needed: object["A"]["B"]["C"] works.

@KM8Oz
Copy link
Author

KM8Oz commented May 23, 2023 via email

/// assert_eq!(*array.get_concurrent("A.B.C").unwrap(), json!("foo")); // true
/// assert_eq!(*array.get_concurrent("A.B.C.D").unwrap(), json!("foo")); // true also
/// ```
pub fn get_concurrent<I: &str>(&self, pattern: I) -> Option<Value> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not compile.

error: expected a trait, found type
   --> src/value/mod.rs:317:30
    |
317 |     pub fn get_concurrent<I: &str>(&self, pattern: I) -> Option<Value> {
    |                              ^^^^

/// ```
pub fn get_concurrent<I: &str>(&self, pattern: I) -> Option<Value> {
let rest: Value = Value::default();
for item in list.split(".").into_iter() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not compile.

error[E0425]: cannot find value `list` in this scope
   --> src/value/mod.rs:319:21
    |
319 |         for item in list.split(".").into_iter() {
    |                     ^^^^ not found in this scope

pub fn get_concurrent<I: &str>(&self, pattern: I) -> Option<Value> {
let rest: Value = Value::default();
for item in list.split(".").into_iter() {
let rest = match self.0.get(item) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not compile.

error[E0609]: no field `0` on type `&Value`
   --> src/value/mod.rs:320:35
    |
320 |             let rest = match self.0.get(item) {
    |                                   ^ unknown field

None => Some(&self.0),
};
}
Some(rest)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function would always return Some(Value::Null), which does not seem useful.

@dtolnay
Copy link
Member

dtolnay commented Oct 18, 2024

This looks like an ad-hoc redesign of JSON Pointer (RFC 6901). I would prefer not to include this in serde_Json.

@dtolnay dtolnay closed this Oct 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants