From 0317119581b7385f34db28d034f411cc9af74d62 Mon Sep 17 00:00:00 2001 From: Dave Patrick Caberto Date: Mon, 8 Jan 2024 15:24:52 +0800 Subject: [PATCH] replace rmp_serde with cbor it is more standard --- Cargo.lock | 61 +++++++++++++--------------------------------- Cargo.toml | 2 +- src/recent_list.rs | 6 ++--- src/session.rs | 6 ++--- 4 files changed, 24 insertions(+), 51 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e786d51..da04fc6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -46,12 +46,6 @@ version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0d8c1fef690941d3e7788d328517591fecc684c084084702d6ff1641e993699a" -[[package]] -name = "byteorder" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" - [[package]] name = "cairo-rs" version = "0.18.5" @@ -134,8 +128,8 @@ dependencies = [ "indexmap", "libadwaita", "regex", - "rmp-serde", "serde", + "serde_cbor", "sourceview5", "tracing", "tracing-subscriber", @@ -529,6 +523,12 @@ dependencies = [ "system-deps", ] +[[package]] +name = "half" +version = "1.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eabb4a44450da02c90444cf74558da904edde8fb4e9035a9a6a4e15445af0bd7" + [[package]] name = "hashbrown" version = "0.14.3" @@ -671,15 +671,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "num-traits" -version = "0.2.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c" -dependencies = [ - "autocfg", -] - [[package]] name = "objc" version = "0.2.7" @@ -752,12 +743,6 @@ version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bb813b8af86854136c6922af0598d719255ecb2179515e6e7730d468f05c9cae" -[[package]] -name = "paste" -version = "1.0.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c" - [[package]] name = "pin-project-lite" version = "0.2.13" @@ -867,28 +852,6 @@ version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" -[[package]] -name = "rmp" -version = "0.8.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f9860a6cc38ed1da53456442089b4dfa35e7cedaa326df63017af88385e6b20" -dependencies = [ - "byteorder", - "num-traits", - "paste", -] - -[[package]] -name = "rmp-serde" -version = "1.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bffea85eea980d8a74453e5d02a8d93028f3c34725de143085a844ebe953258a" -dependencies = [ - "byteorder", - "rmp", - "serde", -] - [[package]] name = "rustc_version" version = "0.4.0" @@ -913,6 +876,16 @@ dependencies = [ "serde_derive", ] +[[package]] +name = "serde_cbor" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2bef2ebfde456fb76bbcf9f59315333decc4fda0b2b44b420243c11e0f5ec1f5" +dependencies = [ + "half", + "serde", +] + [[package]] name = "serde_derive" version = "1.0.194" diff --git a/Cargo.toml b/Cargo.toml index 1bfd866..d4254e8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,8 +19,8 @@ gtk = { version = "0.7", package = "gtk4", features = ["gnome_45"] } gtk_source = { package = "sourceview5", version = "0.7", features = ["v5_10"] } indexmap = "2.1" regex = "1.10.2" -rmp-serde = "1.1.2" serde = { version = "1", features = ["derive"] } +serde_cbor = "0.11.2" tracing = "0.1.37" tracing-subscriber = "0.3" webkit = { package = "webkit6", version = "0.2.0", features = ["v2_42"] } diff --git a/src/recent_list.rs b/src/recent_list.rs index 8f16634..dcede64 100644 --- a/src/recent_list.rs +++ b/src/recent_list.rs @@ -36,7 +36,7 @@ mod imp { fn new() -> Self { Self { - state_file: gio::File::for_path(APP_DATA_DIR.join("recents.msgpack")), + state_file: gio::File::for_path(APP_DATA_DIR.join("recents.cbor")), list: RefCell::new(IndexMap::new()), } } @@ -80,7 +80,7 @@ impl RecentList { let now = Instant::now(); let state = match imp.state_file.load_bytes_future().await { - Ok((bytes, _)) => rmp_serde::from_slice::(&bytes)?, + Ok((bytes, _)) => serde_cbor::from_slice::(&bytes)?, Err(err) => { if !err.matches(gio::IOErrorEnum::NotFound) { return Err(err.into()); @@ -136,7 +136,7 @@ impl RecentList { }; tracing::trace!(?state, "State stored"); - let bytes = rmp_serde::to_vec_named(&state)?; + let bytes = serde_cbor::to_vec(&state)?; imp.state_file .replace_contents_future( bytes, diff --git a/src/session.rs b/src/session.rs index f826c17..14bc4ac 100644 --- a/src/session.rs +++ b/src/session.rs @@ -192,7 +192,7 @@ mod imp { fn new() -> Self { Self { - state_file: gio::File::for_path(APP_DATA_DIR.join("state.msgpack")), + state_file: gio::File::for_path(APP_DATA_DIR.join("state.cbor")), default_window_width: Cell::new(DEFAULT_WINDOW_WIDTH), default_window_height: Cell::new(DEFAULT_WINDOW_HEIGHT), windows: RefCell::default(), @@ -358,7 +358,7 @@ impl Session { let now = Instant::now(); let state = match imp.state_file.load_bytes_future().await { - Ok((bytes, _)) => rmp_serde::from_slice::(&bytes)?, + Ok((bytes, _)) => serde_cbor::from_slice::(&bytes)?, Err(err) => { if !err.matches(gio::IOErrorEnum::NotFound) { return Err(err.into()); @@ -417,7 +417,7 @@ impl Session { }; tracing::trace!(?state, "State stored"); - let bytes = rmp_serde::to_vec_named(&state)?; + let bytes = serde_cbor::to_vec(&state)?; imp.state_file .replace_contents_future( bytes,