Workaround for Rust versions below 1.91.0

This commit is contained in:
sxyazi 2025-10-03 17:12:35 +08:00
parent 27170ce70b
commit c91628484e
No known key found for this signature in database
2 changed files with 11 additions and 5 deletions

View file

@ -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<PathBuf>) -> Self {
let loc = Self::from(path.into());

View file

@ -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<Url<'_>> 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<UrlBuf> = 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]