You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm building a program that takes URLs and strips all the tracking parameters and handles redirects and so on. One of the mappers is ExpandShortLink, which just sends a request to the URL being cleaned and returns the URL the server responded with.
I'm trying to support the case where a user wants to specify HTTP headers for a specific ExpandShortLink without requiring that all uses of ExpandShortLink have a default header map (I expect it to be a niche feature).
Basically, I have this code:
use serde::Deserialize;use serde_json::from_str;use std::collections::HashMap;#[derive(Deserialize)]structRule{// ...mapper:Mapper}#[derive(Deserialize)]enumMapper{// ...ExpandShortLink{#[serde(default)]headers:HashMap<String,String>}}fnmain(){assert!(from_str::<Rule>("{\"mapper\": {\"ExpandShortLink\": {\"headers\": {}}}}").is_ok());assert!(from_str::<Rule>("{\"mapper\": \"ExpandShortLink\"}").is_ok());}
I would like to have {"mapper": "ExpandShortLink"} and {"mapper": {"ExpandShortLink": {"headers": {}}}} both deserialize to Rule {mapper: Mapper::ExpandShortLink {headers: HashMap::new()}}.