Disallow mutation for Canonical
Path
s and PathBuf
s
This commit is contained in:
parent
dd569b1237
commit
dfe3070b18
|
@ -20,7 +20,7 @@ pub trait PathJoin: PathForm {
|
|||
|
||||
pub trait PathPush: PathForm {}
|
||||
|
||||
pub trait PathSet: PathForm {}
|
||||
pub trait PathMut: PathForm {}
|
||||
|
||||
/// A path whose form is unknown. It could be a relative, absolute, or canonical path.
|
||||
///
|
||||
|
@ -36,7 +36,7 @@ impl PathJoin for Any {
|
|||
type Output = Self;
|
||||
}
|
||||
impl PathPush for Any {}
|
||||
impl PathSet for Any {}
|
||||
impl PathMut for Any {}
|
||||
|
||||
/// A strictly relative path.
|
||||
///
|
||||
|
@ -51,7 +51,7 @@ impl MaybeRelative for Relative {}
|
|||
impl PathJoin for Relative {
|
||||
type Output = Any;
|
||||
}
|
||||
impl PathSet for Relative {}
|
||||
impl PathMut for Relative {}
|
||||
|
||||
/// An absolute path.
|
||||
///
|
||||
|
@ -68,7 +68,7 @@ impl PathJoin for Absolute {
|
|||
type Output = Self;
|
||||
}
|
||||
impl PathPush for Absolute {}
|
||||
impl PathSet for Absolute {}
|
||||
impl PathMut for Absolute {}
|
||||
|
||||
// A canonical path.
|
||||
//
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use crate::form::{
|
||||
Absolute, Any, Canonical, IsAbsolute, MaybeAbsolute, MaybeRelative, PathCast, PathForm,
|
||||
PathJoin, PathPush, PathSet, Relative,
|
||||
PathJoin, PathMut, PathPush, Relative,
|
||||
};
|
||||
use std::{
|
||||
borrow::{Borrow, Cow},
|
||||
|
@ -45,11 +45,6 @@ impl<Form: PathForm> Path<Form> {
|
|||
self.inner.as_os_str()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn as_mut_os_str(&mut self) -> &mut OsStr {
|
||||
self.inner.as_mut_os_str()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn to_str(&self) -> Option<&str> {
|
||||
self.inner.to_str()
|
||||
|
@ -186,7 +181,12 @@ impl<Form: PathJoin> Path<Form> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<Form: PathSet> Path<Form> {
|
||||
impl<Form: PathMut> Path<Form> {
|
||||
#[inline]
|
||||
pub fn as_mut_os_str(&mut self) -> &mut OsStr {
|
||||
self.inner.as_mut_os_str()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn with_file_name(&self, file_name: impl AsRef<OsStr>) -> PathBuf<Form> {
|
||||
PathBuf::new_unchecked(self.inner.with_file_name(file_name))
|
||||
|
@ -366,11 +366,6 @@ impl<Form: PathForm> PathBuf<Form> {
|
|||
self.inner.pop()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn as_mut_os_string(&mut self) -> &mut OsString {
|
||||
self.inner.as_mut_os_string()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn into_os_string(self) -> OsString {
|
||||
self.inner.into_os_string()
|
||||
|
@ -473,7 +468,12 @@ impl<Form: PathPush> PathBuf<Form> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<Form: PathSet> PathBuf<Form> {
|
||||
impl<Form: PathMut> PathBuf<Form> {
|
||||
#[inline]
|
||||
pub fn as_mut_os_string(&mut self) -> &mut OsString {
|
||||
self.inner.as_mut_os_string()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn set_file_name(&mut self, file_name: impl AsRef<OsStr>) {
|
||||
self.inner.set_file_name(file_name)
|
||||
|
@ -538,7 +538,7 @@ impl<Form: PathForm> Deref for PathBuf<Form> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<Form: PathForm> DerefMut for PathBuf<Form> {
|
||||
impl<Form: PathMut> DerefMut for PathBuf<Form> {
|
||||
#[inline]
|
||||
fn deref_mut(&mut self) -> &mut Self::Target {
|
||||
// Safety: `Path<Form>` is a repr(transparent) wrapper around `std::path::Path`.
|
||||
|
|
Loading…
Reference in New Issue
Block a user