Fix fallout of DSTifying PartialEq, PartialOrd, Eq, Ord
This commit is contained in:
parent
2896278313
commit
1e5f311d16
9 changed files with 172 additions and 0 deletions
|
@ -890,6 +890,8 @@ impl Json {
|
|||
|
||||
/// If the Json value is an Object, returns the value associated with the provided key.
|
||||
/// Otherwise, returns None.
|
||||
// NOTE(stage0): remove function after a snapshot
|
||||
#[cfg(stage0)]
|
||||
pub fn find<'a>(&'a self, key: &str) -> Option<&'a Json>{
|
||||
match self {
|
||||
&Object(ref map) => map.find_with(|s| key.cmp(&s.as_slice())),
|
||||
|
@ -897,6 +899,16 @@ impl Json {
|
|||
}
|
||||
}
|
||||
|
||||
/// If the Json value is an Object, returns the value associated with the provided key.
|
||||
/// Otherwise, returns None.
|
||||
#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot
|
||||
pub fn find<'a>(&'a self, key: &str) -> Option<&'a Json>{
|
||||
match self {
|
||||
&Object(ref map) => map.find_with(|s| key.cmp(s.as_slice())),
|
||||
_ => None
|
||||
}
|
||||
}
|
||||
|
||||
/// Attempts to get a nested Json Object for each key in `keys`.
|
||||
/// If any key is found not to exist, find_path will return None.
|
||||
/// Otherwise, it will return the Json value associated with the final key.
|
||||
|
@ -914,6 +926,8 @@ impl Json {
|
|||
/// If the Json value is an Object, performs a depth-first search until
|
||||
/// a value associated with the provided key is found. If no value is found
|
||||
/// or the Json value is not an Object, returns None.
|
||||
// NOTE(stage0): remove function after a snapshot
|
||||
#[cfg(stage0)]
|
||||
pub fn search<'a>(&'a self, key: &str) -> Option<&'a Json> {
|
||||
match self {
|
||||
&Object(ref map) => {
|
||||
|
@ -934,6 +948,30 @@ impl Json {
|
|||
}
|
||||
}
|
||||
|
||||
/// If the Json value is an Object, performs a depth-first search until
|
||||
/// a value associated with the provided key is found. If no value is found
|
||||
/// or the Json value is not an Object, returns None.
|
||||
#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot
|
||||
pub fn search<'a>(&'a self, key: &str) -> Option<&'a Json> {
|
||||
match self {
|
||||
&Object(ref map) => {
|
||||
match map.find_with(|s| key.cmp(s.as_slice())) {
|
||||
Some(json_value) => Some(json_value),
|
||||
None => {
|
||||
for (_, v) in map.iter() {
|
||||
match v.search(key) {
|
||||
x if x.is_some() => return x,
|
||||
_ => ()
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
}
|
||||
},
|
||||
_ => None
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns true if the Json value is an Object. Returns false otherwise.
|
||||
pub fn is_object<'a>(&'a self) -> bool {
|
||||
self.as_object().is_some()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue