Function cargo_toml2::to_path

source ·
pub fn to_path<T: AsRef<Path>, R: Serialize>(
    path: T,
    save: R
) -> Result<(), CargoTomlError>
Expand description

Writes a serializable struct to the file at path.

Examples

Re-serializing

// Writing a CargoToml
let toml: CargoToml = from_path("Cargo.toml").expect("Failed to read Cargo.toml");
to_path("Test.toml", toml).expect("Failed to serialize/write CargoToml");

Creating a new Cargo.toml

let toml = CargoToml {
   package: Package {
       name: "Example".into(),
       version: "0.1.0".into(),
       authors: vec!["Namey McNameface".into()],
       ..Default::default()
   },
   ..Default::default()
};
to_path("Test.toml", toml).expect("Failed to serialize/write CargoToml");

Errors

If writing to the provided path fails, or serialization fails.