about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorBenedikt Peetz <benedikt.peetz@b-peetz.de>2024-08-24 11:21:23 +0200
committerBenedikt Peetz <benedikt.peetz@b-peetz.de>2024-08-24 11:45:24 +0200
commit66ded1ec598639fd54a75d6af007ed60541df5ca (patch)
treeba07f30f6224d3d0a63129a9330f4441cc06e113
parentfeat(status): Also show the cache usage (diff)
downloadyt-66ded1ec598639fd54a75d6af007ed60541df5ca.tar.gz
yt-66ded1ec598639fd54a75d6af007ed60541df5ca.zip
feat(bytes): Add implementation for serde's `Serialize`
-rw-r--r--Cargo.lock3
-rw-r--r--Cargo.toml2
-rw-r--r--crates/bytes/Cargo.lock58
-rw-r--r--crates/bytes/Cargo.toml7
-rw-r--r--crates/bytes/src/lib.rs2
-rw-r--r--crates/bytes/src/serde.rs19
6 files changed, 90 insertions, 1 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 927cc05..24e58d1 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -244,6 +244,9 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b"
 [[package]]
 name = "bytes"
 version = "1.0.0"
+dependencies = [
+ "serde",
+]
 
 [[package]]
 name = "bytes"
diff --git a/Cargo.toml b/Cargo.toml
index 17f8e48..3877d1d 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -40,7 +40,7 @@ url = { version = "2.5.2", features = ["serde"] }
 xdg = "2.5.2"
 yt_dlp = { path = "./crates/yt_dlp/" }
 libmpv2 = { path = "./crates/libmpv2" }
-bytes = { path = "./crates/bytes" }
+bytes = { path = "./crates/bytes", features = ["serde"] }
 trinitry = { version = "0.2.2" }
 toml = "0.8.19"
 nucleo-matcher = "0.3.1"
diff --git a/crates/bytes/Cargo.lock b/crates/bytes/Cargo.lock
index b819c60..b3b49c9 100644
--- a/crates/bytes/Cargo.lock
+++ b/crates/bytes/Cargo.lock
@@ -5,3 +5,61 @@ version = 3
 [[package]]
 name = "bytes"
 version = "1.0.0"
+dependencies = [
+ "serde",
+]
+
+[[package]]
+name = "proc-macro2"
+version = "1.0.86"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77"
+dependencies = [
+ "unicode-ident",
+]
+
+[[package]]
+name = "quote"
+version = "1.0.37"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af"
+dependencies = [
+ "proc-macro2",
+]
+
+[[package]]
+name = "serde"
+version = "1.0.209"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "99fce0ffe7310761ca6bf9faf5115afbc19688edd00171d81b1bb1b116c63e09"
+dependencies = [
+ "serde_derive",
+]
+
+[[package]]
+name = "serde_derive"
+version = "1.0.209"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a5831b979fd7b5439637af1752d535ff49f4860c0f341d1baeb6faf0f4242170"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn",
+]
+
+[[package]]
+name = "syn"
+version = "2.0.76"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "578e081a14e0cefc3279b0472138c513f37b41a08d5a3cca9b6e4e8ceb6cd525"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "unicode-ident",
+]
+
+[[package]]
+name = "unicode-ident"
+version = "1.0.12"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"
diff --git a/crates/bytes/Cargo.toml b/crates/bytes/Cargo.toml
index 98691ee..33a6f11 100644
--- a/crates/bytes/Cargo.toml
+++ b/crates/bytes/Cargo.toml
@@ -14,3 +14,10 @@ version = "1.0.0"
 edition = "2021"
 license = "GPL-3.0-or-later"
 description = "Simple byte formatting utilities"
+
+[dependencies]
+serde = { version = "1.0.208", optional = true }
+
+[features]
+default = ["serde"]
+serde = ["dep:serde"]
diff --git a/crates/bytes/src/lib.rs b/crates/bytes/src/lib.rs
index f80b864..9814a4a 100644
--- a/crates/bytes/src/lib.rs
+++ b/crates/bytes/src/lib.rs
@@ -26,6 +26,8 @@ const GB: u64 = 1000 * MB;
 const TB: u64 = 1000 * GB;
 
 pub mod error;
+#[cfg(feature = "serde")]
+pub mod serde;
 
 #[derive(Clone, Copy)]
 pub struct Bytes(u64);
diff --git a/crates/bytes/src/serde.rs b/crates/bytes/src/serde.rs
new file mode 100644
index 0000000..4341e32
--- /dev/null
+++ b/crates/bytes/src/serde.rs
@@ -0,0 +1,19 @@
+// yt - A fully featured command line YouTube client
+//
+// Copyright (C) 2024 Benedikt Peetz <benedikt.peetz@b-peetz.de>
+// SPDX-License-Identifier: GPL-3.0-or-later
+//
+// This file is part of Yt.
+//
+// You should have received a copy of the License along with this program.
+// If not, see <https://www.gnu.org/licenses/gpl-3.0.txt>.
+
+use serde::{Serialize, Serializer};
+
+use crate::Bytes;
+
+impl Serialize for Bytes {
+    fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
+        serializer.serialize_str(self.to_string().as_str())
+    }
+}