Special cases of refs to data (#41)

1. Numeric indices will be converted to strings for refs beginning with `data`
   if there is not valid numeric key
2. Error out if input document already contains value for a ref

Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com>
This commit is contained in:
Anand Krishnamoorthi
2023-11-11 00:15:56 -08:00
committed by GitHub
parent 02c6c6b827
commit 1c492144b3
6 changed files with 164 additions and 87 deletions
+4 -1
View File
@@ -331,6 +331,9 @@ impl Value {
}
pub fn merge(&mut self, mut new: Value) -> Result<()> {
if self == &new {
return Ok(());
}
match (self, &mut new) {
(v @ Value::Undefined, _) => *v = new,
(Value::Set(ref mut set), Value::Set(new)) => {
@@ -351,7 +354,7 @@ impl Value {
};
}
}
_ => bail!("internal error: could not merge value"),
_ => bail!("error: could not merge value"),
};
Ok(())
}