about summary refs log tree commit diff stats
path: root/crates/bytes
diff options
context:
space:
mode:
Diffstat (limited to 'crates/bytes')
-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
4 files changed, 86 insertions, 0 deletions
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())
+    }
+}