mirror of
https://gitlab.com/gabmus/envision.git
synced 2025-04-19 19:14:53 +00:00
fix: wivrn config can have unrecognized fields, they will be ignored and reserialized
This commit is contained in:
parent
5fe4524e83
commit
a9d59172fc
2 changed files with 15 additions and 1 deletions
|
@ -3,6 +3,7 @@ use crate::{
|
|||
xdg::XDG,
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::{Map, Value};
|
||||
use std::{
|
||||
fmt::Display,
|
||||
path::{Path, PathBuf},
|
||||
|
@ -92,6 +93,9 @@ pub struct WivrnConfEncoder {
|
|||
pub offset_y: Option<f32>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub group: Option<i32>,
|
||||
/// contains unknown fields
|
||||
#[serde(flatten)]
|
||||
other: Map<String, Value>,
|
||||
}
|
||||
|
||||
impl Default for WivrnConfEncoder {
|
||||
|
@ -104,6 +108,7 @@ impl Default for WivrnConfEncoder {
|
|||
offset_x: Some(0.0),
|
||||
offset_y: Some(0.0),
|
||||
group: None,
|
||||
other: Map::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -129,6 +134,9 @@ pub struct WivrnConfig {
|
|||
pub application: Option<WivrnConfigApplication>,
|
||||
#[serde(default)]
|
||||
pub tcp_only: bool,
|
||||
/// contains unknown fields
|
||||
#[serde(flatten)]
|
||||
other: Map<String, Value>,
|
||||
}
|
||||
|
||||
impl Default for WivrnConfig {
|
||||
|
@ -139,6 +147,7 @@ impl Default for WivrnConfig {
|
|||
encoders: vec![],
|
||||
application: None,
|
||||
tcp_only: false,
|
||||
other: Map::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -190,6 +199,9 @@ mod tests {
|
|||
Some(WivrnConfigApplication::Str("foobar".into()))
|
||||
);
|
||||
assert!(!conf.tcp_only);
|
||||
assert!(serde_json::to_string(&conf)
|
||||
.unwrap()
|
||||
.contains("\"extraneous\":\"field\",\"other\":{\"weird\":[\"stuff\"]}"));
|
||||
let conf = get_wivrn_config_from_path(Path::new("./test/files/wivrn_config2.json"))
|
||||
.expect("Couln't find wivrn config 2");
|
||||
assert_eq!(
|
||||
|
|
|
@ -11,5 +11,7 @@
|
|||
"offset_y": 0.0
|
||||
}
|
||||
],
|
||||
"application": "foobar"
|
||||
"application": "foobar",
|
||||
"extraneous": "field",
|
||||
"other": {"weird": ["stuff"]}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue