use super::*;
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, PartialEq, JsonSchema)]
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())
}
}
#[test]
fn snapshots() {
assert_one_snapshot(json!([{"/": "baeaaaaa"}]), vec![::cid::Cid::default()]);
}
#[cfg(test)]
quickcheck! {
fn quickcheck(val: Vec<::cid::Cid>) -> () {
assert_unchanged_via_json(val)
}
}