Created
February 6, 2019 07:53
-
-
Save andreastt/94ed241ef96cffa64320bef57fdc57ac to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extern crate serde; // 1.0.85 | |
extern crate serde_json; // 1.0.37 | |
use serde::{Deserialize, Serialize}; | |
//use serde_json::{Map, Value}; | |
//type Capabilities = Map<String, Value>; | |
trait DriverCapabilities { | |
fn browser_name() -> String; | |
} | |
struct FirefoxCapabilities; | |
impl DriverCapabilities for FirefoxCapabilities { | |
fn browser_name() -> String { | |
"firefox".to_string() | |
} | |
} | |
#[derive(Debug, Serialize, Deserialize)] | |
#[serde(rename_all = "camelCase")] | |
struct NewSessionParameters { | |
always_match: Option<Capabilities<DriverCapabilities>>, | |
first_match: Option<Vec<Capabilities<DriverCapabilities>>>, | |
} | |
#[derive(Debug, Serialize, Deserialize)] | |
struct Capabilities<DriverCapabilities> { | |
#[serde(rename = "browserName", default = "DriverCapabilities::browser_name")] | |
browser_name: String, | |
} | |
fn main() -> Result<(), std::io::Error> { | |
let body = r#" | |
{ | |
"alwaysMatch": {"foo": "bar"}, | |
"firstMatch": [ | |
{}, | |
{} | |
] | |
} | |
"#; | |
let params: NewSessionParameters<FirefoxCapabilities> = serde_json::from_str(body)?; | |
dbg!(params); | |
Ok(()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment