use super::*;
use get_size2::GetSize;
impl<T> HasLotusJson for Vec<T>
where
T: HasLotusJson + Clone,
{
type LotusJson = Option<Vec<T::LotusJson>>;
#[cfg(test)]
fn snapshots() -> Vec<(serde_json::Value, Self)> {
unimplemented!("only Vec<Cid> is tested, below")
}
fn into_lotus_json(self) -> Self::LotusJson {
match self.is_empty() {
true => None,
false => Some(self.into_iter().map(T::into_lotus_json).collect()),
}
}
fn from_lotus_json(it: Self::LotusJson) -> Self {
match it {
Some(it) => it.into_iter().map(T::from_lotus_json).collect(),
None => vec![],
}
}
}
#[derive(Debug, Clone, Default, PartialEq, JsonSchema, GetSize)]
pub struct NotNullVec<T>(pub Vec<T>);
impl<T> HasLotusJson for NotNullVec<T>
where
T: HasLotusJson + Clone,
{
type LotusJson = Vec<T::LotusJson>;
#[cfg(test)]
fn snapshots() -> Vec<(serde_json::Value, Self)> {
unimplemented!("only Vec<Cid> is tested, below")
}
fn into_lotus_json(self) -> Self::LotusJson {
self.0.into_iter().map(T::into_lotus_json).collect()
}
fn from_lotus_json(it: Self::LotusJson) -> Self {
Self(it.into_iter().map(T::from_lotus_json).collect())
}
}
pub fn deserialize_empty_not_null_opt<'de, T, D>(
deserializer: D,
) -> Result<Option<NotNullVec<T>>, D::Error>
where
T: Deserialize<'de>,
D: Deserializer<'de>,
{
Ok(Option::<Vec<T>>::deserialize(deserializer)?
.filter(|l| !l.is_empty())
.map(NotNullVec))
}
#[test]
fn snapshots() {
assert_one_snapshot(json!([{"/": "baeaaaaa"}]), vec![::cid::Cid::default()]);
}
#[cfg(test)]
#[quickcheck_macros::quickcheck]
fn quickcheck(val: Vec<::cid::Cid>) {
assert_unchanged_via_json(val)
}