Skip to content

Commit

Permalink
Seal all filesystem related extension traits.
Browse files Browse the repository at this point in the history
  • Loading branch information
m-ou-se committed Jan 21, 2021
1 parent 5f22daa commit 229c004
Show file tree
Hide file tree
Showing 19 changed files with 77 additions and 31 deletions.
28 changes: 28 additions & 0 deletions library/std/src/fs.rs
Expand Up @@ -92,6 +92,10 @@ pub struct File {
inner: fs_imp::File,
}

/// Allows extension traits within `std`.
#[unstable(feature = "sealed", issue = "none")]
impl crate::sealed::Sealed for File {}

/// Metadata information about a file.
///
/// This structure is returned from the [`metadata`] or
Expand All @@ -102,6 +106,10 @@ pub struct File {
#[derive(Clone)]
pub struct Metadata(fs_imp::FileAttr);

/// Allows extension traits within `std`.
#[unstable(feature = "sealed", issue = "none")]
impl crate::sealed::Sealed for Metadata {}

/// Iterator over the entries in a directory.
///
/// This iterator is returned from the [`read_dir`] function of this module and
Expand All @@ -128,6 +136,10 @@ pub struct ReadDir(fs_imp::ReadDir);
#[stable(feature = "rust1", since = "1.0.0")]
pub struct DirEntry(fs_imp::DirEntry);

/// Allows extension traits within `std`.
#[unstable(feature = "sealed", issue = "none")]
impl crate::sealed::Sealed for DirEntry {}

/// Options and flags which can be used to configure how a file is opened.
///
/// This builder exposes the ability to configure how a [`File`] is opened and
Expand Down Expand Up @@ -167,6 +179,10 @@ pub struct DirEntry(fs_imp::DirEntry);
#[stable(feature = "rust1", since = "1.0.0")]
pub struct OpenOptions(fs_imp::OpenOptions);

/// Allows extension traits within `std`.
#[unstable(feature = "sealed", issue = "none")]
impl crate::sealed::Sealed for OpenOptions {}

/// Representation of the various permissions on a file.
///
/// This module only currently provides one bit of information,
Expand All @@ -179,12 +195,20 @@ pub struct OpenOptions(fs_imp::OpenOptions);
#[stable(feature = "rust1", since = "1.0.0")]
pub struct Permissions(fs_imp::FilePermissions);

/// Allows extension traits within `std`.
#[unstable(feature = "sealed", issue = "none")]
impl crate::sealed::Sealed for Permissions {}

/// A structure representing a type of file with accessors for each file type.
/// It is returned by [`Metadata::file_type`] method.
#[stable(feature = "file_type", since = "1.1.0")]
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
pub struct FileType(fs_imp::FileType);

/// Allows extension traits within `std`.
#[unstable(feature = "sealed", issue = "none")]
impl crate::sealed::Sealed for FileType {}

/// A builder used to create directories in various manners.
///
/// This builder also supports platform-specific options.
Expand All @@ -195,6 +219,10 @@ pub struct DirBuilder {
recursive: bool,
}

/// Allows extension traits within `std`.
#[unstable(feature = "sealed", issue = "none")]
impl crate::sealed::Sealed for DirBuilder {}

/// Indicates how large a buffer to pre-allocate before reading the entire file.
fn initial_buffer_size(file: &File) -> usize {
// Allocate one extra byte so the buffer doesn't need to grow before the
Expand Down
3 changes: 2 additions & 1 deletion library/std/src/os/android/fs.rs
@@ -1,6 +1,7 @@
#![stable(feature = "metadata_ext", since = "1.1.0")]

use crate::fs::Metadata;
use crate::sealed::Sealed;
use crate::sys_common::AsInner;

#[allow(deprecated)]
Expand All @@ -10,7 +11,7 @@ use crate::os::android::raw;
///
/// [`fs::Metadata`]: crate::fs::Metadata
#[stable(feature = "metadata_ext", since = "1.1.0")]
pub trait MetadataExt {
pub trait MetadataExt: Sealed {
/// Gain a reference to the underlying `stat` structure which contains
/// the raw information returned by the OS.
///
Expand Down
3 changes: 2 additions & 1 deletion library/std/src/os/dragonfly/fs.rs
@@ -1,6 +1,7 @@
#![stable(feature = "metadata_ext", since = "1.1.0")]

use crate::fs::Metadata;
use crate::sealed::Sealed;
use crate::sys_common::AsInner;

#[allow(deprecated)]
Expand All @@ -10,7 +11,7 @@ use crate::os::dragonfly::raw;
///
/// [`fs::Metadata`]: crate::fs::Metadata
#[stable(feature = "metadata_ext", since = "1.1.0")]
pub trait MetadataExt {
pub trait MetadataExt: Sealed {
/// Gain a reference to the underlying `stat` structure which contains
/// the raw information returned by the OS.
///
Expand Down
3 changes: 2 additions & 1 deletion library/std/src/os/emscripten/fs.rs
@@ -1,6 +1,7 @@
#![stable(feature = "metadata_ext", since = "1.1.0")]

use crate::fs::Metadata;
use crate::sealed::Sealed;
use crate::sys_common::AsInner;

#[allow(deprecated)]
Expand All @@ -10,7 +11,7 @@ use crate::os::emscripten::raw;
///
/// [`fs::Metadata`]: crate::fs::Metadata
#[stable(feature = "metadata_ext", since = "1.1.0")]
pub trait MetadataExt {
pub trait MetadataExt: Sealed {
/// Gain a reference to the underlying `stat` structure which contains
/// the raw information returned by the OS.
///
Expand Down
3 changes: 2 additions & 1 deletion library/std/src/os/freebsd/fs.rs
@@ -1,6 +1,7 @@
#![stable(feature = "metadata_ext", since = "1.1.0")]

use crate::fs::Metadata;
use crate::sealed::Sealed;
use crate::sys_common::AsInner;

#[allow(deprecated)]
Expand All @@ -10,7 +11,7 @@ use crate::os::freebsd::raw;
///
/// [`fs::Metadata`]: crate::fs::Metadata
#[stable(feature = "metadata_ext", since = "1.1.0")]
pub trait MetadataExt {
pub trait MetadataExt: Sealed {
/// Gain a reference to the underlying `stat` structure which contains
/// the raw information returned by the OS.
///
Expand Down
3 changes: 2 additions & 1 deletion library/std/src/os/fuchsia/fs.rs
@@ -1,13 +1,14 @@
#![stable(feature = "metadata_ext", since = "1.1.0")]

use crate::fs::Metadata;
use crate::sealed::Sealed;
use crate::sys_common::AsInner;

/// OS-specific extensions to [`fs::Metadata`].
///
/// [`fs::Metadata`]: crate::fs::Metadata
#[stable(feature = "metadata_ext", since = "1.1.0")]
pub trait MetadataExt {
pub trait MetadataExt: Sealed {
#[stable(feature = "metadata_ext2", since = "1.8.0")]
fn st_dev(&self) -> u64;
#[stable(feature = "metadata_ext2", since = "1.8.0")]
Expand Down
3 changes: 2 additions & 1 deletion library/std/src/os/haiku/fs.rs
@@ -1,6 +1,7 @@
#![stable(feature = "metadata_ext", since = "1.1.0")]

use crate::fs::Metadata;
use crate::sealed::Sealed;
use crate::sys_common::AsInner;

#[allow(deprecated)]
Expand All @@ -10,7 +11,7 @@ use crate::os::haiku::raw;
///
/// [`fs::Metadata`]: crate::fs::Metadata
#[stable(feature = "metadata_ext", since = "1.1.0")]
pub trait MetadataExt {
pub trait MetadataExt: Sealed {
/// Gain a reference to the underlying `stat` structure which contains
/// the raw information returned by the OS.
///
Expand Down
3 changes: 2 additions & 1 deletion library/std/src/os/illumos/fs.rs
@@ -1,6 +1,7 @@
#![stable(feature = "metadata_ext", since = "1.1.0")]

use crate::fs::Metadata;
use crate::sealed::Sealed;
use crate::sys_common::AsInner;

#[allow(deprecated)]
Expand All @@ -10,7 +11,7 @@ use crate::os::illumos::raw;
///
/// [`fs::Metadata`]: crate::fs::Metadata
#[stable(feature = "metadata_ext", since = "1.1.0")]
pub trait MetadataExt {
pub trait MetadataExt: Sealed {
/// Gain a reference to the underlying `stat` structure which contains
/// the raw information returned by the OS.
///
Expand Down
3 changes: 2 additions & 1 deletion library/std/src/os/ios/fs.rs
@@ -1,6 +1,7 @@
#![stable(feature = "metadata_ext", since = "1.1.0")]

use crate::fs::Metadata;
use crate::sealed::Sealed;
use crate::sys_common::AsInner;

#[allow(deprecated)]
Expand All @@ -10,7 +11,7 @@ use crate::os::ios::raw;
///
/// [`fs::Metadata`]: crate::fs::Metadata
#[stable(feature = "metadata_ext", since = "1.1.0")]
pub trait MetadataExt {
pub trait MetadataExt: Sealed {
/// Gain a reference to the underlying `stat` structure which contains
/// the raw information returned by the OS.
///
Expand Down
3 changes: 2 additions & 1 deletion library/std/src/os/linux/fs.rs
Expand Up @@ -3,6 +3,7 @@
#![stable(feature = "metadata_ext", since = "1.1.0")]

use crate::fs::Metadata;
use crate::sealed::Sealed;
use crate::sys_common::AsInner;

#[allow(deprecated)]
Expand All @@ -12,7 +13,7 @@ use crate::os::linux::raw;
///
/// [`fs::Metadata`]: crate::fs::Metadata
#[stable(feature = "metadata_ext", since = "1.1.0")]
pub trait MetadataExt {
pub trait MetadataExt: Sealed {
/// Gain a reference to the underlying `stat` structure which contains
/// the raw information returned by the OS.
///
Expand Down
3 changes: 2 additions & 1 deletion library/std/src/os/macos/fs.rs
@@ -1,6 +1,7 @@
#![stable(feature = "metadata_ext", since = "1.1.0")]

use crate::fs::Metadata;
use crate::sealed::Sealed;
use crate::sys_common::AsInner;

#[allow(deprecated)]
Expand All @@ -10,7 +11,7 @@ use crate::os::macos::raw;
///
/// [`fs::Metadata`]: crate::fs::Metadata
#[stable(feature = "metadata_ext", since = "1.1.0")]
pub trait MetadataExt {
pub trait MetadataExt: Sealed {
/// Gain a reference to the underlying `stat` structure which contains
/// the raw information returned by the OS.
///
Expand Down
3 changes: 2 additions & 1 deletion library/std/src/os/netbsd/fs.rs
@@ -1,6 +1,7 @@
#![stable(feature = "metadata_ext", since = "1.1.0")]

use crate::fs::Metadata;
use crate::sealed::Sealed;
use crate::sys_common::AsInner;

#[allow(deprecated)]
Expand All @@ -10,7 +11,7 @@ use crate::os::netbsd::raw;
///
/// [`fs::Metadata`]: crate::fs::Metadata
#[stable(feature = "metadata_ext", since = "1.1.0")]
pub trait MetadataExt {
pub trait MetadataExt: Sealed {
/// Gain a reference to the underlying `stat` structure which contains
/// the raw information returned by the OS.
///
Expand Down
3 changes: 2 additions & 1 deletion library/std/src/os/openbsd/fs.rs
@@ -1,6 +1,7 @@
#![stable(feature = "metadata_ext", since = "1.1.0")]

use crate::fs::Metadata;
use crate::sealed::Sealed;
use crate::sys_common::AsInner;

#[allow(deprecated)]
Expand All @@ -10,7 +11,7 @@ use crate::os::openbsd::raw;
///
/// [`fs::Metadata`]: crate::fs::Metadata
#[stable(feature = "metadata_ext", since = "1.1.0")]
pub trait MetadataExt {
pub trait MetadataExt: Sealed {
/// Gain a reference to the underlying `stat` structure which contains
/// the raw information returned by the OS.
///
Expand Down
3 changes: 2 additions & 1 deletion library/std/src/os/redox/fs.rs
@@ -1,6 +1,7 @@
#![stable(feature = "metadata_ext", since = "1.1.0")]

use crate::fs::Metadata;
use crate::sealed::Sealed;
use crate::sys_common::AsInner;

#[allow(deprecated)]
Expand All @@ -10,7 +11,7 @@ use crate::os::redox::raw;
///
/// [`fs::Metadata`]: crate::fs::Metadata
#[stable(feature = "metadata_ext", since = "1.1.0")]
pub trait MetadataExt {
pub trait MetadataExt: Sealed {
/// Gain a reference to the underlying `stat` structure which contains
/// the raw information returned by the OS.
///
Expand Down
3 changes: 2 additions & 1 deletion library/std/src/os/solaris/fs.rs
@@ -1,6 +1,7 @@
#![stable(feature = "metadata_ext", since = "1.1.0")]

use crate::fs::Metadata;
use crate::sealed::Sealed;
use crate::sys_common::AsInner;

#[allow(deprecated)]
Expand All @@ -10,7 +11,7 @@ use crate::os::solaris::raw;
///
/// [`fs::Metadata`]: crate::fs::Metadata
#[stable(feature = "metadata_ext", since = "1.1.0")]
pub trait MetadataExt {
pub trait MetadataExt: Sealed {
/// Gain a reference to the underlying `stat` structure which contains
/// the raw information returned by the OS.
///
Expand Down
3 changes: 2 additions & 1 deletion library/std/src/os/vxworks/fs.rs
@@ -1,12 +1,13 @@
#![stable(feature = "metadata_ext", since = "1.1.0")]

use crate::fs::Metadata;
use crate::sealed::Sealed;
use crate::sys_common::AsInner;

///
/// [`fs::Metadata`]: crate::fs::Metadata
#[stable(feature = "metadata_ext", since = "1.1.0")]
pub trait MetadataExt {
pub trait MetadataExt: Sealed {
#[stable(feature = "metadata_ext2", since = "1.8.0")]
fn st_dev(&self) -> u64;
#[stable(feature = "metadata_ext2", since = "1.8.0")]
Expand Down
15 changes: 8 additions & 7 deletions library/std/src/sys/unix/ext/fs.rs
Expand Up @@ -5,6 +5,7 @@
use crate::fs::{self, OpenOptions, Permissions};
use crate::io;
use crate::path::Path;
use crate::sealed::Sealed;
use crate::sys;
use crate::sys::platform::fs::MetadataExt as UnixMetadataExt;
use crate::sys_common::{AsInner, AsInnerMut, FromInner};
Expand All @@ -14,7 +15,7 @@ use io::{Read, Write};

/// Unix-specific extensions to [`fs::File`].
#[stable(feature = "file_offset", since = "1.15.0")]
pub trait FileExt {
pub trait FileExt: Sealed {
/// Reads a number of bytes starting from a given offset.
///
/// Returns the number of bytes read.
Expand Down Expand Up @@ -220,7 +221,7 @@ impl FileExt for fs::File {

/// Unix-specific extensions to [`fs::Permissions`].
#[stable(feature = "fs_ext", since = "1.1.0")]
pub trait PermissionsExt {
pub trait PermissionsExt: Sealed {
/// Returns the underlying raw `st_mode` bits that contain the standard
/// Unix permissions for this file.
///
Expand Down Expand Up @@ -297,7 +298,7 @@ impl PermissionsExt for Permissions {

/// Unix-specific extensions to [`fs::OpenOptions`].
#[stable(feature = "fs_ext", since = "1.1.0")]
pub trait OpenOptionsExt {
pub trait OpenOptionsExt: Sealed {
/// Sets the mode bits that a new file will be created with.
///
/// If a new file is created as part of an `OpenOptions::open` call then this
Expand Down Expand Up @@ -365,7 +366,7 @@ impl OpenOptionsExt for OpenOptions {

/// Unix-specific extensions to [`fs::Metadata`].
#[stable(feature = "metadata_ext", since = "1.1.0")]
pub trait MetadataExt {
pub trait MetadataExt: Sealed {
/// Returns the ID of the device containing the file.
///
/// # Examples
Expand Down Expand Up @@ -716,7 +717,7 @@ impl MetadataExt for fs::Metadata {
/// Adds support for special Unix file types such as block/character devices,
/// pipes, and sockets.
#[stable(feature = "file_type_ext", since = "1.5.0")]
pub trait FileTypeExt {
pub trait FileTypeExt: Sealed {
/// Returns `true` if this file type is a block device.
///
/// # Examples
Expand Down Expand Up @@ -809,7 +810,7 @@ impl FileTypeExt for fs::FileType {

/// Unix-specific extension methods for [`fs::DirEntry`].
#[stable(feature = "dir_entry_ext", since = "1.1.0")]
pub trait DirEntryExt {
pub trait DirEntryExt: Sealed {
/// Returns the underlying `d_ino` field in the contained `dirent`
/// structure.
///
Expand Down Expand Up @@ -860,7 +861,7 @@ pub fn symlink<P: AsRef<Path>, Q: AsRef<Path>>(original: P, link: Q) -> io::Resu

/// Unix-specific extensions to [`fs::DirBuilder`].
#[stable(feature = "dir_builder", since = "1.6.0")]
pub trait DirBuilderExt {
pub trait DirBuilderExt: Sealed {
/// Sets the mode to create new directories with. This option defaults to
/// 0o777.
///
Expand Down

0 comments on commit 229c004

Please sign in to comment.