Skip to content

Commit 571a7aa

Browse files
committed
Seal the internal traits
1 parent 3418122 commit 571a7aa

File tree

4 files changed

+21
-2
lines changed

4 files changed

+21
-2
lines changed

src/dir.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use crate::dir_entry::{SFN_PADDING, SFN_SIZE};
1414
use crate::error::{Error, IoError};
1515
use crate::file::File;
1616
use crate::fs::{DiskSlice, FileSystem, FsIoAdapter, OemCpConverter, ReadWriteSeek};
17+
use crate::io::private::Sealed;
1718
use crate::io::{self, IoBase, Read, ReadFile, Seek, SeekFrom, Write, WriteFile};
1819
use crate::time::TimeProvider;
1920

@@ -57,6 +58,8 @@ impl<IO: ReadWriteSeek, TP, OCC> Clone for DirRawStream<'_, IO, TP, OCC> {
5758
}
5859
}
5960

61+
impl<IO: ReadWriteSeek, TP, OCC> Sealed for DirRawStream<'_, IO, TP, OCC> {}
62+
6063
impl<IO: ReadWriteSeek, TP, OCC> IoBase for DirRawStream<'_, IO, TP, OCC> {
6164
type Error = Error<IO::Error>;
6265
}

src/file.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use core::convert::TryFrom;
33
use crate::dir_entry::DirEntryEditor;
44
use crate::error::Error;
55
use crate::fs::{FileSystem, ReadWriteSeek};
6+
use crate::io::private::Sealed;
67
use crate::io::{IoBase, Read, ReadFile, Seek, SeekFrom, Write, WriteFile};
78
use crate::time::{Date, DateTime, TimeProvider};
89

@@ -251,6 +252,8 @@ impl<IO: ReadWriteSeek, TP, OCC> Clone for File<'_, IO, TP, OCC> {
251252
}
252253
}
253254

255+
impl<IO: ReadWriteSeek, TP, OCC> Sealed for File<'_, IO, TP, OCC> {}
256+
254257
impl<IO: ReadWriteSeek, TP, OCC> IoBase for File<'_, IO, TP, OCC> {
255258
type Error = Error<IO::Error>;
256259
}

src/fs.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use crate::dir::{Dir, DirRawStream};
1111
use crate::dir_entry::{DirFileEntryData, FileAttributes, SFN_PADDING, SFN_SIZE};
1212
use crate::error::Error;
1313
use crate::file::File;
14+
use crate::io::private::Sealed;
1415
use crate::io::{self, IoBase, Read, ReadFile, ReadLeExt, Seek, SeekFrom, Write, WriteFile, WriteLeExt};
1516
use crate::table::{
1617
alloc_cluster, count_free_clusters, format_fat, read_fat_flags, ClusterIterator, RESERVED_FAT_ENTRIES,
@@ -706,6 +707,8 @@ pub(crate) struct FsIoAdapter<'a, IO: ReadWriteSeek, TP, OCC> {
706707
fs: &'a FileSystem<IO, TP, OCC>,
707708
}
708709

710+
impl<IO: ReadWriteSeek, TP, OCC> Sealed for FsIoAdapter<'_, IO, TP, OCC> {}
711+
709712
impl<IO: ReadWriteSeek, TP, OCC> IoBase for FsIoAdapter<'_, IO, TP, OCC> {
710713
type Error = IO::Error;
711714
}
@@ -810,6 +813,8 @@ impl<B: Clone, S> Clone for DiskSlice<B, S> {
810813
}
811814
}
812815

816+
impl<B, S: IoBase> Sealed for DiskSlice<B, S> {}
817+
813818
impl<B, S: IoBase> IoBase for DiskSlice<B, S> {
814819
type Error = Error<S::Error>;
815820
}

src/io.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::error::IoError;
2+
use crate::io::private::Sealed;
23

34
/// Provides IO error as an associated type.
45
///
@@ -9,6 +10,10 @@ pub trait IoBase {
910
type Error: IoError;
1011
}
1112

13+
pub(crate) mod private {
14+
pub trait Sealed {}
15+
}
16+
1217
/// The `Read` trait allows for reading bytes from a source.
1318
///
1419
/// It is based on the `std::io::Read` trait.
@@ -34,7 +39,7 @@ pub trait Read: IoBase {
3439
/// The `ReadFile` trait allows for reading bytes from a source.
3540
///
3641
/// It is based on the `std::io::Read` trait.
37-
pub trait ReadFile: Read {
42+
pub trait ReadFile: Read + Sealed {
3843
/// Pull some bytes from this source into the specified buffer, returning how many bytes were read.
3944
///
4045
/// This function does not provide any guarantees about whether it blocks waiting for data, but if an object needs
@@ -125,7 +130,7 @@ pub trait Write: IoBase {
125130
/// The `WriteFile` trait allows for writing bytes into the sink.
126131
///
127132
/// It is based on the `std::io::Write` trait.
128-
pub trait WriteFile: Write {
133+
pub trait WriteFile: Write + Sealed {
129134
/// Write a buffer into this writer, returning how many bytes were written.
130135
///
131136
/// # Errors
@@ -243,6 +248,9 @@ impl<T> StdIoWrapper<T> {
243248
}
244249
}
245250

251+
#[cfg(feature = "std")]
252+
impl<T> Sealed for StdIoWrapper<T> {}
253+
246254
#[cfg(feature = "std")]
247255
impl<T> IoBase for StdIoWrapper<T> {
248256
type Error = std::io::Error;

0 commit comments

Comments
 (0)