Skip to content

Commit 95f3187

Browse files
committed
Seal the internal traits
1 parent d5dc76e commit 95f3187

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
@@ -15,6 +15,7 @@ use crate::dir_entry::{SFN_PADDING, SFN_SIZE};
1515
use crate::error::{Error, IoError};
1616
use crate::file::File;
1717
use crate::fs::{DiskSlice, FileSystem, FsIoAdapter, OemCpConverter, ReadWriteSeek};
18+
use crate::io::private::Sealed;
1819
use crate::io::{self, IoBase, Read, ReadFile, Seek, SeekFrom, Write, WriteFile};
1920
use crate::time::TimeProvider;
2021

@@ -51,6 +52,8 @@ impl<IO: ReadWriteSeek, TP, OCC> Clone for DirRawStream<'_, IO, TP, OCC> {
5152
}
5253
}
5354

55+
impl<IO: ReadWriteSeek, TP, OCC> Sealed for DirRawStream<'_, IO, TP, OCC> {}
56+
5457
impl<IO: ReadWriteSeek, TP, OCC> IoBase for DirRawStream<'_, IO, TP, OCC> {
5558
type Error = Error<IO::Error>;
5659
}

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

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

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

src/fs.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use crate::dir::{Dir, DirRawStream};
1313
use crate::dir_entry::{DirFileEntryData, FileAttributes, SFN_PADDING, SFN_SIZE};
1414
use crate::error::Error;
1515
use crate::file::File;
16+
use crate::io::private::Sealed;
1617
use crate::io::{self, IoBase, Read, ReadFile, ReadLeExt, Seek, SeekFrom, Write, WriteFile, WriteLeExt};
1718
use crate::table::{
1819
alloc_cluster, count_free_clusters, format_fat, read_fat_flags, ClusterIterator, RESERVED_FAT_ENTRIES,
@@ -694,6 +695,8 @@ pub(crate) struct FsIoAdapter<'a, IO: ReadWriteSeek, TP, OCC> {
694695
fs: &'a FileSystem<IO, TP, OCC>,
695696
}
696697

698+
impl<IO: ReadWriteSeek, TP, OCC> Sealed for FsIoAdapter<'_, IO, TP, OCC> {}
699+
697700
impl<IO: ReadWriteSeek, TP, OCC> IoBase for FsIoAdapter<'_, IO, TP, OCC> {
698701
type Error = IO::Error;
699702
}
@@ -798,6 +801,8 @@ impl<B: Clone, S> Clone for DiskSlice<B, S> {
798801
}
799802
}
800803

804+
impl<B, S: IoBase> Sealed for DiskSlice<B, S> {}
805+
801806
impl<B, S: IoBase> IoBase for DiskSlice<B, S> {
802807
type Error = Error<S::Error>;
803808
}

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)