Skip to content

Commit

Permalink
Merge pull request rust-num#227 from killercup/docs/pointer-example
Browse files Browse the repository at this point in the history
Add a short example to Value::pointer
  • Loading branch information
dtolnay authored Jan 29, 2017
2 parents 5a9c655 + 494c62b commit 4fd7a35
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions json/src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,21 @@ impl Value {
/// returned.
///
/// For more information read [RFC6901](https://tools.ietf.org/html/rfc6901).
///
/// # Examples
///
/// ```rust
/// # #[macro_use] extern crate serde_json;
/// use serde_json::{Value, from_str};
///
/// # pub fn try_main() -> Result<(), serde_json::Error> {
/// let data: Value = from_str(r#"{"x": {"y": ["z", "zz"]}}"#)?;
///
/// assert_eq!(data.pointer("/x/y/1").unwrap(), &json!("zz"));
/// assert_eq!(data.pointer("/a/b/c"), None);
/// # Ok(()) }
/// # fn main() { try_main().unwrap() }
/// ```
pub fn pointer<'a>(&'a self, pointer: &str) -> Option<&'a Value> {
if pointer == "" {
return Some(self);
Expand Down

0 comments on commit 4fd7a35

Please sign in to comment.