mirror of
https://gitlab.com/gabmus/envision.git
synced 2025-08-03 06:38:52 +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,
|
xdg::XDG,
|
||||||
};
|
};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
use serde_json::{Map, Value};
|
||||||
use std::{
|
use std::{
|
||||||
fmt::Display,
|
fmt::Display,
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
|
@ -92,6 +93,9 @@ pub struct WivrnConfEncoder {
|
||||||
pub offset_y: Option<f32>,
|
pub offset_y: Option<f32>,
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
pub group: Option<i32>,
|
pub group: Option<i32>,
|
||||||
|
/// contains unknown fields
|
||||||
|
#[serde(flatten)]
|
||||||
|
other: Map<String, Value>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for WivrnConfEncoder {
|
impl Default for WivrnConfEncoder {
|
||||||
|
@ -104,6 +108,7 @@ impl Default for WivrnConfEncoder {
|
||||||
offset_x: Some(0.0),
|
offset_x: Some(0.0),
|
||||||
offset_y: Some(0.0),
|
offset_y: Some(0.0),
|
||||||
group: None,
|
group: None,
|
||||||
|
other: Map::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -129,6 +134,9 @@ pub struct WivrnConfig {
|
||||||
pub application: Option<WivrnConfigApplication>,
|
pub application: Option<WivrnConfigApplication>,
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub tcp_only: bool,
|
pub tcp_only: bool,
|
||||||
|
/// contains unknown fields
|
||||||
|
#[serde(flatten)]
|
||||||
|
other: Map<String, Value>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for WivrnConfig {
|
impl Default for WivrnConfig {
|
||||||
|
@ -139,6 +147,7 @@ impl Default for WivrnConfig {
|
||||||
encoders: vec![],
|
encoders: vec![],
|
||||||
application: None,
|
application: None,
|
||||||
tcp_only: false,
|
tcp_only: false,
|
||||||
|
other: Map::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -190,6 +199,9 @@ mod tests {
|
||||||
Some(WivrnConfigApplication::Str("foobar".into()))
|
Some(WivrnConfigApplication::Str("foobar".into()))
|
||||||
);
|
);
|
||||||
assert!(!conf.tcp_only);
|
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"))
|
let conf = get_wivrn_config_from_path(Path::new("./test/files/wivrn_config2.json"))
|
||||||
.expect("Couln't find wivrn config 2");
|
.expect("Couln't find wivrn config 2");
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
|
|
@ -11,5 +11,7 @@
|
||||||
"offset_y": 0.0
|
"offset_y": 0.0
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"application": "foobar"
|
"application": "foobar",
|
||||||
|
"extraneous": "field",
|
||||||
|
"other": {"weird": ["stuff"]}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue