fix: deserialize url null value w/ default if backend: huggingface (#75)

This commit is contained in:
Luc Georges 2024-02-12 20:07:59 +01:00 committed by GitHub
parent 86043ce3af
commit 4437c0c8a6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -46,7 +46,14 @@ fn parse_ide<'de, D>(d: D) -> std::result::Result<Ide, D::Error>
where
D: Deserializer<'de>,
{
Deserialize::deserialize(d).map(|b: Option<_>| b.unwrap_or(Ide::Unknown))
Option::deserialize(d).map(|b| b.unwrap_or_default())
}
fn parse_url<'de, D>(d: D) -> std::result::Result<String, D::Error>
where
D: Deserializer<'de>,
{
Option::deserialize(d).map(|b| b.unwrap_or_else(hf_default_url))
}
fn hf_default_url() -> String {
@ -57,7 +64,7 @@ fn hf_default_url() -> String {
#[serde(rename_all = "lowercase", tag = "backend")]
pub enum Backend {
HuggingFace {
#[serde(default = "hf_default_url")]
#[serde(default = "hf_default_url", deserialize_with = "parse_url")]
url: String,
},
// TODO: