From 9b2864bd70e7bff52f4f0bbdfbe0e2164d286063 Mon Sep 17 00:00:00 2001 From: aviac Date: Fri, 10 May 2024 09:00:27 +0200 Subject: feat: naive implementation of ssh_url deserialization --- src/lib.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'src/lib.rs') diff --git a/src/lib.rs b/src/lib.rs index 90d1137..c86ef64 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,5 @@ use reqwest::{Client, Request, StatusCode}; +use serde::{Deserialize, Deserializer}; use soft_assert::*; use url::Url; use zeroize::Zeroize; @@ -254,6 +255,31 @@ fn none_if_blank_url<'de, D: serde::Deserializer<'de>>( deserializer.deserialize_str(EmptyUrlVisitor) } +#[allow(dead_code)] // not used yet, but it might appear in the future +fn deserialize_ssh_url<'de, D, DE>(deserializer: D) -> Result +where + D: Deserializer<'de>, + DE: serde::de::Error, +{ + let raw_url: String = String::deserialize(deserializer).map_err(DE::custom)?; + let url = format!("ssh://{url}", url = raw_url.replace(":", "/")); + Url::parse(url.as_str()).map_err(DE::custom) +} + +fn deserialize_optional_ssh_url<'de, D, DE>(deserializer: D) -> Result, DE> +where + D: Deserializer<'de>, + DE: serde::de::Error, +{ + let raw_url: Option = Option::deserialize(deserializer).map_err(DE::custom)?; + raw_url + .map(|raw_url| { + let url = format!("ssh://{url}", url = raw_url.replace(":", "/")); + Url::parse(url.as_str()).map_err(DE::custom).map(Some) + }) + .unwrap_or(Ok(None)) +} + impl From for structs::MergePullRequestOptionDo { fn from(value: structs::DefaultMergeStyle) -> Self { match value { -- cgit v1.2.3