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