use super::Value;
-use crate::lib::*;
use crate::map::Map;
+use alloc::borrow::ToOwned;
+use alloc::string::String;
+use core::fmt::{self, Display};
+use core::ops;
/// A type that can be used to index into a `serde_json::Value`.
///
impl Index for usize {
fn index_into<'v>(&self, v: &'v Value) -> Option<&'v Value> {
- match *v {
- Value::Array(ref vec) => vec.get(*self),
+ match v {
+ Value::Array(vec) => vec.get(*self),
_ => None,
}
}
fn index_into_mut<'v>(&self, v: &'v mut Value) -> Option<&'v mut Value> {
- match *v {
- Value::Array(ref mut vec) => vec.get_mut(*self),
+ match v {
+ Value::Array(vec) => vec.get_mut(*self),
_ => None,
}
}
fn index_or_insert<'v>(&self, v: &'v mut Value) -> &'v mut Value {
- match *v {
- Value::Array(ref mut vec) => {
+ match v {
+ Value::Array(vec) => {
let len = vec.len();
vec.get_mut(*self).unwrap_or_else(|| {
panic!(
impl Index for str {
fn index_into<'v>(&self, v: &'v Value) -> Option<&'v Value> {
- match *v {
- Value::Object(ref map) => map.get(self),
+ match v {
+ Value::Object(map) => map.get(self),
_ => None,
}
}
fn index_into_mut<'v>(&self, v: &'v mut Value) -> Option<&'v mut Value> {
- match *v {
- Value::Object(ref mut map) => map.get_mut(self),
+ match v {
+ Value::Object(map) => map.get_mut(self),
_ => None,
}
}
fn index_or_insert<'v>(&self, v: &'v mut Value) -> &'v mut Value {
- if let Value::Null = *v {
+ if let Value::Null = v {
*v = Value::Object(Map::new());
}
- match *v {
- Value::Object(ref mut map) => map.entry(self.to_owned()).or_insert(Value::Null),
+ match v {
+ Value::Object(map) => map.entry(self.to_owned()).or_insert(Value::Null),
_ => panic!("cannot access key {:?} in JSON {}", self, Type(v)),
}
}
pub trait Sealed {}
impl Sealed for usize {}
impl Sealed for str {}
- impl Sealed for super::String {}
+ impl Sealed for alloc::string::String {}
impl<'a, T> Sealed for &'a T where T: ?Sized + Sealed {}
}
/// Used in panic messages.
struct Type<'a>(&'a Value);
-impl<'a> fmt::Display for Type<'a> {
+impl<'a> Display for Type<'a> {
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
match *self.0 {
Value::Null => formatter.write_str("null"),