From c91628484e0053b2f4ab5143d1b3618c23b78e03 Mon Sep 17 00:00:00 2001 From: sxyazi Date: Fri, 3 Oct 2025 17:12:35 +0800 Subject: [PATCH] Workaround for Rust versions below 1.91.0 --- yazi-shared/src/loc/buf.rs | 4 +++- yazi-shared/src/url/buf.rs | 12 ++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/yazi-shared/src/loc/buf.rs b/yazi-shared/src/loc/buf.rs index 1a3ecc51..6b83160c 100644 --- a/yazi-shared/src/loc/buf.rs +++ b/yazi-shared/src/loc/buf.rs @@ -84,7 +84,9 @@ impl LocBuf { Ok(Self { inner: loc.inner, uri, urn }) } - pub const fn empty() -> Self { Self { inner: PathBuf::new(), uri: 0, urn: 0 } } + // FIXME: use `LocBuf::empty()` when Rust 1.91.0 released + // pub const fn empty() -> Self { Self { inner: PathBuf::new(), uri: 0, urn: 0 } + // } pub fn zeroed(path: impl Into) -> Self { let loc = Self::from(path.into()); diff --git a/yazi-shared/src/url/buf.rs b/yazi-shared/src/url/buf.rs index 5c268bbb..bf78a70f 100644 --- a/yazi-shared/src/url/buf.rs +++ b/yazi-shared/src/url/buf.rs @@ -1,4 +1,4 @@ -use std::{borrow::Cow, ffi::OsStr, fmt::{Debug, Formatter}, hash::BuildHasher, path::{Path, PathBuf}, str::FromStr}; +use std::{borrow::Cow, ffi::OsStr, fmt::{Debug, Formatter}, hash::BuildHasher, path::{Path, PathBuf}, str::FromStr, sync::OnceLock}; use anyhow::Result; use serde::{Deserialize, Serialize}; @@ -80,9 +80,13 @@ impl PartialEq> for &UrlBuf { impl UrlBuf { #[inline] - pub const fn new() -> &'static Self { - static U: UrlBuf = UrlBuf { loc: LocBuf::empty(), scheme: Scheme::Regular }; - &U + pub fn new() -> &'static Self { + static U: OnceLock = OnceLock::new(); + U.get_or_init(Self::default) + + // FIXME: use `LocBuf::empty()` when Rust 1.91.0 released + // static U: UrlBuf = UrlBuf { loc: LocBuf::empty(), scheme: Scheme::Regular + // }; &U } #[inline]