Skip to content

Commit

Permalink
fix: deserialize url null value w/ default if backend: huggingface (
Browse files Browse the repository at this point in the history
  • Loading branch information
McPatate authored Feb 12, 2024
1 parent 86043ce commit 4437c0c
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions crates/custom-types/src/llm_ls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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:
Expand Down

0 comments on commit 4437c0c

Please sign in to comment.