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 { impl Idiom {
pub fn add(mut self, n: Part) -> Idiom { pub fn push(mut self, n: Part) -> Idiom {
self.parts.push(n); self.parts.push(n);
self self
} }

View file

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

View file

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

View file

@ -12,14 +12,14 @@ impl Value {
Value::Object(v) => v Value::Object(v) => v
.value .value
.iter() .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<_>>(), .collect::<Vec<_>>(),
// Current path part is an array // Current path part is an array
Value::Array(v) => v Value::Array(v) => v
.value .value
.iter() .iter()
.enumerate() .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<_>>(), .collect::<Vec<_>>(),
// Process everything else // Process everything else
_ => vec![prev], _ => vec![prev],