save
This commit is contained in:
parent
c2c508db1b
commit
b110f48b3b
19
Cargo.lock
generated
19
Cargo.lock
generated
|
@ -127,6 +127,9 @@ name = "bitflags"
|
||||||
version = "2.4.2"
|
version = "2.4.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "ed570934406eb16438a4e976b1b4500774099c13b8cb96eec99f620f05090ddf"
|
checksum = "ed570934406eb16438a4e976b1b4500774099c13b8cb96eec99f620f05090ddf"
|
||||||
|
dependencies = [
|
||||||
|
"serde",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "block-buffer"
|
name = "block-buffer"
|
||||||
|
@ -1102,6 +1105,18 @@ dependencies = [
|
||||||
"windows-sys 0.48.0",
|
"windows-sys 0.48.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "ron"
|
||||||
|
version = "0.8.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b91f7eff05f748767f183df4320a63d6936e9c6107d97c9e6bdd9784f4289c94"
|
||||||
|
dependencies = [
|
||||||
|
"base64",
|
||||||
|
"bitflags 2.4.2",
|
||||||
|
"serde",
|
||||||
|
"serde_derive",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rustc-demangle"
|
name = "rustc-demangle"
|
||||||
version = "0.1.23"
|
version = "0.1.23"
|
||||||
|
@ -1502,10 +1517,12 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tesla-common"
|
name = "tesla-common"
|
||||||
version = "0.1.1"
|
version = "0.2.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"ron",
|
||||||
"serde",
|
"serde",
|
||||||
"teslatte",
|
"teslatte",
|
||||||
|
"thiserror",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "tesla-common"
|
name = "tesla-common"
|
||||||
version = "0.1.1"
|
version = "0.2.0"
|
||||||
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
|
||||||
|
@ -8,3 +8,5 @@ edition = "2021"
|
||||||
[dependencies]
|
[dependencies]
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
teslatte = { git = "https://git.alexjanka.com/alex/teslatte" }
|
teslatte = { git = "https://git.alexjanka.com/alex/teslatte" }
|
||||||
|
ron = "0.8"
|
||||||
|
thiserror = "1.0"
|
||||||
|
|
17
src/lib.rs
17
src/lib.rs
|
@ -1,8 +1,25 @@
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
use std::path::Path;
|
||||||
use teslatte::auth::{AccessToken, RefreshToken};
|
use teslatte::auth::{AccessToken, RefreshToken};
|
||||||
|
use thiserror::Error;
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone)]
|
#[derive(Serialize, Deserialize, Clone)]
|
||||||
pub struct AuthInfo {
|
pub struct AuthInfo {
|
||||||
pub access_token: AccessToken,
|
pub access_token: AccessToken,
|
||||||
pub refresh_token: Option<RefreshToken>,
|
pub refresh_token: Option<RefreshToken>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl AuthInfo {
|
||||||
|
pub fn save(&self, path: &Path) -> Result<(), SaveError> {
|
||||||
|
std::fs::write(path, ron::ser::to_string(self)?)?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Error, Debug)]
|
||||||
|
pub enum SaveError {
|
||||||
|
#[error("stdio error")]
|
||||||
|
StdIo(#[from] std::io::Error),
|
||||||
|
#[error("ron")]
|
||||||
|
RonSpanned(#[from] ron::Error),
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue