From 65bad5849d9dda3a9ad0b325bce95ab9e5fae70e Mon Sep 17 00:00:00 2001 From: Antoine Martin Date: Tue, 2 Feb 2021 06:12:29 +0100 Subject: [PATCH] yaml > json --- Cargo.lock | 35 ++++++++++++++++++++++++++++++++++- Cargo.toml | 2 +- src/main.rs | 8 ++++---- 3 files changed, 39 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 30856f9..a24226c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -125,7 +125,7 @@ dependencies = [ "clap", "matrix-sdk", "serde", - "serde_json", + "serde_yaml", "tokio", "tracing-subscriber", "url", @@ -386,6 +386,12 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "212d0f5754cb6769937f4501cc0e67f4f4483c8d2c3e1e922ee9edbe4ab4c7c0" +[[package]] +name = "dtoa" +version = "0.4.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88d7ed2934d741c6b37e33e3832298e8850b53fd2d2bea03873375596c7cea4e" + [[package]] name = "encoding_rs" version = "0.8.26" @@ -805,6 +811,12 @@ version = "0.2.84" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1cca32fa0182e8c0989459524dc356b8f2b5c10f1b9eb521b7d182c03cf8c5ff" +[[package]] +name = "linked-hash-map" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fb9b38af92608140b86b693604b9ffcc5824240a484d1ecd4795bacb2fe88f3" + [[package]] name = "lock_api" version = "0.4.2" @@ -1703,6 +1715,18 @@ dependencies = [ "serde", ] +[[package]] +name = "serde_yaml" +version = "0.8.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "971be8f6e4d4a47163b405a3df70d14359186f9ab0f3a3ec37df144ca1ce089f" +dependencies = [ + "dtoa", + "linked-hash-map", + "serde", + "yaml-rust", +] + [[package]] name = "sha1" version = "0.6.0" @@ -2384,6 +2408,15 @@ dependencies = [ "winapi", ] +[[package]] +name = "yaml-rust" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56c1936c4cc7a1c9ab21a1ebb602eb942ba868cbd44a99cb7cdc5892335e1c85" +dependencies = [ + "linked-hash-map", +] + [[package]] name = "zeroize" version = "1.2.0" diff --git a/Cargo.toml b/Cargo.toml index e21e399..9ab6dd3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,7 @@ clap = "3.0.0-beta.2" tokio = { version = "1", features = [ "full" ] } tracing-subscriber = "0.2" url = { version = "2.2", features = [ "serde" ] } -serde_json = "1" +serde_yaml = "0.8" serde = "1.0" [dependencies.matrix-sdk] diff --git a/src/main.rs b/src/main.rs index 0457d24..8c3ead7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -105,7 +105,7 @@ async fn load_or_init_session( if session_file.is_file() { let reader = BufReader::new(File::open(session_file).unwrap()); - let session: Session = serde_json::from_reader(reader).unwrap(); + let session: Session = serde_yaml::from_reader(reader).unwrap(); client.restore_login(session.clone()).await.unwrap(); @@ -125,7 +125,7 @@ async fn load_or_init_session( }; let writer = BufWriter::new(File::create(session_file).unwrap()); - serde_json::to_writer(writer, &session).unwrap(); + serde_yaml::to_writer(writer, &session).unwrap(); } } @@ -139,7 +139,7 @@ async fn login_and_sync( let client = Client::new_with_config(homeserver_url, client_config).unwrap(); - load_or_init_session(&client, state_dir.join("session.json"), username, password).await; + load_or_init_session(&client, state_dir.join("session.yaml"), username, password).await; client .add_event_emitter(Box::new(AutoJoinBot::new(client.clone()))) @@ -175,7 +175,7 @@ async fn main() -> Result<(), matrix_sdk::Error> { let config_file = opts.config; let config: Config = - serde_json::from_reader(BufReader::new(File::open(config_file).unwrap())).unwrap(); + serde_yaml::from_reader(BufReader::new(File::open(config_file).unwrap())).unwrap(); login_and_sync( config.homeserver,