Skip to content

Commit

Permalink
Update serde_yaml to 0.9.34
Browse files Browse the repository at this point in the history
  • Loading branch information
banool committed Jun 14, 2024
1 parent 69d29a1 commit 2a9057f
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 27 deletions.
50 changes: 25 additions & 25 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,7 @@ serde-name = "0.1.1"
serde-generate = { git = "https://github.com/aptos-labs/serde-reflection", rev = "73b6bbf748334b71ff6d7d09d06a29e3062ca075" }
serde-reflection = { git = "https://github.com/aptos-labs/serde-reflection", rev = "73b6bbf748334b71ff6d7d09d06a29e3062ca075" }
serde_with = "3.4.0"
serde_yaml = "0.8.24"
serde_yaml = "0.9.34"
shadow-rs = "0.16.2"
simplelog = "0.9.0"
smallbitvec = "2.5.1"
Expand Down
18 changes: 17 additions & 1 deletion config/src/config/persistable_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub trait PersistableConfig: Serialize + DeserializeOwned {
/// Save the config to disk at the given output path
fn save_config<P: AsRef<Path>>(&self, output_file: P) -> Result<(), Error> {
// Serialize the config to a string
let serialized_config = serde_yaml::to_vec(&self)
let serialized_config = serde_yaml_to_vec(&self)
.map_err(|e| Error::Yaml(output_file.as_ref().to_str().unwrap().to_string(), e))?;

Self::write_file(serialized_config, output_file)
Expand Down Expand Up @@ -58,3 +58,19 @@ pub trait PersistableConfig: Serialize + DeserializeOwned {
// We only implement PersistableConfig for the configs that should be read/written to disk
impl PersistableConfig for NodeConfig {}
impl PersistableConfig for SafetyRulesConfig {}

/// Serialize the given data structure as a YAML byte vector.
///
/// Serialization can fail if `T`'s implementation of `Serialize` decides to
/// return an error.
///
/// serde_yaml 0.9.x doesn't have this function so we reimplement it here as it existed
/// in serde_yaml 0.8.x.
pub fn serde_yaml_to_vec<T: ?Sized>(value: &T) -> serde_yaml::Result<Vec<u8>>
where
T: serde::ser::Serialize,
{
let mut vec = Vec::with_capacity(128);
serde_yaml::to_writer(&mut vec, value)?;
Ok(vec)
}

0 comments on commit 2a9057f

Please sign in to comment.