feat: add video details response model

- add paginator, impl for playlist items
- small model refactor
- add ignore_any deserializer
- removed unnecessary clones in response mapping
This commit is contained in:
ThetaDev 2022-09-19 00:08:37 +02:00
parent 17b6844eb0
commit 972288d810
32 changed files with 61791 additions and 5316 deletions

View file

@ -8,6 +8,8 @@ pub use vec_log_err::VecLogError;
use std::fmt::Debug;
use serde::{de::IgnoredAny, Deserializer};
/// This represents a result from a deserializing/mapping operation.
/// It holds the desired content (`c`) and a list of warning messages,
/// if there occurred minor error during the deserializing or mapping
@ -38,3 +40,59 @@ where
}
}
}
/// Deserialization method that consumes anything and returns an empty value.
/// Intended to be used for a wildcard enum option.
///
/// Example:
/// ```rs
/// #[derive(Deserialize)]
/// enum Fruit {
/// Apple {
/// red: bool,
/// },
/// Banana {
/// yellow: bool,
/// },
/// #[serde(other, deserialize_with = "deserialize_blackhole")]
/// None,
/// }
/// ```
pub fn ignore_any<'de, D>(deserializer: D) -> Result<(), D::Error>
where
D: Deserializer<'de>,
{
deserializer.deserialize_ignored_any(IgnoredAny).and(Ok(()))
}
#[cfg(test)]
mod tests {
use serde::Deserialize;
use super::*;
#[derive(Debug, Deserialize, PartialEq)]
enum E {
Apple {
red: bool,
},
Banana {
yellow: bool,
},
#[serde(other, deserialize_with = "ignore_any")]
None,
}
#[test]
fn t_ignore_any() {
assert_eq!(
serde_json::from_str::<E>(r#"{"Apple": {"red": true}}"#).unwrap(),
E::Apple { red: true }
);
assert_eq!(
serde_json::from_str::<E>(r#"{"Lemon": {"yellow": true}}"#).unwrap(),
E::None
);
assert!(serde_json::from_str::<E>(r#"{"Apple": {"yellow": true}}"#).is_err());
}
}