From 6c6cb913c33a94b6246d21af1525fad02b5cd3d8 Mon Sep 17 00:00:00 2001 From: Alex Janka Date: Mon, 12 Feb 2024 11:38:19 +1100 Subject: [PATCH] option path --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/lib.rs | 11 +++++++---- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c77ff7f..dd9f99e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1517,7 +1517,7 @@ dependencies = [ [[package]] name = "tesla-common" -version = "0.3.0" +version = "0.3.1" dependencies = [ "ron", "serde", diff --git a/Cargo.toml b/Cargo.toml index 7759697..b2c2943 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "tesla-common" -version = "0.3.0" +version = "0.3.1" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/src/lib.rs b/src/lib.rs index 6a6f216..6b57a90 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -11,11 +11,14 @@ pub struct AuthInfo { } impl AuthInfo { - pub fn save(&self, path: &Path) -> Result, ron::Error> { + pub fn save(&self, path: Option<&Path>) -> Result, ron::Error> { let ser = ron::ser::to_string(self)?; - Ok(std::fs::write(path, ser.clone()) - .map(|_v| None) - .unwrap_or(Some(ser))) + Ok(match path { + Some(path) => std::fs::write(path, ser.clone()) + .map(|_v| None) + .unwrap_or(Some(ser)), + None => Some(ser), + }) } }