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