Implement Sizable for both OwnedLiterals and serde_json.
This commit is contained in:
parent
1a54e35736
commit
a6c22417e5
19
src/bin.rs
19
src/bin.rs
@ -316,7 +316,24 @@ impl Loopable for serde_json::Value {
|
||||
|
||||
impl Sizable for serde_json::Value {
|
||||
fn get_size<'a>(&'a self) -> Option<IceResult<'a>> {
|
||||
todo!()
|
||||
match self {
|
||||
serde_json::Value::Null => {
|
||||
Some(IceResult::from_owned(OwnedLiteral::LPositiveInteger(0)))
|
||||
}
|
||||
serde_json::Value::Bool(_boolean) => {
|
||||
Some(IceResult::from_owned(OwnedLiteral::LPositiveInteger(0)))
|
||||
}
|
||||
serde_json::Value::Number(_num) => Some(IceResult::from_borrowed(self)),
|
||||
serde_json::Value::String(text) => Some(IceResult::from_owned(
|
||||
OwnedLiteral::LPositiveInteger(text.len().try_into().unwrap()),
|
||||
)),
|
||||
serde_json::Value::Array(arr) => Some(IceResult::from_owned(
|
||||
OwnedLiteral::LPositiveInteger(arr.len().try_into().unwrap()),
|
||||
)),
|
||||
serde_json::Value::Object(obj) => Some(IceResult::from_owned(
|
||||
OwnedLiteral::LPositiveInteger(obj.len().try_into().unwrap()),
|
||||
)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -21,6 +21,7 @@ use crate::renderer::Walkable;
|
||||
use std::borrow::Borrow;
|
||||
use std::cmp::Ordering;
|
||||
use std::collections::HashMap;
|
||||
use std::convert::TryInto;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct ParametersContext<'a> {
|
||||
@ -192,7 +193,14 @@ impl Walkable for OwnedLiteral {
|
||||
|
||||
impl Sizable for OwnedLiteral {
|
||||
fn get_size<'a>(&'a self) -> Option<IceResult<'a>> {
|
||||
todo!()
|
||||
match self {
|
||||
OwnedLiteral::LFloat(_) => Some(IceResult::from_borrowed(self)),
|
||||
OwnedLiteral::LPositiveInteger(_) => Some(IceResult::from_borrowed(self)),
|
||||
OwnedLiteral::LNegativeInteger(_) => Some(IceResult::from_borrowed(self)),
|
||||
OwnedLiteral::LString(text) => Some(IceResult::from_owned(
|
||||
OwnedLiteral::LPositiveInteger(text.len().try_into().unwrap()),
|
||||
)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user