yaml > json

This commit is contained in:
Antoine Martin 2021-02-02 06:12:29 +01:00
parent ab08f6e0f3
commit 65bad5849d
3 changed files with 39 additions and 6 deletions

35
Cargo.lock generated
View file

@ -125,7 +125,7 @@ dependencies = [
"clap", "clap",
"matrix-sdk", "matrix-sdk",
"serde", "serde",
"serde_json", "serde_yaml",
"tokio", "tokio",
"tracing-subscriber", "tracing-subscriber",
"url", "url",
@ -386,6 +386,12 @@ version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "212d0f5754cb6769937f4501cc0e67f4f4483c8d2c3e1e922ee9edbe4ab4c7c0" checksum = "212d0f5754cb6769937f4501cc0e67f4f4483c8d2c3e1e922ee9edbe4ab4c7c0"
[[package]]
name = "dtoa"
version = "0.4.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "88d7ed2934d741c6b37e33e3832298e8850b53fd2d2bea03873375596c7cea4e"
[[package]] [[package]]
name = "encoding_rs" name = "encoding_rs"
version = "0.8.26" version = "0.8.26"
@ -805,6 +811,12 @@ version = "0.2.84"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1cca32fa0182e8c0989459524dc356b8f2b5c10f1b9eb521b7d182c03cf8c5ff" checksum = "1cca32fa0182e8c0989459524dc356b8f2b5c10f1b9eb521b7d182c03cf8c5ff"
[[package]]
name = "linked-hash-map"
version = "0.5.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7fb9b38af92608140b86b693604b9ffcc5824240a484d1ecd4795bacb2fe88f3"
[[package]] [[package]]
name = "lock_api" name = "lock_api"
version = "0.4.2" version = "0.4.2"
@ -1703,6 +1715,18 @@ dependencies = [
"serde", "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]] [[package]]
name = "sha1" name = "sha1"
version = "0.6.0" version = "0.6.0"
@ -2384,6 +2408,15 @@ dependencies = [
"winapi", "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]] [[package]]
name = "zeroize" name = "zeroize"
version = "1.2.0" version = "1.2.0"

View file

@ -11,7 +11,7 @@ clap = "3.0.0-beta.2"
tokio = { version = "1", features = [ "full" ] } tokio = { version = "1", features = [ "full" ] }
tracing-subscriber = "0.2" tracing-subscriber = "0.2"
url = { version = "2.2", features = [ "serde" ] } url = { version = "2.2", features = [ "serde" ] }
serde_json = "1" serde_yaml = "0.8"
serde = "1.0" serde = "1.0"
[dependencies.matrix-sdk] [dependencies.matrix-sdk]

View file

@ -105,7 +105,7 @@ async fn load_or_init_session(
if session_file.is_file() { if session_file.is_file() {
let reader = BufReader::new(File::open(session_file).unwrap()); 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(); 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()); 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(); 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 client
.add_event_emitter(Box::new(AutoJoinBot::new(client.clone()))) .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_file = opts.config;
let config: 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( login_and_sync(
config.homeserver, config.homeserver,