refactor: use Self where possible (#3138)

This commit is contained in:
adamnemecek 2025-09-05 09:48:30 -07:00 committed by GitHub
parent e795d6cf42
commit 021d86f0d1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
42 changed files with 112 additions and 112 deletions

View file

@ -40,7 +40,7 @@ impl<'a> Ctx<'a> {
}
#[inline]
pub fn renew<'b>(cx: &'a mut Ctx<'b>) -> Ctx<'a> {
pub fn renew<'b>(cx: &'a mut Ctx<'b>) -> Self {
let tab = cx.core.mgr.tabs.cursor;
Self { core: cx.core, tab, level: cx.level, source: cx.source }
}

View file

@ -50,7 +50,7 @@ impl Mux {
pub fn tmux_drain() -> Result<()> {
if TMUX.get() {
crossterm::execute!(TTY.writer(), crossterm::style::Print(Mux::csi("\x1b[5n")))?;
crossterm::execute!(TTY.writer(), crossterm::style::Print(Self::csi("\x1b[5n")))?;
_ = Emulator::read_until_dsr();
}
Ok(())

View file

@ -26,7 +26,7 @@ pub struct Border {
impl Border {
pub fn compose(lua: &Lua) -> mlua::Result<Value> {
let new = lua.create_function(|_, (_, edge): (Table, Edge)| {
Ok(Border { edge, r#type: ratatui::widgets::BorderType::Rounded, ..Default::default() })
Ok(Self { edge, r#type: ratatui::widgets::BorderType::Rounded, ..Default::default() })
})?;
let border = lua.create_table_from([

View file

@ -14,7 +14,7 @@ pub struct Clear {
impl Clear {
pub fn compose(lua: &Lua) -> mlua::Result<Value> {
let new = lua.create_function(|_, (_, area): (Table, Area)| Ok(Clear { area }))?;
let new = lua.create_function(|_, (_, area): (Table, Area)| Ok(Self { area }))?;
let clear = lua.create_table()?;
clear.set_metatable(Some(lua.create_table_from([(MetaMethod::Call.name(), new)])?))?;

View file

@ -16,7 +16,7 @@ pub struct Gauge {
impl Gauge {
pub fn compose(lua: &Lua) -> mlua::Result<Value> {
let new = lua.create_function(|_, _: Table| Ok(Gauge::default()))?;
let new = lua.create_function(|_, _: Table| Ok(Self::default()))?;
let gauge = lua.create_table()?;
gauge.set_metatable(Some(lua.create_table_from([(MetaMethod::Call.name(), new)])?))?;

View file

@ -29,20 +29,20 @@ impl DerefMut for Line {
impl Line {
pub fn compose(lua: &Lua) -> mlua::Result<Value> {
let new = lua.create_function(|_, (_, value): (Table, Value)| Line::try_from(value))?;
let new = lua.create_function(|_, (_, value): (Table, Value)| Self::try_from(value))?;
let parse = lua.create_function(|_, code: mlua::String| {
let code = code.as_bytes();
let Some(line) = code.split_inclusive(|&b| b == b'\n').next() else {
return Ok(Line::default());
return Ok(Self::default());
};
let mut lines = line.into_text().into_lua_err()?.lines;
if lines.is_empty() {
return Ok(Line::default());
return Ok(Self::default());
}
Ok(Line { inner: mem::take(&mut lines[0]), ..Default::default() })
Ok(Self { inner: mem::take(&mut lines[0]), ..Default::default() })
})?;
let line = lua.create_table_from([("parse", parse)])?;
@ -90,7 +90,7 @@ impl TryFrom<Table> for Line {
Value::UserData(ud) => {
if let Ok(Span(span)) = ud.take() {
spans.push(span);
} else if let Ok(Line { inner: mut line, .. }) = ud.take() {
} else if let Ok(Self { inner: mut line, .. }) = ud.take() {
line.spans.iter_mut().for_each(|s| s.style = line.style.patch(s.style));
spans.extend(line.spans);
} else {

View file

@ -83,6 +83,6 @@ impl UserData for Rect {
fn add_methods<M: mlua::UserDataMethods<Self>>(methods: &mut M) {
methods.add_method("pad", |_, me, pad: Pad| Ok(me.pad(pad)));
methods.add_method("contains", |_, me, Rect(rect)| Ok(me.contains(rect.into())));
methods.add_method("contains", |_, me, Self(rect)| Ok(me.contains(rect.into())));
}
}

View file

@ -19,7 +19,7 @@ impl DerefMut for Span {
impl Span {
pub fn compose(lua: &Lua) -> mlua::Result<Value> {
let new = lua.create_function(|_, (_, value): (Table, Value)| Span::try_from(value))?;
let new = lua.create_function(|_, (_, value): (Table, Value)| Self::try_from(value))?;
let span = lua.create_table()?;
span.set_metatable(Some(lua.create_table_from([(MetaMethod::Call.name(), new)])?))?;
@ -65,7 +65,7 @@ impl TryFrom<Value> for Span {
Ok(Self(match value {
Value::String(s) => s.to_string_lossy().into(),
Value::UserData(ud) => {
if let Ok(Span(span)) = ud.take() {
if let Ok(Self(span)) = ud.take() {
span
} else {
Err(EXPECTED.into_lua_err())?
@ -81,7 +81,7 @@ impl UserData for Span {
crate::impl_style_method!(methods, 0.style);
crate::impl_style_shorthands!(methods, 0.style);
methods.add_method("visible", |_, Span(me), ()| {
methods.add_method("visible", |_, Self(me), ()| {
Ok(me.content.chars().any(|c| c.width().unwrap_or(0) > 0))
});
methods.add_function_mut("truncate", |_, (ud, t): (AnyUserData, Table)| {

View file

@ -21,10 +21,10 @@ pub struct Text {
impl Text {
pub fn compose(lua: &Lua) -> mlua::Result<Value> {
let new = lua.create_function(|_, (_, value): (Table, Value)| Text::try_from(value))?;
let new = lua.create_function(|_, (_, value): (Table, Value)| Self::try_from(value))?;
let parse = lua.create_function(|_, code: mlua::String| {
Ok(Text { inner: code.as_bytes().into_text().into_lua_err()?, ..Default::default() })
Ok(Self { inner: code.as_bytes().into_text().into_lua_err()?, ..Default::default() })
})?;
let text = lua.create_table_from([("parse", parse)])?;
@ -51,7 +51,7 @@ impl TryFrom<Value> for Text {
Value::UserData(ud) => match ud.type_id() {
Some(t) if t == TypeId::of::<Line>() => ud.take::<Line>()?.inner.into(),
Some(t) if t == TypeId::of::<Span>() => ud.take::<Span>()?.0.into(),
Some(t) if t == TypeId::of::<Text>() => return ud.take(),
Some(t) if t == TypeId::of::<Self>() => return ud.take(),
Some(t) if t == TypeId::of::<Error>() => ud.take::<Error>()?.into_string().into(),
_ => Err(EXPECTED.into_lua_err())?,
},

View file

@ -14,7 +14,7 @@ pub enum Error {
impl Error {
pub fn install(lua: &Lua) -> mlua::Result<()> {
let new = lua.create_function(|_, msg: String| Ok(Error::custom(msg)))?;
let new = lua.create_function(|_, msg: String| Ok(Self::custom(msg)))?;
lua.globals().raw_set("Error", lua.create_table_from([("custom", new)])?)
}
@ -23,10 +23,10 @@ impl Error {
pub fn into_string(self) -> SStr {
match self {
Error::Io(e) => Cow::Owned(e.to_string()),
Error::IoKind(e) => Cow::Owned(e.to_string()),
Error::Serde(e) => Cow::Owned(e.to_string()),
Error::Custom(s) => s,
Self::Io(e) => Cow::Owned(e.to_string()),
Self::IoKind(e) => Cow::Owned(e.to_string()),
Self::Serde(e) => Cow::Owned(e.to_string()),
Self::Custom(s) => s,
}
}
}
@ -34,10 +34,10 @@ impl Error {
impl Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Error::Io(e) => write!(f, "{e}"),
Error::IoKind(e) => write!(f, "{e}"),
Error::Serde(e) => write!(f, "{e}"),
Error::Custom(s) => write!(f, "{s}"),
Self::Io(e) => write!(f, "{e}"),
Self::IoKind(e) => write!(f, "{e}"),
Self::Serde(e) => write!(f, "{e}"),
Self::Custom(s) => write!(f, "{s}"),
}
}
}
@ -55,7 +55,7 @@ impl UserData for Error {
fn add_fields<F: UserDataFields<Self>>(fields: &mut F) {
fields.add_field_method_get("code", |_, me| {
Ok(match me {
Error::Io(e) => e.raw_os_error(),
Self::Io(e) => e.raw_os_error(),
_ => None,
})
});
@ -64,8 +64,8 @@ impl UserData for Error {
fn add_methods<M: UserDataMethods<Self>>(methods: &mut M) {
methods.add_meta_method(MetaMethod::ToString, |lua, me, ()| {
Ok(match me {
Error::Io(_) | Error::IoKind(_) | Error::Serde(_) => lua.create_string(me.to_string()),
Error::Custom(s) => lua.create_string(s.as_ref()),
Self::Io(_) | Self::IoKind(_) | Self::Serde(_) => lua.create_string(me.to_string()),
Self::Custom(s) => lua.create_string(s.as_ref()),
})
});
methods.add_meta_function(MetaMethod::Concat, |lua, (lhs, rhs): (Value, Value)| {

View file

@ -44,7 +44,7 @@ impl<'a> From<&'a Url> for UrlCow<'a> {
}
impl From<Url> for yazi_shared::url::UrlBufCov {
fn from(value: Url) -> Self { UrlBufCov(value.inner) }
fn from(value: Url) -> Self { Self(value.inner) }
}
impl TryFrom<&[u8]> for Url {

View file

@ -31,7 +31,7 @@ pub struct Style {
impl From<Style> for ratatui::style::Style {
fn from(value: Style) -> Self {
ratatui::style::Style {
Self {
fg: value.fg.map(Into::into),
bg: value.bg.map(Into::into),
underline_color: None,
@ -43,33 +43,33 @@ impl From<Style> for ratatui::style::Style {
impl From<Style> for ratatui::style::Modifier {
fn from(value: Style) -> Self {
let mut modifier = Modifier::empty();
let mut modifier = Self::empty();
if value.bold {
modifier |= Modifier::BOLD;
modifier |= Self::BOLD;
}
if value.dim {
modifier |= Modifier::DIM;
modifier |= Self::DIM;
}
if value.italic {
modifier |= Modifier::ITALIC;
modifier |= Self::ITALIC;
}
if value.underline {
modifier |= Modifier::UNDERLINED;
modifier |= Self::UNDERLINED;
}
if value.blink {
modifier |= Modifier::SLOW_BLINK;
modifier |= Self::SLOW_BLINK;
}
if value.blink_rapid {
modifier |= Modifier::RAPID_BLINK;
modifier |= Self::RAPID_BLINK;
}
if value.reversed {
modifier |= Modifier::REVERSED;
modifier |= Self::REVERSED;
}
if value.hidden {
modifier |= Modifier::HIDDEN;
modifier |= Self::HIDDEN;
}
if value.crossed {
modifier |= Modifier::CROSSED_OUT;
modifier |= Self::CROSSED_OUT;
}
modifier
}

View file

@ -11,35 +11,35 @@ pub enum Mode {
impl Mode {
pub fn visual_mut(&mut self) -> Option<(usize, &mut BTreeSet<usize>)> {
match self {
Mode::Normal => None,
Mode::Select(start, indices) => Some((*start, indices)),
Mode::Unset(start, indices) => Some((*start, indices)),
Self::Normal => None,
Self::Select(start, indices) => Some((*start, indices)),
Self::Unset(start, indices) => Some((*start, indices)),
}
}
pub fn take_visual(&mut self) -> Option<(usize, BTreeSet<usize>)> {
match mem::take(self) {
Mode::Normal => None,
Mode::Select(start, indices) => Some((start, indices)),
Mode::Unset(start, indices) => Some((start, indices)),
Self::Normal => None,
Self::Select(start, indices) => Some((start, indices)),
Self::Unset(start, indices) => Some((start, indices)),
}
}
}
impl Mode {
pub fn is_select(&self) -> bool { matches!(self, Mode::Select(..)) }
pub fn is_select(&self) -> bool { matches!(self, Self::Select(..)) }
pub fn is_unset(&self) -> bool { matches!(self, Mode::Unset(..)) }
pub fn is_unset(&self) -> bool { matches!(self, Self::Unset(..)) }
pub fn is_visual(&self) -> bool { matches!(self, Mode::Select(..) | Mode::Unset(..)) }
pub fn is_visual(&self) -> bool { matches!(self, Self::Select(..) | Self::Unset(..)) }
}
impl Display for Mode {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(match self {
Mode::Normal => "normal",
Mode::Select(..) => "select",
Mode::Unset(..) => "unset",
Self::Normal => "normal",
Self::Select(..) => "select",
Self::Unset(..) => "unset",
})
}
}

View file

@ -34,7 +34,7 @@ impl Default for Preference {
impl From<&Preference> for FilesSorter {
fn from(value: &Preference) -> Self {
FilesSorter {
Self {
by: value.sort_by,
sensitive: value.sort_sensitive,
reverse: value.sort_reverse,

View file

@ -10,26 +10,26 @@ impl DirEntry {
#[must_use]
pub fn url(&self) -> UrlBuf {
match self {
DirEntry::Local(local) => local.url(),
Self::Local(local) => local.url(),
}
}
#[must_use]
pub fn file_name(&self) -> OsString {
match self {
DirEntry::Local(local) => local.file_name(),
Self::Local(local) => local.file_name(),
}
}
pub async fn metadata(&self) -> io::Result<std::fs::Metadata> {
match self {
DirEntry::Local(local) => local.metadata().await,
Self::Local(local) => local.metadata().await,
}
}
pub async fn file_type(&self) -> io::Result<std::fs::FileType> {
match self {
DirEntry::Local(local) => local.file_type().await,
Self::Local(local) => local.file_type().await,
}
}
}
@ -43,26 +43,26 @@ impl DirEntrySync {
#[must_use]
pub fn url(&self) -> UrlBuf {
match self {
DirEntrySync::Local(local) => local.url(),
Self::Local(local) => local.url(),
}
}
#[must_use]
pub fn file_name(&self) -> OsString {
match self {
DirEntrySync::Local(local) => local.file_name(),
Self::Local(local) => local.file_name(),
}
}
pub fn metadata(&self) -> io::Result<std::fs::Metadata> {
match self {
DirEntrySync::Local(local) => local.metadata(),
Self::Local(local) => local.metadata(),
}
}
pub fn file_type(&self) -> io::Result<std::fs::FileType> {
match self {
DirEntrySync::Local(local) => local.file_type(),
Self::Local(local) => local.file_type(),
}
}
}

View file

@ -15,7 +15,7 @@ impl From<tokio::fs::DirEntry> for DirEntry {
}
impl From<DirEntry> for crate::provider::DirEntry {
fn from(value: DirEntry) -> Self { crate::provider::DirEntry::Local(value) }
fn from(value: DirEntry) -> Self { Self::Local(value) }
}
impl DirEntry {
@ -37,7 +37,7 @@ impl From<std::fs::DirEntry> for DirEntrySync {
}
impl From<DirEntrySync> for crate::provider::DirEntrySync {
fn from(value: DirEntrySync) -> Self { crate::provider::DirEntrySync::Local(value) }
fn from(value: DirEntrySync) -> Self { Self::Local(value) }
}
impl DirEntrySync {

View file

@ -9,7 +9,7 @@ impl From<tokio::fs::ReadDir> for ReadDir {
}
impl From<ReadDir> for crate::provider::ReadDir {
fn from(value: ReadDir) -> Self { crate::provider::ReadDir::Local(value) }
fn from(value: ReadDir) -> Self { Self::Local(value) }
}
impl ReadDir {
@ -26,7 +26,7 @@ impl From<std::fs::ReadDir> for ReadDirSync {
}
impl From<ReadDirSync> for crate::provider::ReadDirSync {
fn from(value: ReadDirSync) -> Self { crate::provider::ReadDirSync::Local(value) }
fn from(value: ReadDirSync) -> Self { Self::Local(value) }
}
impl Iterator for ReadDirSync {

View file

@ -5,7 +5,7 @@ impl From<tokio::fs::File> for RwFile {
}
impl From<RwFile> for crate::provider::RwFile {
fn from(value: RwFile) -> Self { crate::provider::RwFile::Local(value) }
fn from(value: RwFile) -> Self { Self::Local(value) }
}
impl From<tokio::fs::File> for crate::provider::RwFile {

View file

@ -9,7 +9,7 @@ pub enum ReadDir {
impl ReadDir {
pub async fn next_entry(&mut self) -> io::Result<Option<DirEntry>> {
match self {
ReadDir::Local(local) => local.next_entry().await.map(|entry| entry.map(Into::into)),
Self::Local(local) => local.next_entry().await.map(|entry| entry.map(Into::into)),
}
}
}
@ -24,7 +24,7 @@ impl Iterator for ReadDirSync {
fn next(&mut self) -> Option<io::Result<DirEntrySync>> {
match self {
ReadDirSync::Local(local) => local.next().map(|result| result.map(Into::into)),
Self::Local(local) => local.next().map(|result| result.map(Into::into)),
}
}
}

View file

@ -7,7 +7,7 @@ pub enum RwFile {
impl RwFile {
pub fn reader(self) -> Box<dyn BufRead> {
match self {
RwFile::Local(local) => Box::new(local.reader()),
Self::Local(local) => Box::new(local.reader()),
}
}
}

View file

@ -26,8 +26,8 @@ impl TryFrom<CmdCow> for ShowOpt {
}
}
impl From<Box<ShowOpt>> for ShowOpt {
fn from(value: Box<ShowOpt>) -> Self { *value }
impl From<Box<Self>> for ShowOpt {
fn from(value: Box<Self>) -> Self { *value }
}
impl FromLua for ShowOpt {

View file

@ -15,7 +15,7 @@ bitflags! {
impl From<CmdCow> for EscapeOpt {
fn from(c: CmdCow) -> Self {
c.args.iter().fold(EscapeOpt::empty(), |acc, (k, v)| {
c.args.iter().fold(Self::empty(), |acc, (k, v)| {
match (k.as_str().unwrap_or(""), v.as_bool().unwrap_or(false)) {
("all", true) => Self::all(),
("find", true) => acc | Self::FIND,

View file

@ -19,7 +19,7 @@ impl From<CmdCow> for QuitOpt {
impl From<QuitOpt> for EventQuit {
fn from(value: QuitOpt) -> Self {
EventQuit { code: value.code, no_cwd_file: value.no_cwd_file, ..Default::default() }
Self { code: value.code, no_cwd_file: value.no_cwd_file, ..Default::default() }
}
}

View file

@ -9,5 +9,5 @@ pub struct TaskSnap {
}
impl From<&Task> for TaskSnap {
fn from(task: &Task) -> Self { TaskSnap { name: task.name.clone(), prog: task.prog } }
fn from(task: &Task) -> Self { Self { name: task.name.clone(), prog: task.prog } }
}

View file

@ -36,9 +36,9 @@ impl ConditionOp {
#[inline]
pub fn prec(&self) -> u8 {
match self {
ConditionOp::Or => 1,
ConditionOp::And => 2,
ConditionOp::Not => 3,
Self::Or => 1,
Self::And => 2,
Self::Not => 3,
_ => 0,
}
}

View file

@ -18,7 +18,7 @@ impl<S> Debounce<S>
where
S: Stream + Unpin,
{
pub fn new(stream: S, interval: Duration) -> Debounce<S> {
pub fn new(stream: S, interval: Duration) -> Self {
Self { stream, interval, sleep: sleep(Duration::ZERO), last: None }
}
}

View file

@ -7,28 +7,28 @@ pub enum Either<L, R> {
impl<L, R> Either<L, R> {
pub fn left(&self) -> Option<&L> {
match self {
Either::Left(l) => Some(l),
Self::Left(l) => Some(l),
_ => None,
}
}
pub fn right(&self) -> Option<&R> {
match self {
Either::Right(r) => Some(r),
Self::Right(r) => Some(r),
_ => None,
}
}
pub fn left_mut(&mut self) -> Option<&mut L> {
match self {
Either::Left(l) => Some(l),
Self::Left(l) => Some(l),
_ => None,
}
}
pub fn right_mut(&mut self) -> Option<&mut R> {
match self {
Either::Right(r) => Some(r),
Self::Right(r) => Some(r),
_ => None,
}
}
@ -43,28 +43,28 @@ impl<L, R> Either<L, R> {
pub fn into_left(self) -> Option<L> {
match self {
Either::Left(l) => Some(l),
Self::Left(l) => Some(l),
_ => None,
}
}
pub fn into_right(self) -> Option<R> {
match self {
Either::Right(r) => Some(r),
Self::Right(r) => Some(r),
_ => None,
}
}
pub fn left_or_err<E, F: FnOnce() -> E>(self, f: F) -> Result<L, E> {
match self {
Either::Left(l) => Ok(l),
Self::Left(l) => Ok(l),
_ => Err(f()),
}
}
pub fn right_or_err<E, F: FnOnce() -> E>(self, f: F) -> Result<R, E> {
match self {
Either::Right(r) => Ok(r),
Self::Right(r) => Ok(r),
_ => Err(f()),
}
}

View file

@ -215,7 +215,7 @@ impl FromStr for Cmd {
}
let mut me = Self::new(mem::take(&mut words[0]), Default::default(), Some(Default::default()))?;
me.args = Cmd::parse_args(words.into_iter().skip(1), last, true)?;
me.args = Self::parse_args(words.into_iter().skip(1), last, true)?;
Ok(me)
}
}

View file

@ -57,7 +57,7 @@ impl Data {
}
#[inline]
pub fn into_dict(self) -> Option<HashMap<DataKey, Data>> {
pub fn into_dict(self) -> Option<HashMap<DataKey, Self>> {
match self {
Self::Dict(d) => Some(d),
_ => None,

View file

@ -37,7 +37,7 @@ impl Event {
}
#[inline]
pub fn take() -> mpsc::UnboundedReceiver<Event> { RX.drop() }
pub fn take() -> mpsc::UnboundedReceiver<Self> { RX.drop() }
#[inline]
pub fn emit(self) { TX.send(self).ok(); }

View file

@ -128,7 +128,7 @@ impl<'a> Loc<'a> {
}
#[inline]
pub fn as_loc(self) -> Loc<'a> { self }
pub fn as_loc(self) -> Self { self }
#[inline]
pub fn as_path(self) -> &'a Path { self.inner }

View file

@ -75,7 +75,7 @@ impl OsStrSplit for OsStr {
let (a, b) = bytes.split_at(i);
// SAFETY: These substrings were separated by a UTF-8 string.
return Some(unsafe {
(OsStr::from_encoded_bytes_unchecked(a), OsStr::from_encoded_bytes_unchecked(&b[1..]))
(Self::from_encoded_bytes_unchecked(a), Self::from_encoded_bytes_unchecked(&b[1..]))
});
}
None
@ -87,7 +87,7 @@ pub trait Pattern {
}
impl Pattern for char {
fn predicate(&self, byte: u8) -> bool { *self == byte as char }
fn predicate(&self, byte: u8) -> bool { *self == byte as Self }
}
impl Pattern for &[char] {

View file

@ -20,7 +20,7 @@ impl<T: ?Sized> Clone for Symbol<T> {
RawEntryMut::Occupied(mut oe) => *oe.get_mut() += 1,
RawEntryMut::Vacant(_) => unreachable!(),
}
Symbol::new(self.ptr.clone())
Self::new(self.ptr.clone())
}
}

View file

@ -17,5 +17,5 @@ pub enum Source {
impl Source {
#[inline]
pub fn is_key(self) -> bool { self == Source::Key }
pub fn is_key(self) -> bool { self == Self::Key }
}

View file

@ -28,7 +28,7 @@ impl<T> Deref for SyncCell<T> {
impl<T: Copy> Clone for SyncCell<T> {
#[inline]
fn clone(&self) -> SyncCell<T> { SyncCell::new(self.get()) }
fn clone(&self) -> Self { Self::new(self.get()) }
}
impl<T: Copy + Debug> Debug for SyncCell<T> {

View file

@ -27,8 +27,8 @@ impl From<Url<'_>> for UrlBuf {
fn from(url: Url<'_>) -> Self { Self { loc: url.loc.into(), scheme: url.scheme.into() } }
}
impl From<&UrlBuf> for UrlBuf {
fn from(url: &UrlBuf) -> Self { url.clone() }
impl From<&Self> for UrlBuf {
fn from(url: &Self) -> Self { url.clone() }
}
impl From<&PathBuf> for UrlBuf {
@ -53,8 +53,8 @@ impl TryFrom<String> for UrlBuf {
}
}
impl AsRef<UrlBuf> for UrlBuf {
fn as_ref(&self) -> &UrlBuf { self }
impl AsRef<Self> for UrlBuf {
fn as_ref(&self) -> &Self { self }
}
impl<'a> From<&'a UrlBuf> for Cow<'a, UrlBuf> {
@ -65,8 +65,8 @@ impl From<UrlBuf> for Cow<'_, UrlBuf> {
fn from(url: UrlBuf) -> Self { Cow::Owned(url) }
}
impl From<Cow<'_, UrlBuf>> for UrlBuf {
fn from(url: Cow<'_, UrlBuf>) -> Self { url.into_owned() }
impl From<Cow<'_, Self>> for UrlBuf {
fn from(url: Cow<'_, Self>) -> Self { url.into_owned() }
}
// --- Eq
@ -253,7 +253,7 @@ impl Debug for UrlBuf {
impl Serialize for UrlBuf {
fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let UrlBuf { scheme, loc } = self;
let Self { scheme, loc } = self;
match (scheme.is_virtual(), loc.to_str()) {
(false, Some(s)) => serializer.serialize_str(s),
(true, Some(s)) => serializer.serialize_str(&format!("{}{s}", Encode::from(self))),

View file

@ -43,7 +43,7 @@ impl<'a> FromIterator<Component<'a>> for UrlBuf {
impl<'a> FromIterator<Component<'a>> for PathBuf {
fn from_iter<I: IntoIterator<Item = Component<'a>>>(iter: I) -> Self {
let mut buf = PathBuf::new();
let mut buf = Self::new();
iter.into_iter().for_each(|c| match c {
Component::Scheme(_) => {}
Component::Prefix(p) => buf.push(path::Component::Prefix(p)),

View file

@ -95,5 +95,5 @@ impl UrlBufCov {
pub fn as_url(&self) -> UrlCov<'_> { UrlCov::from(self) }
#[inline]
pub fn parent(&self) -> Option<UrlBufCov> { self.0.parent().map(Into::into) }
pub fn parent(&self) -> Option<Self> { self.0.parent().map(Into::into) }
}

View file

@ -166,7 +166,7 @@ impl<'a> Url<'a> {
}
#[inline]
pub fn pair(self) -> Option<(Url<'a>, &'a Urn)> { Some((self.parent()?, self.loc.urn())) }
pub fn pair(self) -> Option<(Self, &'a Urn)> { Some((self.parent()?, self.loc.urn())) }
#[inline]
pub fn as_path(self) -> Option<&'a Path> {

View file

@ -20,7 +20,7 @@ impl Backend {
Self { local: backend::Local::serve(out_tx) }
}
pub(crate) async fn sync(mut self, to_unwatch: Vec<UrlBuf>, to_watch: Vec<UrlBuf>) -> Backend {
pub(crate) async fn sync(mut self, to_unwatch: Vec<UrlBuf>, to_watch: Vec<UrlBuf>) -> Self {
if to_unwatch.is_empty() && to_watch.is_empty() {
return self;
}

View file

@ -8,5 +8,5 @@ pub enum InputMode {
impl InputMode {
#[inline]
pub(super) fn delta(&self) -> usize { (*self != InputMode::Insert) as usize }
pub(super) fn delta(&self) -> usize { (*self != Self::Insert) as usize }
}

View file

@ -13,10 +13,10 @@ impl InputOp {
#[inline]
pub(super) fn start(&self) -> Option<usize> {
match self {
InputOp::None => None,
InputOp::Select(s) => Some(*s),
InputOp::Delete(.., s) => Some(*s),
InputOp::Yank(s) => Some(*s),
Self::None => None,
Self::Select(s) => Some(*s),
Self::Delete(.., s) => Some(*s),
Self::Yank(s) => Some(*s),
}
}