-
Notifications
You must be signed in to change notification settings - Fork 216
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: use toml-span for deserialization (#2718)
Co-authored-by: Julian Hofer <julianhofer@gnome.org>
- Loading branch information
1 parent
82fc219
commit 537739c
Showing
111 changed files
with
4,129 additions
and
1,214 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,52 @@ | ||
use indexmap::IndexMap; | ||
use serde::Deserialize; | ||
use toml_span::{de_helpers::TableHelper, DeserError, Value}; | ||
|
||
#[derive(Default, Clone, Deserialize, Debug)] | ||
#[serde(deny_unknown_fields)] | ||
use pixi_toml::TomlIndexMap; | ||
|
||
#[derive(Default, Clone, Debug)] | ||
pub struct Activation { | ||
pub scripts: Option<Vec<String>>, | ||
/// Environment variables to set before running the scripts. | ||
pub env: Option<IndexMap<String, String>>, | ||
} | ||
|
||
impl<'de> toml_span::Deserialize<'de> for Activation { | ||
fn deserialize(value: &mut Value<'de>) -> Result<Self, DeserError> { | ||
let mut th = TableHelper::new(value)?; | ||
let scripts = th.optional("scripts"); | ||
let env = th.optional::<TomlIndexMap<_, _>>("env"); | ||
th.finalize(None)?; | ||
Ok(Activation { | ||
scripts, | ||
env: env.map(TomlIndexMap::into_inner), | ||
}) | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod test { | ||
use super::*; | ||
use crate::toml::FromTomlStr; | ||
|
||
#[test] | ||
fn deserialize_activation() { | ||
let input = r#" | ||
scripts = ["echo 'Hello, World!'"] | ||
[env] | ||
FOO = "bar" | ||
"#; | ||
|
||
let activation = Activation::from_toml_str(input).unwrap(); | ||
assert_eq!( | ||
activation.scripts, | ||
Some(vec!["echo 'Hello, World!'".to_string()]) | ||
); | ||
assert_eq!( | ||
activation.env, | ||
Some(IndexMap::from_iter(vec![( | ||
"FOO".to_string(), | ||
"bar".to_string() | ||
)])) | ||
); | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.