We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
fn main() { let obj = b"{\"key\":\"Small JSON-file with object.\"}"; let mut json_obj_repr: serde_json::Value = serde_json::from_slice(obj).unwrap(); let missing_key = json_obj_repr["Hello World!"].take(); println!("From object I took {:?}", missing_key); let string = b"\"There is just a string in valid JSON-file.\""; let mut json_str_repr: serde_json::Value = serde_json::from_slice(string).unwrap(); let invalid_operation = json_str_repr["Hello World!"].take(); println!("Never reach this {:?}", invalid_operation); }
println!
Shows that taking from missing key returns Value::Null variant. And this is what we all expect from Value::take(&mut self).
Value::take(&mut self)
take()
thread 'main' panicked at /home/user/.cargo/registry/src/index.crates.io-6f17d22bba15001f/serde_json-1.0.135/src/value/index.rs:102:18: cannot access key "Hello World!" in JSON string
And second println! is never reached.
My toolchain is stable-x86_64-unknown-linux-gnu - rustc 1.84.0 (9fc6b4312 2025-01-07).
stable-x86_64-unknown-linux-gnu - rustc 1.84.0 (9fc6b4312 2025-01-07)
The text was updated successfully, but these errors were encountered:
No branches or pull requests
I have a code like this
First
println!
Shows that taking from missing key returns Value::Null variant. And this is what we all expect from
Value::take(&mut self)
.Second
take()
panicsAnd second
println!
is never reached.My toolchain is
stable-x86_64-unknown-linux-gnu - rustc 1.84.0 (9fc6b4312 2025-01-07)
.The text was updated successfully, but these errors were encountered: