Deserialize YAML into a `serde_json::Map`, bounding both the number of * nodes and the total size of materialized strings so that anchor/alias * expansion cannot exhaust memory. */
(bytes: &[u8])
| 20 | * nodes and the total size of materialized strings so that anchor/alias |
| 21 | * expansion cannot exhaust memory. */ |
| 22 | pub fn from_slice(bytes: &[u8]) -> Result<Map<String, Value>, serde_yaml_ng::Error> { |
| 23 | let nodes = Cell::new(0); |
| 24 | let byte_count = Cell::new(0); |
| 25 | let budget = Budget { |
| 26 | nodes: &nodes, |
| 27 | bytes: &byte_count, |
| 28 | }; |
| 29 | let value = BoundedValue { budget } |
| 30 | .deserialize(serde_yaml_ng::Deserializer::from_slice(bytes))?; |
| 31 | match value { |
| 32 | Value::Object(map) => Ok(map), |
| 33 | _ => Err(serde_yaml_ng::Error::custom( |
| 34 | "expected a mapping at the top level", |
| 35 | )), |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | #[derive(Clone, Copy)] |
| 40 | struct Budget<'a> { |