Rollup merge of #81281 - a1phyr:inline_path, r=dtolnay

Inline methods of Path and OsString

These methods are not generic, and therefore aren't candidates for cross-crate inlining without an `#[inline]` attribute.
This commit is contained in:
Jonas Schievink 2021-01-23 20:16:12 +01:00 committed by GitHub
commit 44c668cfca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 103 additions and 0 deletions

View File

@ -111,6 +111,7 @@ impl OsString {
/// let os_string = OsString::new();
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
pub fn new() -> OsString {
OsString { inner: Buf::from_string(String::new()) }
}
@ -127,6 +128,7 @@ impl OsString {
/// assert_eq!(os_string.as_os_str(), os_str);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
pub fn as_os_str(&self) -> &OsStr {
self
}
@ -145,6 +147,7 @@ impl OsString {
/// assert_eq!(string, Ok(String::from("foo")));
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
pub fn into_string(self) -> Result<String, OsString> {
self.inner.into_string().map_err(|buf| OsString { inner: buf })
}
@ -163,6 +166,7 @@ impl OsString {
/// assert_eq!(&os_string, "foobar");
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
pub fn push<T: AsRef<OsStr>>(&mut self, s: T) {
self.inner.push_slice(&s.as_ref().inner)
}
@ -189,6 +193,7 @@ impl OsString {
/// assert_eq!(capacity, os_string.capacity());
/// ```
#[stable(feature = "osstring_simple_functions", since = "1.9.0")]
#[inline]
pub fn with_capacity(capacity: usize) -> OsString {
OsString { inner: Buf::with_capacity(capacity) }
}
@ -207,6 +212,7 @@ impl OsString {
/// assert_eq!(&os_string, "");
/// ```
#[stable(feature = "osstring_simple_functions", since = "1.9.0")]
#[inline]
pub fn clear(&mut self) {
self.inner.clear()
}
@ -224,6 +230,7 @@ impl OsString {
/// assert!(os_string.capacity() >= 10);
/// ```
#[stable(feature = "osstring_simple_functions", since = "1.9.0")]
#[inline]
pub fn capacity(&self) -> usize {
self.inner.capacity()
}
@ -243,6 +250,7 @@ impl OsString {
/// assert!(s.capacity() >= 10);
/// ```
#[stable(feature = "osstring_simple_functions", since = "1.9.0")]
#[inline]
pub fn reserve(&mut self, additional: usize) {
self.inner.reserve(additional)
}
@ -265,6 +273,7 @@ impl OsString {
/// assert!(s.capacity() >= 10);
/// ```
#[stable(feature = "osstring_simple_functions", since = "1.9.0")]
#[inline]
pub fn reserve_exact(&mut self, additional: usize) {
self.inner.reserve_exact(additional)
}
@ -285,6 +294,7 @@ impl OsString {
/// assert_eq!(3, s.capacity());
/// ```
#[stable(feature = "osstring_shrink_to_fit", since = "1.19.0")]
#[inline]
pub fn shrink_to_fit(&mut self) {
self.inner.shrink_to_fit()
}
@ -342,6 +352,7 @@ impl From<String> for OsString {
/// Converts a [`String`] into a [`OsString`].
///
/// The conversion copies the data, and includes an allocation on the heap.
#[inline]
fn from(s: String) -> OsString {
OsString { inner: Buf::from_string(s) }
}
@ -408,6 +419,7 @@ impl fmt::Debug for OsString {
#[stable(feature = "rust1", since = "1.0.0")]
impl PartialEq for OsString {
#[inline]
fn eq(&self, other: &OsString) -> bool {
&**self == &**other
}
@ -415,6 +427,7 @@ impl PartialEq for OsString {
#[stable(feature = "rust1", since = "1.0.0")]
impl PartialEq<str> for OsString {
#[inline]
fn eq(&self, other: &str) -> bool {
&**self == other
}
@ -422,6 +435,7 @@ impl PartialEq<str> for OsString {
#[stable(feature = "rust1", since = "1.0.0")]
impl PartialEq<OsString> for str {
#[inline]
fn eq(&self, other: &OsString) -> bool {
&**other == self
}
@ -429,6 +443,7 @@ impl PartialEq<OsString> for str {
#[stable(feature = "os_str_str_ref_eq", since = "1.29.0")]
impl PartialEq<&str> for OsString {
#[inline]
fn eq(&self, other: &&str) -> bool {
**self == **other
}
@ -436,6 +451,7 @@ impl PartialEq<&str> for OsString {
#[stable(feature = "os_str_str_ref_eq", since = "1.29.0")]
impl<'a> PartialEq<OsString> for &'a str {
#[inline]
fn eq(&self, other: &OsString) -> bool {
**other == **self
}
@ -539,6 +555,7 @@ impl OsStr {
/// assert_eq!(os_str.to_str(), Some("foo"));
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
pub fn to_str(&self) -> Option<&str> {
self.inner.to_str()
}
@ -589,6 +606,7 @@ impl OsStr {
/// }
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
pub fn to_string_lossy(&self) -> Cow<'_, str> {
self.inner.to_string_lossy()
}
@ -605,6 +623,7 @@ impl OsStr {
/// assert_eq!(os_string, OsString::from("foo"));
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
pub fn to_os_string(&self) -> OsString {
OsString { inner: self.inner.to_owned() }
}
@ -655,6 +674,7 @@ impl OsStr {
/// ```
#[doc(alias = "length")]
#[stable(feature = "osstring_simple_functions", since = "1.9.0")]
#[inline]
pub fn len(&self) -> usize {
self.inner.inner.len()
}
@ -696,6 +716,7 @@ impl OsStr {
/// assert_eq!("grÜße, jÜrgen ❤", s);
/// ```
#[unstable(feature = "osstring_ascii", issue = "70516")]
#[inline]
pub fn make_ascii_lowercase(&mut self) {
self.inner.make_ascii_lowercase()
}
@ -721,6 +742,7 @@ impl OsStr {
/// assert_eq!("GRüßE, JüRGEN ❤", s);
/// ```
#[unstable(feature = "osstring_ascii", issue = "70516")]
#[inline]
pub fn make_ascii_uppercase(&mut self) {
self.inner.make_ascii_uppercase()
}
@ -784,6 +806,7 @@ impl OsStr {
/// assert!(!non_ascii.is_ascii());
/// ```
#[unstable(feature = "osstring_ascii", issue = "70516")]
#[inline]
pub fn is_ascii(&self) -> bool {
self.inner.is_ascii()
}
@ -811,6 +834,7 @@ impl OsStr {
#[stable(feature = "box_from_os_str", since = "1.17.0")]
impl From<&OsStr> for Box<OsStr> {
#[inline]
fn from(s: &OsStr) -> Box<OsStr> {
let rw = Box::into_raw(s.inner.into_box()) as *mut OsStr;
unsafe { Box::from_raw(rw) }
@ -832,6 +856,7 @@ impl From<Cow<'_, OsStr>> for Box<OsStr> {
impl From<Box<OsStr>> for OsString {
/// Converts a [`Box`]`<`[`OsStr`]`>` into a `OsString` without copying or
/// allocating.
#[inline]
fn from(boxed: Box<OsStr>) -> OsString {
boxed.into_os_string()
}
@ -840,6 +865,7 @@ impl From<Box<OsStr>> for OsString {
#[stable(feature = "box_from_os_string", since = "1.20.0")]
impl From<OsString> for Box<OsStr> {
/// Converts a [`OsString`] into a [`Box`]`<OsStr>` without copying or allocating.
#[inline]
fn from(s: OsString) -> Box<OsStr> {
s.into_boxed_os_str()
}
@ -925,6 +951,7 @@ impl<'a> From<Cow<'a, OsStr>> for OsString {
#[stable(feature = "box_default_extra", since = "1.17.0")]
impl Default for Box<OsStr> {
#[inline]
fn default() -> Box<OsStr> {
let rw = Box::into_raw(Slice::empty_box()) as *mut OsStr;
unsafe { Box::from_raw(rw) }
@ -1075,6 +1102,7 @@ impl OsStr {
#[stable(feature = "rust1", since = "1.0.0")]
impl Borrow<OsStr> for OsString {
#[inline]
fn borrow(&self) -> &OsStr {
&self[..]
}
@ -1083,9 +1111,11 @@ impl Borrow<OsStr> for OsString {
#[stable(feature = "rust1", since = "1.0.0")]
impl ToOwned for OsStr {
type Owned = OsString;
#[inline]
fn to_owned(&self) -> OsString {
self.to_os_string()
}
#[inline]
fn clone_into(&self, target: &mut OsString) {
self.inner.clone_into(&mut target.inner)
}
@ -1093,6 +1123,7 @@ impl ToOwned for OsStr {
#[stable(feature = "rust1", since = "1.0.0")]
impl AsRef<OsStr> for OsStr {
#[inline]
fn as_ref(&self) -> &OsStr {
self
}
@ -1123,12 +1154,14 @@ impl AsRef<OsStr> for String {
}
impl FromInner<Buf> for OsString {
#[inline]
fn from_inner(buf: Buf) -> OsString {
OsString { inner: buf }
}
}
impl IntoInner<Buf> for OsString {
#[inline]
fn into_inner(self) -> Buf {
self.inner
}
@ -1145,6 +1178,7 @@ impl AsInner<Slice> for OsStr {
impl FromStr for OsString {
type Err = core::convert::Infallible;
#[inline]
fn from_str(s: &str) -> Result<Self, Self::Err> {
Ok(OsString::from(s))
}

View File

@ -401,12 +401,14 @@ impl<'a> PrefixComponent<'a> {
/// See [`Prefix`]'s documentation for more information on the different
/// kinds of prefixes.
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
pub fn kind(&self) -> Prefix<'a> {
self.parsed
}
/// Returns the raw [`OsStr`] slice for this prefix.
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
pub fn as_os_str(&self) -> &'a OsStr {
self.raw
}
@ -414,6 +416,7 @@ impl<'a> PrefixComponent<'a> {
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a> cmp::PartialEq for PrefixComponent<'a> {
#[inline]
fn eq(&self, other: &PrefixComponent<'a>) -> bool {
cmp::PartialEq::eq(&self.parsed, &other.parsed)
}
@ -421,6 +424,7 @@ impl<'a> cmp::PartialEq for PrefixComponent<'a> {
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a> cmp::PartialOrd for PrefixComponent<'a> {
#[inline]
fn partial_cmp(&self, other: &PrefixComponent<'a>) -> Option<cmp::Ordering> {
cmp::PartialOrd::partial_cmp(&self.parsed, &other.parsed)
}
@ -428,6 +432,7 @@ impl<'a> cmp::PartialOrd for PrefixComponent<'a> {
#[stable(feature = "rust1", since = "1.0.0")]
impl cmp::Ord for PrefixComponent<'_> {
#[inline]
fn cmp(&self, other: &Self) -> cmp::Ordering {
cmp::Ord::cmp(&self.parsed, &other.parsed)
}
@ -522,6 +527,7 @@ impl<'a> Component<'a> {
#[stable(feature = "rust1", since = "1.0.0")]
impl AsRef<OsStr> for Component<'_> {
#[inline]
fn as_ref(&self) -> &OsStr {
self.as_os_str()
}
@ -529,6 +535,7 @@ impl AsRef<OsStr> for Component<'_> {
#[stable(feature = "path_component_asref", since = "1.25.0")]
impl AsRef<Path> for Component<'_> {
#[inline]
fn as_ref(&self) -> &Path {
self.as_os_str().as_ref()
}
@ -750,6 +757,7 @@ impl<'a> Components<'a> {
#[stable(feature = "rust1", since = "1.0.0")]
impl AsRef<Path> for Components<'_> {
#[inline]
fn as_ref(&self) -> &Path {
self.as_path()
}
@ -757,6 +765,7 @@ impl AsRef<Path> for Components<'_> {
#[stable(feature = "rust1", since = "1.0.0")]
impl AsRef<OsStr> for Components<'_> {
#[inline]
fn as_ref(&self) -> &OsStr {
self.as_path().as_os_str()
}
@ -792,6 +801,7 @@ impl<'a> Iter<'a> {
/// assert_eq!(Path::new("foo/bar.txt"), iter.as_path());
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
pub fn as_path(&self) -> &'a Path {
self.inner.as_path()
}
@ -799,6 +809,7 @@ impl<'a> Iter<'a> {
#[stable(feature = "rust1", since = "1.0.0")]
impl AsRef<Path> for Iter<'_> {
#[inline]
fn as_ref(&self) -> &Path {
self.as_path()
}
@ -806,6 +817,7 @@ impl AsRef<Path> for Iter<'_> {
#[stable(feature = "rust1", since = "1.0.0")]
impl AsRef<OsStr> for Iter<'_> {
#[inline]
fn as_ref(&self) -> &OsStr {
self.as_path().as_os_str()
}
@ -815,6 +827,7 @@ impl AsRef<OsStr> for Iter<'_> {
impl<'a> Iterator for Iter<'a> {
type Item = &'a OsStr;
#[inline]
fn next(&mut self) -> Option<&'a OsStr> {
self.inner.next().map(Component::as_os_str)
}
@ -822,6 +835,7 @@ impl<'a> Iterator for Iter<'a> {
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a> DoubleEndedIterator for Iter<'a> {
#[inline]
fn next_back(&mut self) -> Option<&'a OsStr> {
self.inner.next_back().map(Component::as_os_str)
}
@ -935,6 +949,7 @@ impl FusedIterator for Components<'_> {}
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a> cmp::PartialEq for Components<'a> {
#[inline]
fn eq(&self, other: &Components<'a>) -> bool {
Iterator::eq(self.clone(), other.clone())
}
@ -945,6 +960,7 @@ impl cmp::Eq for Components<'_> {}
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a> cmp::PartialOrd for Components<'a> {
#[inline]
fn partial_cmp(&self, other: &Components<'a>) -> Option<cmp::Ordering> {
Iterator::partial_cmp(self.clone(), other.clone())
}
@ -952,6 +968,7 @@ impl<'a> cmp::PartialOrd for Components<'a> {
#[stable(feature = "rust1", since = "1.0.0")]
impl cmp::Ord for Components<'_> {
#[inline]
fn cmp(&self, other: &Self) -> cmp::Ordering {
Iterator::cmp(self.clone(), other.clone())
}
@ -985,6 +1002,7 @@ pub struct Ancestors<'a> {
impl<'a> Iterator for Ancestors<'a> {
type Item = &'a Path;
#[inline]
fn next(&mut self) -> Option<Self::Item> {
let next = self.next;
self.next = next.and_then(Path::parent);
@ -1060,6 +1078,7 @@ pub struct PathBuf {
}
impl PathBuf {
#[inline]
fn as_mut_vec(&mut self) -> &mut Vec<u8> {
unsafe { &mut *(self as *mut PathBuf as *mut Vec<u8>) }
}
@ -1074,6 +1093,7 @@ impl PathBuf {
/// let path = PathBuf::new();
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
pub fn new() -> PathBuf {
PathBuf { inner: OsString::new() }
}
@ -1097,6 +1117,7 @@ impl PathBuf {
///
/// [`with_capacity`]: OsString::with_capacity
#[stable(feature = "path_buf_capacity", since = "1.44.0")]
#[inline]
pub fn with_capacity(capacity: usize) -> PathBuf {
PathBuf { inner: OsString::with_capacity(capacity) }
}
@ -1112,6 +1133,7 @@ impl PathBuf {
/// assert_eq!(Path::new("/test"), p.as_path());
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
pub fn as_path(&self) -> &Path {
self
}
@ -1315,12 +1337,14 @@ impl PathBuf {
/// let os_str = p.into_os_string();
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
pub fn into_os_string(self) -> OsString {
self.inner
}
/// Converts this `PathBuf` into a [boxed](Box) [`Path`].
#[stable(feature = "into_boxed_path", since = "1.20.0")]
#[inline]
pub fn into_boxed_path(self) -> Box<Path> {
let rw = Box::into_raw(self.inner.into_boxed_os_str()) as *mut Path;
unsafe { Box::from_raw(rw) }
@ -1330,6 +1354,7 @@ impl PathBuf {
///
/// [`capacity`]: OsString::capacity
#[stable(feature = "path_buf_capacity", since = "1.44.0")]
#[inline]
pub fn capacity(&self) -> usize {
self.inner.capacity()
}
@ -1338,6 +1363,7 @@ impl PathBuf {
///
/// [`clear`]: OsString::clear
#[stable(feature = "path_buf_capacity", since = "1.44.0")]
#[inline]
pub fn clear(&mut self) {
self.inner.clear()
}
@ -1346,6 +1372,7 @@ impl PathBuf {
///
/// [`reserve`]: OsString::reserve
#[stable(feature = "path_buf_capacity", since = "1.44.0")]
#[inline]
pub fn reserve(&mut self, additional: usize) {
self.inner.reserve(additional)
}
@ -1354,6 +1381,7 @@ impl PathBuf {
///
/// [`reserve_exact`]: OsString::reserve_exact
#[stable(feature = "path_buf_capacity", since = "1.44.0")]
#[inline]
pub fn reserve_exact(&mut self, additional: usize) {
self.inner.reserve_exact(additional)
}
@ -1362,6 +1390,7 @@ impl PathBuf {
///
/// [`shrink_to_fit`]: OsString::shrink_to_fit
#[stable(feature = "path_buf_capacity", since = "1.44.0")]
#[inline]
pub fn shrink_to_fit(&mut self) {
self.inner.shrink_to_fit()
}
@ -1370,6 +1399,7 @@ impl PathBuf {
///
/// [`shrink_to`]: OsString::shrink_to
#[unstable(feature = "shrink_to", issue = "56431")]
#[inline]
pub fn shrink_to(&mut self, min_capacity: usize) {
self.inner.shrink_to(min_capacity)
}
@ -1400,6 +1430,7 @@ impl From<Box<Path>> for PathBuf {
/// Converts a `Box<Path>` into a `PathBuf`
///
/// This conversion does not allocate or copy memory.
#[inline]
fn from(boxed: Box<Path>) -> PathBuf {
boxed.into_path_buf()
}
@ -1411,6 +1442,7 @@ impl From<PathBuf> for Box<Path> {
///
/// This conversion currently should not allocate memory,
/// but this behavior is not guaranteed on all platforms or in all future versions.
#[inline]
fn from(p: PathBuf) -> Box<Path> {
p.into_boxed_path()
}
@ -1426,6 +1458,7 @@ impl Clone for Box<Path> {
#[stable(feature = "rust1", since = "1.0.0")]
impl<T: ?Sized + AsRef<OsStr>> From<&T> for PathBuf {
#[inline]
fn from(s: &T) -> PathBuf {
PathBuf::from(s.as_ref().to_os_string())
}
@ -1447,6 +1480,7 @@ impl From<PathBuf> for OsString {
/// Converts a `PathBuf` into a `OsString`
///
/// This conversion does not allocate or copy memory.
#[inline]
fn from(path_buf: PathBuf) -> OsString {
path_buf.inner
}
@ -1457,6 +1491,7 @@ impl From<String> for PathBuf {
/// Converts a `String` into a `PathBuf`
///
/// This conversion does not allocate or copy memory.
#[inline]
fn from(s: String) -> PathBuf {
PathBuf::from(OsString::from(s))
}
@ -1466,6 +1501,7 @@ impl From<String> for PathBuf {
impl FromStr for PathBuf {
type Err = core::convert::Infallible;
#[inline]
fn from_str(s: &str) -> Result<Self, Self::Err> {
Ok(PathBuf::from(s))
}
@ -1510,6 +1546,7 @@ impl ops::Deref for PathBuf {
#[stable(feature = "rust1", since = "1.0.0")]
impl Borrow<Path> for PathBuf {
#[inline]
fn borrow(&self) -> &Path {
self.deref()
}
@ -1517,6 +1554,7 @@ impl Borrow<Path> for PathBuf {
#[stable(feature = "default_for_pathbuf", since = "1.17.0")]
impl Default for PathBuf {
#[inline]
fn default() -> Self {
PathBuf::new()
}
@ -1597,9 +1635,11 @@ impl From<&Path> for Rc<Path> {
#[stable(feature = "rust1", since = "1.0.0")]
impl ToOwned for Path {
type Owned = PathBuf;
#[inline]
fn to_owned(&self) -> PathBuf {
self.to_path_buf()
}
#[inline]
fn clone_into(&self, target: &mut PathBuf) {
self.inner.clone_into(&mut target.inner);
}
@ -1607,6 +1647,7 @@ impl ToOwned for Path {
#[stable(feature = "rust1", since = "1.0.0")]
impl cmp::PartialEq for PathBuf {
#[inline]
fn eq(&self, other: &PathBuf) -> bool {
self.components() == other.components()
}
@ -1624,6 +1665,7 @@ impl cmp::Eq for PathBuf {}
#[stable(feature = "rust1", since = "1.0.0")]
impl cmp::PartialOrd for PathBuf {
#[inline]
fn partial_cmp(&self, other: &PathBuf) -> Option<cmp::Ordering> {
self.components().partial_cmp(other.components())
}
@ -1631,6 +1673,7 @@ impl cmp::PartialOrd for PathBuf {
#[stable(feature = "rust1", since = "1.0.0")]
impl cmp::Ord for PathBuf {
#[inline]
fn cmp(&self, other: &PathBuf) -> cmp::Ordering {
self.components().cmp(other.components())
}
@ -1638,6 +1681,7 @@ impl cmp::Ord for PathBuf {
#[stable(feature = "rust1", since = "1.0.0")]
impl AsRef<OsStr> for PathBuf {
#[inline]
fn as_ref(&self) -> &OsStr {
&self.inner[..]
}
@ -1745,6 +1789,7 @@ impl Path {
/// assert_eq!(os_str, std::ffi::OsStr::new("foo.txt"));
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
pub fn as_os_str(&self) -> &OsStr {
&self.inner
}
@ -1766,6 +1811,7 @@ impl Path {
/// assert_eq!(path.to_str(), Some("foo.txt"));
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
pub fn to_str(&self) -> Option<&str> {
self.inner.to_str()
}
@ -1791,6 +1837,7 @@ impl Path {
/// Had `path` contained invalid unicode, the `to_string_lossy` call might
/// have returned `"fo<66>.txt"`.
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
pub fn to_string_lossy(&self) -> Cow<'_, str> {
self.inner.to_string_lossy()
}
@ -1854,6 +1901,7 @@ impl Path {
///
/// [`is_absolute`]: Path::is_absolute
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
pub fn is_relative(&self) -> bool {
!self.is_absolute()
}
@ -1879,6 +1927,7 @@ impl Path {
/// assert!(Path::new("/etc/passwd").has_root());
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
pub fn has_root(&self) -> bool {
self.components().has_root()
}
@ -1941,6 +1990,7 @@ impl Path {
///
/// [`parent`]: Path::parent
#[stable(feature = "path_ancestors", since = "1.28.0")]
#[inline]
pub fn ancestors(&self) -> Ancestors<'_> {
Ancestors { next: Some(&self) }
}
@ -2265,6 +2315,7 @@ impl Path {
/// assert_eq!(it.next(), None)
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
pub fn iter(&self) -> Iter<'_> {
Iter { inner: self.components() }
}
@ -2284,6 +2335,7 @@ impl Path {
/// println!("{}", path.display());
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
pub fn display(&self) -> Display<'_> {
Display { path: self }
}
@ -2305,6 +2357,7 @@ impl Path {
/// println!("{:?}", metadata.file_type());
/// ```
#[stable(feature = "path_ext", since = "1.5.0")]
#[inline]
pub fn metadata(&self) -> io::Result<fs::Metadata> {
fs::metadata(self)
}
@ -2323,6 +2376,7 @@ impl Path {
/// println!("{:?}", metadata.file_type());
/// ```
#[stable(feature = "path_ext", since = "1.5.0")]
#[inline]
pub fn symlink_metadata(&self) -> io::Result<fs::Metadata> {
fs::symlink_metadata(self)
}
@ -2341,6 +2395,7 @@ impl Path {
/// assert_eq!(path.canonicalize().unwrap(), PathBuf::from("/foo/test/bar.rs"));
/// ```
#[stable(feature = "path_ext", since = "1.5.0")]
#[inline]
pub fn canonicalize(&self) -> io::Result<PathBuf> {
fs::canonicalize(self)
}
@ -2358,6 +2413,7 @@ impl Path {
/// let path_link = path.read_link().expect("read_link call failed");
/// ```
#[stable(feature = "path_ext", since = "1.5.0")]
#[inline]
pub fn read_link(&self) -> io::Result<PathBuf> {
fs::read_link(self)
}
@ -2382,6 +2438,7 @@ impl Path {
/// }
/// ```
#[stable(feature = "path_ext", since = "1.5.0")]
#[inline]
pub fn read_dir(&self) -> io::Result<fs::ReadDir> {
fs::read_dir(self)
}
@ -2406,6 +2463,7 @@ impl Path {
/// This is a convenience function that coerces errors to false. If you want to
/// check errors, call [`fs::metadata`].
#[stable(feature = "path_ext", since = "1.5.0")]
#[inline]
pub fn exists(&self) -> bool {
fs::metadata(self).is_ok()
}
@ -2480,6 +2538,7 @@ impl Path {
#[stable(feature = "rust1", since = "1.0.0")]
impl AsRef<OsStr> for Path {
#[inline]
fn as_ref(&self) -> &OsStr {
&self.inner
}
@ -2531,6 +2590,7 @@ impl fmt::Display for Display<'_> {
#[stable(feature = "rust1", since = "1.0.0")]
impl cmp::PartialEq for Path {
#[inline]
fn eq(&self, other: &Path) -> bool {
self.components().eq(other.components())
}
@ -2550,6 +2610,7 @@ impl cmp::Eq for Path {}
#[stable(feature = "rust1", since = "1.0.0")]
impl cmp::PartialOrd for Path {
#[inline]
fn partial_cmp(&self, other: &Path) -> Option<cmp::Ordering> {
self.components().partial_cmp(other.components())
}
@ -2557,6 +2618,7 @@ impl cmp::PartialOrd for Path {
#[stable(feature = "rust1", since = "1.0.0")]
impl cmp::Ord for Path {
#[inline]
fn cmp(&self, other: &Path) -> cmp::Ordering {
self.components().cmp(other.components())
}
@ -2564,6 +2626,7 @@ impl cmp::Ord for Path {
#[stable(feature = "rust1", since = "1.0.0")]
impl AsRef<Path> for Path {
#[inline]
fn as_ref(&self) -> &Path {
self
}
@ -2571,6 +2634,7 @@ impl AsRef<Path> for Path {
#[stable(feature = "rust1", since = "1.0.0")]
impl AsRef<Path> for OsStr {
#[inline]
fn as_ref(&self) -> &Path {
Path::new(self)
}
@ -2578,6 +2642,7 @@ impl AsRef<Path> for OsStr {
#[stable(feature = "cow_os_str_as_ref_path", since = "1.8.0")]
impl AsRef<Path> for Cow<'_, OsStr> {
#[inline]
fn as_ref(&self) -> &Path {
Path::new(self)
}
@ -2585,6 +2650,7 @@ impl AsRef<Path> for Cow<'_, OsStr> {
#[stable(feature = "rust1", since = "1.0.0")]
impl AsRef<Path> for OsString {
#[inline]
fn as_ref(&self) -> &Path {
Path::new(self)
}
@ -2600,6 +2666,7 @@ impl AsRef<Path> for str {
#[stable(feature = "rust1", since = "1.0.0")]
impl AsRef<Path> for String {
#[inline]
fn as_ref(&self) -> &Path {
Path::new(self)
}
@ -2617,6 +2684,7 @@ impl AsRef<Path> for PathBuf {
impl<'a> IntoIterator for &'a PathBuf {
type Item = &'a OsStr;
type IntoIter = Iter<'a>;
#[inline]
fn into_iter(self) -> Iter<'a> {
self.iter()
}
@ -2626,6 +2694,7 @@ impl<'a> IntoIterator for &'a PathBuf {
impl<'a> IntoIterator for &'a Path {
type Item = &'a OsStr;
type IntoIter = Iter<'a>;
#[inline]
fn into_iter(self) -> Iter<'a> {
self.iter()
}