mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-21 23:01:05 +00:00
refactor: satisfy mismatched-lifetime-syntaxes lint (#2881)
This commit is contained in:
parent
52d37fa25d
commit
a076ff8c82
14 changed files with 33 additions and 31 deletions
7
Cargo.lock
generated
7
Cargo.lock
generated
|
|
@ -2421,12 +2421,9 @@ checksum = "e3a9fe34e3e7a50316060351f37187a3f546bce95496156754b601a5fa71b76e"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "slab"
|
name = "slab"
|
||||||
version = "0.4.9"
|
version = "0.4.10"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67"
|
checksum = "04dc19736151f35336d325007ac991178d504a119863a2fcb3758cdb5e52c50d"
|
||||||
dependencies = [
|
|
||||||
"autocfg",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "smallvec"
|
name = "smallvec"
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
#![allow(clippy::unit_arg, clippy::option_map_unit_fn)]
|
#![allow(clippy::option_map_unit_fn, clippy::unit_arg)]
|
||||||
|
|
||||||
yazi_macro::mod_pub!(drivers);
|
yazi_macro::mod_pub!(drivers);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
use std::borrow::Cow;
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use tracing::error;
|
use tracing::error;
|
||||||
use yazi_macro::time;
|
use yazi_macro::time;
|
||||||
|
|
@ -8,14 +10,14 @@ use crate::{CLOSE, ESCAPE, Emulator, START, TMUX};
|
||||||
pub struct Mux;
|
pub struct Mux;
|
||||||
|
|
||||||
impl Mux {
|
impl Mux {
|
||||||
pub fn csi(s: &str) -> std::borrow::Cow<str> {
|
pub fn csi(s: &str) -> Cow<'_, str> {
|
||||||
if TMUX.get() {
|
if TMUX.get() {
|
||||||
std::borrow::Cow::Owned(format!(
|
Cow::Owned(format!(
|
||||||
"{START}{}{CLOSE}",
|
"{START}{}{CLOSE}",
|
||||||
s.trim_start_matches('\x1b').replace('\x1b', ESCAPE.get()),
|
s.trim_start_matches('\x1b').replace('\x1b', ESCAPE.get()),
|
||||||
))
|
))
|
||||||
} else {
|
} else {
|
||||||
std::borrow::Cow::Borrowed(s)
|
Cow::Borrowed(s)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -175,7 +175,7 @@ macro_rules! impl_pub_body {
|
||||||
($name:ident) => {
|
($name:ident) => {
|
||||||
impl $name {
|
impl $name {
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub(super) fn body(&self) -> Result<Cow<str>> {
|
pub(super) fn body(&self) -> Result<Cow<'_, str>> {
|
||||||
Ok(if let Some(json) = &self.json {
|
Ok(if let Some(json) = &self.json {
|
||||||
json.into()
|
json.into()
|
||||||
} else if let Some(str) = &self.str {
|
} else if let Some(str) = &self.str {
|
||||||
|
|
|
||||||
|
|
@ -38,11 +38,11 @@ impl Chord {
|
||||||
.into_owned()
|
.into_owned()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn desc(&self) -> Option<Cow<str>> {
|
pub fn desc(&self) -> Option<Cow<'_, str>> {
|
||||||
self.desc.as_ref().map(|s| RE.get_or_init(|| Regex::new(r"\s+").unwrap()).replace_all(s, " "))
|
self.desc.as_ref().map(|s| RE.get_or_init(|| Regex::new(r"\s+").unwrap()).replace_all(s, " "))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn desc_or_run(&self) -> Cow<str> { self.desc().unwrap_or_else(|| self.run().into()) }
|
pub fn desc_or_run(&self) -> Cow<'_, str> { self.desc().unwrap_or_else(|| self.run().into()) }
|
||||||
|
|
||||||
pub fn contains(&self, s: &str) -> bool {
|
pub fn contains(&self, s: &str) -> bool {
|
||||||
let s = s.to_lowercase();
|
let s = s.to_lowercase();
|
||||||
|
|
|
||||||
|
|
@ -75,7 +75,7 @@ impl From<&str> for Separator {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Separator {
|
impl Separator {
|
||||||
fn transform<T: AsRef<Path> + ?Sized>(self, p: &T) -> Cow<OsStr> {
|
fn transform<T: AsRef<Path> + ?Sized>(self, p: &T) -> Cow<'_, OsStr> {
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
if self == Self::Unix {
|
if self == Self::Unix {
|
||||||
return match yazi_fs::backslash_to_slash(p.as_ref()) {
|
return match yazi_fs::backslash_to_slash(p.as_ref()) {
|
||||||
|
|
|
||||||
|
|
@ -110,7 +110,7 @@ impl Term {
|
||||||
std::process::exit(f());
|
std::process::exit(f());
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn draw(&mut self, f: impl FnOnce(&mut Frame)) -> io::Result<CompletedFrame> {
|
pub(super) fn draw(&mut self, f: impl FnOnce(&mut Frame)) -> io::Result<CompletedFrame<'_>> {
|
||||||
let last = self.inner.draw(f)?;
|
let last = self.inner.draw(f)?;
|
||||||
|
|
||||||
self.last_area = last.area;
|
self.last_area = last.area;
|
||||||
|
|
@ -118,7 +118,10 @@ impl Term {
|
||||||
Ok(last)
|
Ok(last)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn draw_partial(&mut self, f: impl FnOnce(&mut Frame)) -> io::Result<CompletedFrame> {
|
pub(super) fn draw_partial(
|
||||||
|
&mut self,
|
||||||
|
f: impl FnOnce(&mut Frame),
|
||||||
|
) -> io::Result<CompletedFrame<'_>> {
|
||||||
self.inner.draw(|frame| {
|
self.inner.draw(|frame| {
|
||||||
let buffer = frame.buffer_mut();
|
let buffer = frame.buffer_mut();
|
||||||
for y in self.last_area.top()..self.last_area.bottom() {
|
for y in self.last_area.top()..self.last_area.bottom() {
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,7 @@ impl Table {
|
||||||
table.into_lua(lua)
|
table.into_lua(lua)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn selected_cell(&self) -> Option<&ratatui::text::Text> {
|
pub fn selected_cell(&self) -> Option<&ratatui::text::Text<'_>> {
|
||||||
let row = &self.rows[self.selected()?];
|
let row = &self.rows[self.selected()?];
|
||||||
let col = self.state.selected_column()?;
|
let col = self.state.selected_column()?;
|
||||||
if row.cells.is_empty() { None } else { Some(&row.cells[col.min(row.cells.len() - 1)].text) }
|
if row.cells.is_empty() { None } else { Some(&row.cells[col.min(row.cells.len() - 1)].text) }
|
||||||
|
|
|
||||||
|
|
@ -12,13 +12,13 @@ mod unix;
|
||||||
mod windows;
|
mod windows;
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn escape_unix(s: &str) -> Cow<str> { unix::escape_str(s) }
|
pub fn escape_unix(s: &str) -> Cow<'_, str> { unix::escape_str(s) }
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn escape_windows(s: &str) -> Cow<str> { windows::escape_str(s) }
|
pub fn escape_windows(s: &str) -> Cow<'_, str> { windows::escape_str(s) }
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn escape_native(s: &str) -> Cow<str> {
|
pub fn escape_native(s: &str) -> Cow<'_, str> {
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
{
|
{
|
||||||
escape_unix(s)
|
escape_unix(s)
|
||||||
|
|
@ -30,7 +30,7 @@ pub fn escape_native(s: &str) -> Cow<str> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn escape_os_str(s: &OsStr) -> Cow<OsStr> {
|
pub fn escape_os_str(s: &OsStr) -> Cow<'_, OsStr> {
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
{
|
{
|
||||||
unix::escape_os_str(s)
|
unix::escape_os_str(s)
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
use std::{borrow::Cow, mem};
|
use std::{borrow::Cow, mem};
|
||||||
|
|
||||||
pub fn escape_str(s: &str) -> Cow<str> {
|
pub fn escape_str(s: &str) -> Cow<'_, str> {
|
||||||
match escape_slice(s.as_bytes()) {
|
match escape_slice(s.as_bytes()) {
|
||||||
Cow::Borrowed(_) => Cow::Borrowed(s),
|
Cow::Borrowed(_) => Cow::Borrowed(s),
|
||||||
Cow::Owned(v) => String::from_utf8(v).expect("Invalid bytes returned by escape_slice()").into(),
|
Cow::Owned(v) => String::from_utf8(v).expect("Invalid bytes returned by escape_slice()").into(),
|
||||||
|
|
@ -8,7 +8,7 @@ pub fn escape_str(s: &str) -> Cow<str> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
pub fn escape_os_str(s: &std::ffi::OsStr) -> Cow<std::ffi::OsStr> {
|
pub fn escape_os_str(s: &std::ffi::OsStr) -> Cow<'_, std::ffi::OsStr> {
|
||||||
use std::os::unix::ffi::{OsStrExt, OsStringExt};
|
use std::os::unix::ffi::{OsStrExt, OsStringExt};
|
||||||
|
|
||||||
match escape_slice(s.as_bytes()) {
|
match escape_slice(s.as_bytes()) {
|
||||||
|
|
@ -17,7 +17,7 @@ pub fn escape_os_str(s: &std::ffi::OsStr) -> Cow<std::ffi::OsStr> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn escape_slice(s: &[u8]) -> Cow<[u8]> {
|
fn escape_slice(s: &[u8]) -> Cow<'_, [u8]> {
|
||||||
if !s.is_empty() && s.iter().copied().all(allowed) {
|
if !s.is_empty() && s.iter().copied().all(allowed) {
|
||||||
return Cow::Borrowed(s);
|
return Cow::Borrowed(s);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
use std::{borrow::Cow, iter::repeat_n};
|
use std::{borrow::Cow, iter::repeat_n};
|
||||||
|
|
||||||
pub fn escape_str(s: &str) -> Cow<str> {
|
pub fn escape_str(s: &str) -> Cow<'_, str> {
|
||||||
let bytes = s.as_bytes();
|
let bytes = s.as_bytes();
|
||||||
if !bytes.is_empty() && !bytes.iter().any(|&c| matches!(c, b' ' | b'"' | b'\n' | b'\t')) {
|
if !bytes.is_empty() && !bytes.iter().any(|&c| matches!(c, b' ' | b'"' | b'\n' | b'\t')) {
|
||||||
return Cow::Borrowed(s);
|
return Cow::Borrowed(s);
|
||||||
|
|
|
||||||
|
|
@ -2,11 +2,11 @@ use core::str;
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
|
|
||||||
pub trait Transliterator {
|
pub trait Transliterator {
|
||||||
fn transliterate(&self) -> Cow<str>;
|
fn transliterate(&self) -> Cow<'_, str>;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Transliterator for &[u8] {
|
impl Transliterator for &[u8] {
|
||||||
fn transliterate(&self) -> Cow<str> {
|
fn transliterate(&self) -> Cow<'_, str> {
|
||||||
// Fast path to skip over ASCII chars at the beginning of the string
|
// Fast path to skip over ASCII chars at the beginning of the string
|
||||||
let ascii_len = self.iter().take_while(|&&c| c < 0x7f).count();
|
let ascii_len = self.iter().take_while(|&&c| c < 0x7f).count();
|
||||||
if ascii_len >= self.len() {
|
if ascii_len >= self.len() {
|
||||||
|
|
|
||||||
|
|
@ -19,13 +19,13 @@ impl Default for Tty {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Tty {
|
impl Tty {
|
||||||
pub const fn reader(&self) -> TtyReader { TtyReader(&self.stdin) }
|
pub const fn reader(&self) -> TtyReader<'_> { TtyReader(&self.stdin) }
|
||||||
|
|
||||||
pub const fn writer(&self) -> TtyWriter { TtyWriter(&self.stdout) }
|
pub const fn writer(&self) -> TtyWriter<'_> { TtyWriter(&self.stdout) }
|
||||||
|
|
||||||
pub fn lockin(&self) -> MutexGuard<Handle> { self.stdin.lock() }
|
pub fn lockin(&self) -> MutexGuard<'_, Handle> { self.stdin.lock() }
|
||||||
|
|
||||||
pub fn lockout(&self) -> MutexGuard<BufWriter<Handle>> { self.stdout.lock() }
|
pub fn lockout(&self) -> MutexGuard<'_, BufWriter<Handle>> { self.stdout.lock() }
|
||||||
|
|
||||||
pub fn read_until<P>(&self, timeout: Duration, predicate: P) -> (Vec<u8>, std::io::Result<()>)
|
pub fn read_until<P>(&self, timeout: Duration, predicate: P) -> (Vec<u8>, std::io::Result<()>)
|
||||||
where
|
where
|
||||||
|
|
|
||||||
|
|
@ -75,7 +75,7 @@ impl Input {
|
||||||
pub fn value(&self) -> &str { &self.snap().value }
|
pub fn value(&self) -> &str { &self.snap().value }
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn display(&self) -> Cow<str> {
|
pub fn display(&self) -> Cow<'_, str> {
|
||||||
if self.obscure {
|
if self.obscure {
|
||||||
"•".repeat(self.snap().window(self.limit).len()).into()
|
"•".repeat(self.snap().window(self.limit).len()).into()
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue