Skip to content

Commit

Permalink
Merge pull request #61 from maciejhirsz/0.8.7
Browse files Browse the repository at this point in the history
0.8.7 the `take` method
  • Loading branch information
maciejhirsz authored Jul 7, 2016
2 parents dd1fae5 + f5dfea1 commit bbef847
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "json"
version = "0.8.6"
version = "0.8.7"
authors = ["Maciej Hirsz <maciej.hirsz@gmail.com>"]
description = "JSON implementation in Rust"
repository = "https://github.com/maciejhirsz/json-rust"
Expand Down
2 changes: 1 addition & 1 deletion src/iterators.rs
Original file line number Diff line number Diff line change
@@ -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> {
Expand Down
33 changes: 32 additions & 1 deletion src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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<T>(&mut self, value: T) -> JsonResult<()>
Expand Down Expand Up @@ -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();
Expand All @@ -311,6 +336,8 @@ impl Index<usize> for JsonValue {

/// Implements mutable indexing by `usize` to easily modify array members:
///
/// ## Example
///
/// ```
/// # #[macro_use]
/// # extern crate json;
Expand Down Expand Up @@ -347,6 +374,8 @@ impl IndexMut<usize> for JsonValue {

/// Implements indexing by `&str` to easily access object members:
///
/// ## Example
///
/// ```
/// # #[macro_use]
/// # extern crate json;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit bbef847

Please sign in to comment.