Skip to content

Commit

Permalink
device_add constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
arcnmx committed Mar 13, 2018
1 parent 86d5b9d commit 0a6d8c2
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions qmp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ extern crate serde;
#[macro_use]
extern crate serde_derive;

use std::string;

include!(concat!(env!("OUT_DIR"), "/qmp.rs"));

#[derive(Debug, Clone, Serialize, Deserialize)]
Expand All @@ -17,3 +19,19 @@ pub struct QMP {
pub struct QapiCapabilities {
pub QMP: QMP,
}

impl device_add {
pub fn new(driver: string::String, id: Option<string::String>, bus: Option<string::String>, props: qapi::Dictionary) -> Self {
let mut dict = qapi::Dictionary::default();
dict.insert("driver".into(), qapi::Any::String(driver));
if let Some(id) = id {
dict.insert("id".into(), qapi::Any::String(id));
}
if let Some(bus) = bus {
dict.insert("bus".into(), qapi::Any::String(bus));
}
dict.extend(props.into_iter());

device_add(dict)
}
}

0 comments on commit 0a6d8c2

Please sign in to comment.