diff options
author | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2025-07-10 15:50:16 +0200 |
---|---|---|
committer | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2025-07-10 15:50:16 +0200 |
commit | 66d56d7a2b64c5ed13860d809d9bf35d86292df2 (patch) | |
tree | 2d79d616024e1dd326afd8b7d2b8b05efb165386 | |
parent | build(.cargo/cargo.toml): Remove pointless `PYO3_PATH` (diff) | |
download | yt-66d56d7a2b64c5ed13860d809d9bf35d86292df2.zip |
refactor(crates/bytes): Move into yt
`yt_dlp` no longer depends on it.
-rw-r--r-- | crates/bytes/.gitignore | 11 | ||||
-rw-r--r-- | crates/bytes/Cargo.lock | 65 | ||||
-rw-r--r-- | crates/bytes/Cargo.lock.license | 9 | ||||
-rw-r--r-- | crates/bytes/Cargo.toml | 33 | ||||
-rw-r--r-- | crates/bytes/src/serde.rs | 19 | ||||
-rwxr-xr-x | crates/bytes/update.sh | 15 | ||||
-rw-r--r-- | crates/yt/Cargo.toml | 1 | ||||
-rw-r--r-- | crates/yt/src/main.rs | 7 | ||||
-rw-r--r-- | crates/yt/src/shared/bytes/error.rs (renamed from crates/bytes/src/error.rs) | 0 | ||||
-rw-r--r-- | crates/yt/src/shared/bytes/mod.rs (renamed from crates/bytes/src/lib.rs) | 24 | ||||
-rw-r--r-- | crates/yt/src/shared/mod.rs | 1 |
11 files changed, 26 insertions, 159 deletions
diff --git a/crates/bytes/.gitignore b/crates/bytes/.gitignore deleted file mode 100644 index 8876ea6..0000000 --- a/crates/bytes/.gitignore +++ /dev/null @@ -1,11 +0,0 @@ -# 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>. - -/target diff --git a/crates/bytes/Cargo.lock b/crates/bytes/Cargo.lock deleted file mode 100644 index b30ba3d..0000000 --- a/crates/bytes/Cargo.lock +++ /dev/null @@ -1,65 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -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.210" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" -dependencies = [ - "serde_derive", -] - -[[package]] -name = "serde_derive" -version = "1.0.210" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "syn" -version = "2.0.77" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "unicode-ident" -version = "1.0.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" diff --git a/crates/bytes/Cargo.lock.license b/crates/bytes/Cargo.lock.license deleted file mode 100644 index d4d410f..0000000 --- a/crates/bytes/Cargo.lock.license +++ /dev/null @@ -1,9 +0,0 @@ -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>. diff --git a/crates/bytes/Cargo.toml b/crates/bytes/Cargo.toml deleted file mode 100644 index 4439aa8..0000000 --- a/crates/bytes/Cargo.toml +++ /dev/null @@ -1,33 +0,0 @@ -# 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>. - -[package] -name = "bytes" -description = "Simple byte formatting utilities" -keywords = [] -categories = [] -version.workspace = true -edition.workspace = true -authors.workspace = true -license.workspace = true -repository.workspace = true -rust-version.workspace = true -publish = false - -[dependencies] -serde.workspace = true - -[dev-dependencies] - -[lints] -workspace = true - -[package.metadata.docs.rs] -all-features = true diff --git a/crates/bytes/src/serde.rs b/crates/bytes/src/serde.rs deleted file mode 100644 index 4341e32..0000000 --- a/crates/bytes/src/serde.rs +++ /dev/null @@ -1,19 +0,0 @@ -// 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()) - } -} diff --git a/crates/bytes/update.sh b/crates/bytes/update.sh deleted file mode 100755 index c1a0215..0000000 --- a/crates/bytes/update.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/usr/bin/env sh - -# 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>. - -cd "$(dirname "$0")" || exit 1 -[ "$1" = "upgrade" ] && cargo upgrade --incompatible -cargo update diff --git a/crates/yt/Cargo.toml b/crates/yt/Cargo.toml index c3ed3b0..0a9227f 100644 --- a/crates/yt/Cargo.toml +++ b/crates/yt/Cargo.toml @@ -39,7 +39,6 @@ tempfile = "3.20.0" toml = "0.8.23" xdg = "3.0.0" shlex = "1.3.0" -bytes.workspace = true libmpv2.workspace = true log.workspace = true serde.workspace = true diff --git a/crates/yt/src/main.rs b/crates/yt/src/main.rs index f78c23e..f6f18be 100644 --- a/crates/yt/src/main.rs +++ b/crates/yt/src/main.rs @@ -17,7 +17,6 @@ use std::{env::current_exe, sync::Arc}; use anyhow::{Context, Result, bail}; use app::App; -use bytes::Bytes; use cache::{invalidate, maintain}; use clap::{CommandFactory, Parser}; use cli::{CacheCommand, SelectCommand, SubscriptionCommand, VideosCommand}; @@ -31,7 +30,11 @@ use tokio::{ task::JoinHandle, }; -use crate::{cli::Command, storage::subscriptions}; +use crate::{ + cli::Command, + shared::bytes::Bytes, + storage::subscription, +}; pub mod ansi_escape_codes; pub mod app; diff --git a/crates/bytes/src/error.rs b/crates/yt/src/shared/bytes/error.rs index c9783d8..c9783d8 100644 --- a/crates/bytes/src/error.rs +++ b/crates/yt/src/shared/bytes/error.rs diff --git a/crates/bytes/src/lib.rs b/crates/yt/src/shared/bytes/mod.rs index 2a9248d..31e782e 100644 --- a/crates/bytes/src/lib.rs +++ b/crates/yt/src/shared/bytes/mod.rs @@ -16,6 +16,7 @@ )] use std::{fmt::Display, str::FromStr}; +use ::serde::{Deserialize, Serialize}; use error::BytesError; const B: u64 = 1; @@ -31,10 +32,11 @@ const MB: u64 = 1000 * KB; const GB: u64 = 1000 * MB; const TB: u64 = 1000 * GB; -pub mod error; -pub mod serde; +pub(crate) mod error; -#[derive(Clone, Copy, Debug, PartialEq, PartialOrd, Ord, Eq)] +#[derive(Clone, Copy, Debug, PartialEq, PartialOrd, Ord, Eq, Deserialize, Serialize)] +#[serde(try_from = "String")] +#[serde(into = "String")] pub struct Bytes(u64); impl Bytes { @@ -131,6 +133,20 @@ impl Display for Bytes { } } +impl From<Bytes> for String { + fn from(value: Bytes) -> Self { + value.to_string() + } +} + +impl TryFrom<String> for Bytes { + type Error = BytesError; + + fn try_from(value: String) -> Result<Self, Self::Error> { + value.as_str().parse() + } +} + // taken from this stack overflow question: https://stackoverflow.com/a/76572321 /// Round to significant digits (rather than digits after the decimal). /// @@ -149,7 +165,7 @@ impl Display for Bytes { ///# } /// ``` #[must_use] -pub fn precision_f64(x: f64, decimals: u32) -> f64 { +pub(crate) fn precision_f64(x: f64, decimals: u32) -> f64 { if x == 0. || decimals == 0 { 0. } else { diff --git a/crates/yt/src/shared/mod.rs b/crates/yt/src/shared/mod.rs new file mode 100644 index 0000000..14e4949 --- /dev/null +++ b/crates/yt/src/shared/mod.rs @@ -0,0 +1 @@ +pub(crate) mod bytes; |