aboutsummaryrefslogtreecommitdiffstats
path: root/crates
diff options
context:
space:
mode:
authorBenedikt Peetz <benedikt.peetz@b-peetz.de>2025-07-15 06:56:30 +0200
committerBenedikt Peetz <benedikt.peetz@b-peetz.de>2025-07-15 06:56:30 +0200
commite60cf473b3ba1b5c0295d69e93e7d266f62ed60a (patch)
tree360b39d779facf5d0cc63ef71cdc729b922adbc7 /crates
parentrefactor(crates/yt/download/progress_hook): Use `json_{get,cast}` and owu-colors (diff)
downloadyt-e60cf473b3ba1b5c0295d69e93e7d266f62ed60a.zip
refactor(crates/yt): Allow `missing_panic_docs` and use expect
Diffstat (limited to '')
-rw-r--r--crates/yt/src/comments/mod.rs6
-rw-r--r--crates/yt/src/comments/output.rs2
-rw-r--r--crates/yt/src/download/mod.rs2
-rw-r--r--crates/yt/src/main.rs4
-rw-r--r--crates/yt/src/select/mod.rs4
-rw-r--r--crates/yt/src/unreachable.rs50
6 files changed, 8 insertions, 60 deletions
diff --git a/crates/yt/src/comments/mod.rs b/crates/yt/src/comments/mod.rs
index 178d8f0..e667bd9 100644
--- a/crates/yt/src/comments/mod.rs
+++ b/crates/yt/src/comments/mod.rs
@@ -64,10 +64,10 @@ pub(crate) async fn get(app: &App) -> Result<Comments> {
let replies = mem::take(&mut comment.replies);
let mut output_replies: Vec<CommentExt> = vec![];
- let re = Regex::new(r"\u{200b}?(@[^\t\s]+)\u{200b}?").unreachable("This is hardcoded");
+ let re = Regex::new(r"\u{200b}?(@[^\t\s]+)\u{200b}?").expect("This is hardcoded");
for reply in replies {
if let Some(replyee_match) = re.captures(&reply.value.text){
- let full_match = replyee_match.get(0).unreachable("This will always exist");
+ let full_match = replyee_match.get(0).expect("This will always exist");
let text = reply.
value.
text[0..full_match.start()]
@@ -78,7 +78,7 @@ pub(crate) async fn get(app: &App) -> Result<Comments> {
.text[full_match.end()..];
let text: &str = text.trim().trim_matches('\u{200b}');
- let replyee = replyee_match.get(1).unreachable("This should also exist").as_str();
+ let replyee = replyee_match.get(1).expect("This should also exist").as_str();
if let Some(parent) = output_replies
diff --git a/crates/yt/src/comments/output.rs b/crates/yt/src/comments/output.rs
index 67dec8f..4a27f3b 100644
--- a/crates/yt/src/comments/output.rs
+++ b/crates/yt/src/comments/output.rs
@@ -30,7 +30,7 @@ pub(crate) async fn display_fmt_and_less(input: String) -> Result<()> {
std::thread::spawn(move || {
stdin
.write_all(input.as_bytes())
- .unreachable("Should be able to write to the stdin of less");
+ .expect("Should be able to write to the stdin of less");
});
let _ = less.wait().context("Failed to await less")?;
diff --git a/crates/yt/src/download/mod.rs b/crates/yt/src/download/mod.rs
index 991d409..13e1bb3 100644
--- a/crates/yt/src/download/mod.rs
+++ b/crates/yt/src/download/mod.rs
@@ -19,11 +19,9 @@ use crate::{
db::{extractor_hash::ExtractorHash, insert::Operations, video::Video},
notify::{wait_for_cache_reduction, wait_for_db_write},
},
- unreachable::Unreachable,
};
use anyhow::{Context, Result, bail};
-use bytes::Bytes;
use futures::{FutureExt, future::BoxFuture};
use log::{debug, error, info, warn};
use tokio::{fs, select, task::JoinHandle, time};
diff --git a/crates/yt/src/main.rs b/crates/yt/src/main.rs
index 46ab037..824f842 100644
--- a/crates/yt/src/main.rs
+++ b/crates/yt/src/main.rs
@@ -11,9 +11,9 @@
// `yt` is not a library. Besides, the `anyhow::Result` type is really useless, if you're not going
// to print it anyways.
-#![allow(clippy::missing_errors_doc)]
+#![allow(clippy::missing_errors_doc, clippy::missing_panics_doc)]
-use std::{env::current_exe, sync::Arc};
+use std::sync::Arc;
use anyhow::{Context, Result, bail};
use app::App;
diff --git a/crates/yt/src/select/mod.rs b/crates/yt/src/select/mod.rs
index 4e526b6..9afe071 100644
--- a/crates/yt/src/select/mod.rs
+++ b/crates/yt/src/select/mod.rs
@@ -63,7 +63,7 @@ pub(crate) async fn select_split(
if author_map.contains_key(sub) {
let vec: &mut Vec<_> = author_map
.get_mut(sub)
- .unreachable("This key is set, we checked in the if above");
+ .expect("This key is set, we checked in the if above");
vec.push(video);
} else {
@@ -264,7 +264,7 @@ async fn process_file(app: &App, file: &File) -> Result<i64> {
let crate::cli::Command::Select { cmd } = args
.command
- .unreachable("This will be some, as we constructed it above.")
+ .expect("This will be some, as we constructed it above.")
else {
unreachable!("This is checked in the `filter_line` function")
};
diff --git a/crates/yt/src/unreachable.rs b/crates/yt/src/unreachable.rs
deleted file mode 100644
index 436fbb6..0000000
--- a/crates/yt/src/unreachable.rs
+++ /dev/null
@@ -1,50 +0,0 @@
-// yt - A fully featured command line YouTube client
-//
-// Copyright (C) 2024 Benedikt Peetz <benedikt.peetz@b-peetz.de>
-// Copyright (C) 2025 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>.
-
-// This has been taken from: https://gitlab.torproject.org/tpo/core/arti/-/issues/950
-
-// The functions here should be annotated with `#[inline(always)]`.
-#![allow(clippy::inline_always)]
-
-use std::fmt::Debug;
-
-/// Trait for something that can possibly be unwrapped, like a Result or Option.
-/// It provides semantic information, that unwrapping here should never happen.
-pub trait Unreachable<T> {
- /// Like `expect()`, but does not trigger clippy.
- ///
- /// # Usage
- ///
- /// This method only exists so that we can use it without hitting
- /// `clippy::missing_panics_docs`. Therefore, we should only use it
- /// for situations where we are certain that the panic cannot occur
- /// unless something else is very broken. Consider instead using
- /// `expect()` and adding a `Panics` section to your function
- /// documentation.
- ///
- /// # Panics
- ///
- /// Panics if this is not an object that can be unwrapped, such as
- /// None or an Err.
- fn unreachable(self, msg: &str) -> T;
-}
-impl<T> Unreachable<T> for Option<T> {
- #[inline(always)]
- fn unreachable(self, msg: &str) -> T {
- self.expect(msg)
- }
-}
-impl<T, E: Debug> Unreachable<T> for Result<T, E> {
- #[inline(always)]
- fn unreachable(self, msg: &str) -> T {
- self.expect(msg)
- }
-}