diff --git a/Cargo.toml b/Cargo.toml index 45d1bea..a56fa2a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "json" -version = "0.8.6" +version = "0.8.7" authors = ["Maciej Hirsz "] description = "JSON implementation in Rust" repository = "https://github.com/maciejhirsz/json-rust" diff --git a/src/iterators.rs b/src/iterators.rs index c8d7b0d..a798220 100644 --- a/src/iterators.rs +++ b/src/iterators.rs @@ -1,6 +1,6 @@ use std::collections::btree_map; use std::slice; -use std::iter::{Iterator, DoubleEndedIterator}; +use std::iter::{ Iterator, DoubleEndedIterator }; use JsonValue; pub enum Members<'a> { diff --git a/src/value.rs b/src/value.rs index 55b5163..62f92d3 100644 --- a/src/value.rs +++ b/src/value.rs @@ -2,7 +2,7 @@ use std::collections::BTreeMap; use std::ops::{ Index, IndexMut, Deref }; use iterators::{ Members, MembersMut, Entries, EntriesMut }; use { JsonResult, JsonError }; -use std::{ usize, u8, u16, u32, u64, isize, i8, i16, i32, i64, f32 }; +use std::{ mem, usize, u8, u16, u32, u64, isize, i8, i16, i32, i64, f32 }; macro_rules! f64_to_unsinged { ($unsigned:ident, $value:expr) => { @@ -175,6 +175,29 @@ impl JsonValue { } } + /// Take over the ownership of the value, leaving `Null` in it's place. + /// + /// ## Example + /// + /// ``` + /// # #[macro_use] extern crate json; + /// # fn main() { + /// let mut data = array!["Foo", 42]; + /// + /// let first = data[0].take(); + /// let second = data[1].take(); + /// + /// assert!(first == "Foo"); + /// assert!(second == 42); + /// + /// assert!(data[0].is_null()); + /// assert!(data[1].is_null()); + /// # } + /// ``` + pub fn take(&mut self) -> JsonValue { + mem::replace(self, JsonValue::Null) + } + /// Works on `JsonValue::Array` - pushes a new value to the array. #[must_use] pub fn push(&mut self, value: T) -> JsonResult<()> @@ -290,6 +313,8 @@ impl JsonValue { /// Implements indexing by `usize` to easily access array members: /// +/// ## Example +/// /// ``` /// # use json::JsonValue; /// let mut array = JsonValue::new_array(); @@ -311,6 +336,8 @@ impl Index for JsonValue { /// Implements mutable indexing by `usize` to easily modify array members: /// +/// ## Example +/// /// ``` /// # #[macro_use] /// # extern crate json; @@ -347,6 +374,8 @@ impl IndexMut for JsonValue { /// Implements indexing by `&str` to easily access object members: /// +/// ## Example +/// /// ``` /// # #[macro_use] /// # extern crate json; @@ -391,6 +420,8 @@ impl<'a> Index<&'a String> for JsonValue { /// Implements mutable indexing by `&str` to easily modify object members: /// +/// ## Example +/// /// ``` /// # #[macro_use] /// # extern crate json;