option path
This commit is contained in:
parent
cd100ca7fe
commit
6c6cb913c3
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -1517,7 +1517,7 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tesla-common"
|
name = "tesla-common"
|
||||||
version = "0.3.0"
|
version = "0.3.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"ron",
|
"ron",
|
||||||
"serde",
|
"serde",
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "tesla-common"
|
name = "tesla-common"
|
||||||
version = "0.3.0"
|
version = "0.3.1"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
11
src/lib.rs
11
src/lib.rs
|
@ -11,11 +11,14 @@ pub struct AuthInfo {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AuthInfo {
|
impl AuthInfo {
|
||||||
pub fn save(&self, path: &Path) -> Result<Option<String>, ron::Error> {
|
pub fn save(&self, path: Option<&Path>) -> Result<Option<String>, ron::Error> {
|
||||||
let ser = ron::ser::to_string(self)?;
|
let ser = ron::ser::to_string(self)?;
|
||||||
Ok(std::fs::write(path, ser.clone())
|
Ok(match path {
|
||||||
.map(|_v| None)
|
Some(path) => std::fs::write(path, ser.clone())
|
||||||
.unwrap_or(Some(ser)))
|
.map(|_v| None)
|
||||||
|
.unwrap_or(Some(ser)),
|
||||||
|
None => Some(ser),
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue