Skip to content

Commit

Permalink
Increase MSRV to 1.70.0
Browse files Browse the repository at this point in the history
  • Loading branch information
dylni committed Feb 17, 2024
1 parent 6b5c2ea commit 8797897
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 54 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ jobs:
strategy:
matrix:
platform: [macos-latest, ubuntu-latest, windows-latest]
version: [1.57.0, stable, beta, nightly]
version: [1.70.0, stable, beta, nightly]
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "normpath"
version = "1.1.1"
authors = ["dylni"]
edition = "2021"
rust-version = "1.57.0"
rust-version = "1.70.0"
description = """
More reliable path manipulation
"""
Expand All @@ -29,7 +29,7 @@ windows-sys = { version = "0.52", features = ["Win32_Storage_FileSystem"] }

[dev-dependencies]
bincode = "1.3"
tempfile = "=3.6"
tempfile = "3.2"

[target.'cfg(windows)'.dev-dependencies]
windows-sys = { version = "0.52", features = ["Win32_Foundation"] }
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ See the [documentation] for available functionality and examples.

## Rust version support

The minimum supported Rust toolchain version is currently Rust 1.57.0.
The minimum supported Rust toolchain version is currently Rust 1.70.0.

Minor version updates may increase this version requirement. However, the
previous two Rust releases will always be supported. If the minimum Rust
Expand Down
80 changes: 52 additions & 28 deletions src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ use std::ffi::OsStr;
use std::ffi::OsString;
use std::fs::Metadata;
use std::fs::ReadDir;
use std::hash::Hash;
use std::hash::Hasher;
use std::io;
use std::mem;
use std::ops::Deref;
Expand Down Expand Up @@ -145,7 +147,7 @@ impl BasePath {
pub fn canonicalize(&self) -> io::Result<BasePathBuf> {
self.as_path().canonicalize().map(|base| {
debug_assert!(normalize::is_base(&base));
BasePathBuf(base.into_os_string())
BasePathBuf(base)
})
}

Expand Down Expand Up @@ -463,7 +465,7 @@ impl ToOwned for BasePath {

#[inline]
fn to_owned(&self) -> Self::Owned {
BasePathBuf(self.0.to_owned())
BasePathBuf(self.0.to_owned().into())
}
}

Expand All @@ -472,8 +474,8 @@ impl ToOwned for BasePath {
/// For more information, see [`BasePath`].
///
/// [prefix]: ::std::path::Prefix
#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub struct BasePathBuf(pub(super) OsString);
#[derive(Clone, Debug)]
pub struct BasePathBuf(pub(super) PathBuf);

impl BasePathBuf {
/// Equivalent to [`BasePath::new`] but returns an owned path.
Expand Down Expand Up @@ -529,7 +531,7 @@ impl BasePathBuf {
{
let path = path.into();
if normalize::is_base(&path) {
Ok(Self(path.into_os_string()))
Ok(Self(path))
} else {
Err(MissingPrefixBufError(path))
}
Expand All @@ -539,14 +541,14 @@ impl BasePathBuf {
#[inline]
#[must_use]
pub fn into_os_string(self) -> OsString {
self.0
self.0.into_os_string()
}

/// Returns the wrapped path.
#[inline]
#[must_use]
pub fn into_path_buf(self) -> PathBuf {
self.0.into()
self.0
}

/// Equivalent to [`BasePath::parent`] but modifies `self` in place.
Expand Down Expand Up @@ -574,13 +576,6 @@ impl BasePathBuf {
self.check_parent().map(|()| self.pop_unchecked())
}

pub(super) fn replace_with<F>(&mut self, replace_fn: F)
where
F: FnOnce(PathBuf) -> PathBuf,
{
self.0 = replace_fn(mem::take(&mut self.0).into()).into_os_string();
}

/// Equivalent to [`PathBuf::pop`].
///
/// It is usually better to use [`pop`].
Expand All @@ -602,13 +597,7 @@ impl BasePathBuf {
/// [`pop`]: Self::pop
#[inline]
pub fn pop_unchecked(&mut self) -> bool {
// This value is never used.
let mut result = false;
self.replace_with(|mut base| {
result = base.pop();
base
});
result
self.0.pop()
}

/// Equivalent to [`BasePath::join`] but modifies `self` in place.
Expand Down Expand Up @@ -638,14 +627,14 @@ impl BasePathBuf {
impl AsRef<OsStr> for BasePathBuf {
#[inline]
fn as_ref(&self) -> &OsStr {
&self.0
self.0.as_os_str()
}
}

impl AsRef<Path> for BasePathBuf {
#[inline]
fn as_ref(&self) -> &Path {
self.as_path()
&self.0
}
}

Expand All @@ -668,10 +657,12 @@ impl Deref for BasePathBuf {

#[inline]
fn deref(&self) -> &BasePath {
BasePath::from_inner(&self.0)
BasePath::from_inner(self.0.as_os_str())
}
}

impl Eq for BasePathBuf {}

impl From<BasePathBuf> for Cow<'_, BasePath> {
#[inline]
fn from(value: BasePathBuf) -> Self {
Expand All @@ -682,14 +673,46 @@ impl From<BasePathBuf> for Cow<'_, BasePath> {
impl From<BasePathBuf> for OsString {
#[inline]
fn from(value: BasePathBuf) -> Self {
value.0
value.into_os_string()
}
}

impl From<BasePathBuf> for PathBuf {
#[inline]
fn from(value: BasePathBuf) -> Self {
value.into_path_buf()
value.0
}
}

impl Hash for BasePathBuf {
#[inline]
fn hash<H>(&self, state: &mut H)
where
H: Hasher,
{
(**self).hash(state);
}
}

impl Ord for BasePathBuf {
#[inline]
fn cmp(&self, other: &Self) -> Ordering {
(**self).cmp(&**other)
}
}

impl PartialEq for BasePathBuf {
#[inline]
fn eq(&self, other: &Self) -> bool {
**self == **other
}
}

impl PartialOrd for BasePathBuf {
#[allow(clippy::incorrect_partial_ord_impl_on_ord_type)]
#[inline]
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
(**self).partial_cmp(&**other)
}
}

Expand Down Expand Up @@ -750,7 +773,7 @@ mod serde {
where
D: Deserializer<'de>,
{
OsString::deserialize(deserializer).map(Self)
OsString::deserialize(deserializer).map(|x| Self(x.into()))
}
}

Expand All @@ -770,7 +793,8 @@ mod serde {
where
S: Serializer,
{
serializer.serialize_newtype_struct("BasePathBuf", &self.0)
serializer
.serialize_newtype_struct("BasePathBuf", self.as_os_str())
}
}
}
Expand Down
5 changes: 1 addition & 4 deletions src/common/normalize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ pub(super) fn normalize(path: &Path) -> io::Result<BasePathBuf> {

pub(super) fn push(base: &mut BasePathBuf, path: &Path) {
if !path.as_os_str().is_empty() {
base.replace_with(|mut base| {
base.push(path);
base
});
base.0.push(path);
}
}
4 changes: 1 addition & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,9 +287,7 @@ impl PathExt for Path {
#[cfg(feature = "localization")]
#[inline]
fn localize_name(&self) -> Cow<'_, OsStr> {
let name = if let Some(name) = self.components().next_back() {
name
} else {
let Some(name) = self.components().next_back() else {
return Cow::Borrowed(OsStr::new(""));
};
assert_ne!(
Expand Down
21 changes: 9 additions & 12 deletions src/windows/normalize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub(super) fn to_base(path: &Path) -> io::Result<BasePathBuf> {
let base = env::current_dir()?;
debug_assert!(is_base(&base));

let mut base = BasePathBuf(base.into_os_string());
let mut base = BasePathBuf(base);
base.push(path);
Ok(base)
}
Expand All @@ -57,7 +57,7 @@ fn normalize_verbatim(path: &Path) -> BasePathBuf {
*ch = SEPARATOR;
}
}
BasePathBuf(OsString::from_wide(&path))
BasePathBuf(OsString::from_wide(&path).into())
}

pub(super) fn normalize_virtually(
Expand Down Expand Up @@ -138,7 +138,7 @@ pub(super) fn normalize_virtually(
unsafe {
buffer.set_len(length);
}
break Ok(BasePathBuf(OsString::from_wide(&buffer)));
break Ok(BasePathBuf(OsString::from_wide(&buffer).into()));
}
}

Expand All @@ -159,11 +159,8 @@ fn get_prefix(base: &BasePath) -> PrefixComponent<'_> {
}

fn push_separator(base: &mut BasePathBuf) {
base.replace_with(|mut base| {
// Add a separator if necessary.
base.push("");
base
});
// Add a separator if necessary.
base.0.push("");
}

pub(super) fn push(base: &mut BasePathBuf, initial_path: &Path) {
Expand All @@ -187,14 +184,14 @@ pub(super) fn push(base: &mut BasePathBuf, initial_path: &Path) {
// Equivalent to [path.has_root()] but more efficient.
|| next_component == Some(Component::RootDir)
{
*base = BasePathBuf(path.into_os_string());
*base = BasePathBuf(path);
return;
}
}
Some(Component::RootDir) => {
let mut buffer = get_prefix(base).as_os_str().to_owned();
buffer.push(path);
*base = BasePathBuf(buffer);
*base = BasePathBuf(buffer.into());
return;
}
_ => {
Expand All @@ -211,12 +208,12 @@ pub(super) fn push(base: &mut BasePathBuf, initial_path: &Path) {

if let Some(component) = next_component {
push_separator(base);
base.0.push(component);
base.0.as_mut_os_string().push(component);

let components = components.as_path();
if !components.as_os_str().is_empty() {
push_separator(base);
base.0.push(components);
base.0.as_mut_os_string().push(components);
}
}

Expand Down
4 changes: 1 addition & 3 deletions tests/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ where

impl PartialEq<Result<&Path, &io::Error>> for Wrapper<'_> {
fn eq(&self, other: &Result<&Path, &io::Error>) -> bool {
other
.map(|x| self.0.as_os_str() == x.as_os_str())
.unwrap_or(false)
other.is_ok_and(|x| self.0.as_os_str() == x.as_os_str())
}
}

Expand Down

0 comments on commit 8797897

Please sign in to comment.