Compare commits
No commits in common. "9a652d851fa962183e60b11cbb4e34477a979aac" and "e0124894732a9dd3bd6390b54cb3e087d05dce51" have entirely different histories.
9a652d851f
...
e012489473
2 changed files with 20 additions and 14 deletions
|
@ -3,7 +3,7 @@ use std::convert::TryFrom;
|
|||
use once_cell::sync::Lazy;
|
||||
use regex::Regex;
|
||||
use serde::{Deserialize, Deserializer};
|
||||
use serde_with::{serde_as, DefaultOnError, DeserializeAs, VecSkipError};
|
||||
use serde_with::{serde_as, DeserializeAs, VecSkipError};
|
||||
|
||||
use crate::{
|
||||
client::response::url_endpoint::{
|
||||
|
@ -122,13 +122,10 @@ struct RichTextInternal {
|
|||
}
|
||||
|
||||
/// TextLinkRun is a single component from a YouTube text with links
|
||||
#[serde_as]
|
||||
#[derive(Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct RichTextRun {
|
||||
text: String,
|
||||
#[serde(default)]
|
||||
#[serde_as(as = "DefaultOnError")]
|
||||
navigation_endpoint: Option<NavigationEndpoint>,
|
||||
}
|
||||
|
||||
|
|
|
@ -20,6 +20,13 @@ where
|
|||
where
|
||||
D: serde::Deserializer<'de>,
|
||||
{
|
||||
#[derive(serde::Deserialize)]
|
||||
#[serde(untagged)]
|
||||
enum GoodOrError<T> {
|
||||
Good(T),
|
||||
Error(serde_json::Value),
|
||||
}
|
||||
|
||||
struct SeqVisitor<T>(PhantomData<T>);
|
||||
|
||||
impl<'de, T> Visitor<'de> for SeqVisitor<T>
|
||||
|
@ -39,14 +46,16 @@ where
|
|||
let mut values = Vec::with_capacity(seq.size_hint().unwrap_or_default());
|
||||
let mut warnings = Vec::new();
|
||||
|
||||
loop {
|
||||
match seq.next_element::<T>() {
|
||||
Ok(val) => match val {
|
||||
Some(val) => values.push(val),
|
||||
None => break,
|
||||
},
|
||||
Err(e) => {
|
||||
warnings.push(format!("error deserializing item: {e}"));
|
||||
while let Some(value) = seq.next_element()? {
|
||||
match value {
|
||||
GoodOrError::<T>::Good(value) => {
|
||||
values.push(value);
|
||||
}
|
||||
GoodOrError::<T>::Error(value) => {
|
||||
warnings.push(format!(
|
||||
"error deserializing item: {}",
|
||||
serde_json::to_string(&value).unwrap_or_default()
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -177,8 +186,8 @@ mod tests {
|
|||
|
||||
insta::assert_debug_snapshot!(res.items.warnings, @r###"
|
||||
[
|
||||
"error deserializing item: missing field `name` at line 1 column 40",
|
||||
"error deserializing item: missing field `name` at line 1 column 73",
|
||||
"error deserializing item: {\"xyz\":\"i2\"}",
|
||||
"error deserializing item: {\"namra\":\"i4\"}",
|
||||
]
|
||||
"###);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue