Change method name so it doesn’t conflict with std::ops::Add::add

This commit is contained in:
Tobie Morgan Hitchcock 2022-05-04 11:34:17 +01:00
parent f33031ca6b
commit 896e384b98
4 changed files with 16 additions and 16 deletions

View file

@ -73,7 +73,7 @@ impl From<Vec<Part>> for Idiom {
}
impl Idiom {
pub fn add(mut self, n: Part) -> Idiom {
pub fn push(mut self, n: Part) -> Idiom {
self.parts.push(n);
self
}

View file

@ -13,7 +13,7 @@ impl Value {
if !b.value.contains_key(key) {
ops.push(Operation {
op: Op::Remove,
path: path.clone().add(key.clone().into()),
path: path.clone().push(key.clone().into()),
value: Value::Null,
})
}
@ -23,11 +23,11 @@ impl Value {
match a.value.get(key) {
None => ops.push(Operation {
op: Op::Add,
path: path.clone().add(key.clone().into()),
path: path.clone().push(key.clone().into()),
value: val.clone(),
}),
Some(old) => {
let path = path.clone().add(key.clone().into());
let path = path.clone().push(key.clone().into());
ops.append(&mut old.diff(val, path))
}
}
@ -36,7 +36,7 @@ impl Value {
(Value::Array(a), Value::Array(b)) if a != b => {
let mut n = 0;
while n < min(a.len(), b.len()) {
let path = path.clone().add(n.into());
let path = path.clone().push(n.into());
ops.append(&mut a.value[n].diff(&b.value[n], path));
n += 1;
}
@ -44,7 +44,7 @@ impl Value {
if n >= a.len() {
ops.push(Operation {
op: Op::Add,
path: path.clone().add(n.into()),
path: path.clone().push(n.into()),
value: b.value[n].clone(),
})
}
@ -54,7 +54,7 @@ impl Value {
if n >= b.len() {
ops.push(Operation {
op: Op::Remove,
path: path.clone().add(n.into()),
path: path.clone().push(n.into()),
value: Value::Null,
})
}

View file

@ -14,10 +14,10 @@ impl Value {
// Current path part is an object
Value::Object(v) => match p {
Part::Field(f) => match v.value.get(&f.name) {
Some(v) => v._each(path.next(), prev.add(p.clone())),
Some(v) => v._each(path.next(), prev.push(p.clone())),
None => vec![],
},
Part::All => self._each(path.next(), prev.add(p.clone())),
Part::All => self._each(path.next(), prev.push(p.clone())),
_ => vec![],
},
// Current path part is an array
@ -26,25 +26,25 @@ impl Value {
.value
.iter()
.enumerate()
.flat_map(|(i, v)| v._each(path.next(), prev.clone().add(Part::from(i))))
.flat_map(|(i, v)| v._each(path.next(), prev.clone().push(Part::from(i))))
.collect::<Vec<_>>(),
Part::First => match v.value.first() {
Some(v) => v._each(path.next(), prev.add(p.clone())),
Some(v) => v._each(path.next(), prev.push(p.clone())),
None => vec![],
},
Part::Last => match v.value.last() {
Some(v) => v._each(path.next(), prev.add(p.clone())),
Some(v) => v._each(path.next(), prev.push(p.clone())),
None => vec![],
},
Part::Index(i) => match v.value.get(i.to_usize()) {
Some(v) => v._each(path.next(), prev.add(p.clone())),
Some(v) => v._each(path.next(), prev.push(p.clone())),
None => vec![],
},
_ => v
.value
.iter()
.enumerate()
.flat_map(|(i, v)| v._each(path.next(), prev.clone().add(Part::from(i))))
.flat_map(|(i, v)| v._each(path.next(), prev.clone().push(Part::from(i))))
.collect::<Vec<_>>(),
},
// Ignore everything else

View file

@ -12,14 +12,14 @@ impl Value {
Value::Object(v) => v
.value
.iter()
.flat_map(|(k, v)| v._every(prev.clone().add(Part::from(k))))
.flat_map(|(k, v)| v._every(prev.clone().push(Part::from(k))))
.collect::<Vec<_>>(),
// Current path part is an array
Value::Array(v) => v
.value
.iter()
.enumerate()
.flat_map(|(i, v)| v._every(prev.clone().add(Part::from(i))))
.flat_map(|(i, v)| v._every(prev.clone().push(Part::from(i))))
.collect::<Vec<_>>(),
// Process everything else
_ => vec![prev],