Skip to content

Commit

Permalink
Seal the internal traits
Browse files Browse the repository at this point in the history
  • Loading branch information
alexkazik committed Aug 16, 2024
1 parent a831413 commit cc5ef34
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use crate::dir_entry::{SFN_PADDING, SFN_SIZE};
use crate::error::{Error, IoError};
use crate::file::File;
use crate::fs::{DiskSlice, FileSystem, FsIoAdapter, OemCpConverter, ReadWriteSeek};
use crate::io::private::Sealed;
use crate::io::{self, IoBase, ReadFile, Seek, SeekFrom, WriteFile};
use crate::time::TimeProvider;

Expand Down Expand Up @@ -51,6 +52,8 @@ impl<IO: ReadWriteSeek, TP, OCC> Clone for DirRawStream<'_, IO, TP, OCC> {
}
}

impl<IO: ReadWriteSeek, TP, OCC> Sealed for DirRawStream<'_, IO, TP, OCC> {}

impl<IO: ReadWriteSeek, TP, OCC> IoBase for DirRawStream<'_, IO, TP, OCC> {
type Error = Error<IO::Error>;
}
Expand Down
3 changes: 3 additions & 0 deletions src/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use core::convert::TryFrom;
use crate::dir_entry::DirEntryEditor;
use crate::error::Error;
use crate::fs::{FileSystem, ReadWriteSeek};
use crate::io::private::Sealed;
use crate::io::{IoBase, ReadFile, Seek, SeekFrom, Write, WriteFile};
use crate::time::{Date, DateTime, TimeProvider};

Expand Down Expand Up @@ -250,6 +251,8 @@ impl<IO: ReadWriteSeek, TP, OCC> Clone for File<'_, IO, TP, OCC> {
}
}

impl<IO: ReadWriteSeek, TP, OCC> Sealed for File<'_, IO, TP, OCC> {}

impl<IO: ReadWriteSeek, TP, OCC> IoBase for File<'_, IO, TP, OCC> {
type Error = Error<IO::Error>;
}
Expand Down
5 changes: 5 additions & 0 deletions src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use crate::dir::{Dir, DirRawStream};
use crate::dir_entry::{DirFileEntryData, FileAttributes, SFN_PADDING, SFN_SIZE};
use crate::error::Error;
use crate::file::File;
use crate::io::private::Sealed;
use crate::io::{self, IoBase, Read, ReadFile, ReadLeExt, Seek, SeekFrom, Write, WriteFile, WriteLeExt};
use crate::table::{
alloc_cluster, count_free_clusters, format_fat, read_fat_flags, ClusterIterator, RESERVED_FAT_ENTRIES,
Expand Down Expand Up @@ -694,6 +695,8 @@ pub(crate) struct FsIoAdapter<'a, IO: ReadWriteSeek, TP, OCC> {
fs: &'a FileSystem<IO, TP, OCC>,
}

impl<IO: ReadWriteSeek, TP, OCC> Sealed for FsIoAdapter<'_, IO, TP, OCC> {}

impl<IO: ReadWriteSeek, TP, OCC> IoBase for FsIoAdapter<'_, IO, TP, OCC> {
type Error = IO::Error;
}
Expand Down Expand Up @@ -798,6 +801,8 @@ impl<B: Clone, S> Clone for DiskSlice<B, S> {
}
}

impl<B, S: IoBase> Sealed for DiskSlice<B, S> {}

impl<B, S: IoBase> IoBase for DiskSlice<B, S> {
type Error = Error<S::Error>;
}
Expand Down
12 changes: 10 additions & 2 deletions src/io.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::error::IoError;
use crate::io::private::Sealed;

/// Provides IO error as an associated type.
///
Expand All @@ -9,6 +10,10 @@ pub trait IoBase {
type Error: IoError;
}

pub(crate) mod private {
pub trait Sealed {}
}

/// The `Read` trait allows for reading bytes from a source.
///
/// It is based on the `std::io::Read` trait.
Expand All @@ -34,7 +39,7 @@ pub trait Read: IoBase {
/// The `ReadFile` trait allows for reading bytes from a source.
///
/// It is based on the `std::io::Read` trait.
pub trait ReadFile: Read {
pub trait ReadFile: Read + Sealed {
/// Pull some bytes from this source into the specified buffer, returning how many bytes were read.
///
/// This function does not provide any guarantees about whether it blocks waiting for data, but if an object needs
Expand Down Expand Up @@ -131,7 +136,7 @@ pub trait Write: IoBase {
/// The `WriteFile` trait allows for writing bytes into the sink.
///
/// It is based on the `std::io::Write` trait.
pub trait WriteFile: Write {
pub trait WriteFile: Write + Sealed {
/// Write a buffer into this writer, returning how many bytes were written.
///
/// # Errors
Expand Down Expand Up @@ -259,6 +264,9 @@ impl<T> StdIoWrapper<T> {
}
}

#[cfg(feature = "std")]
impl<T> Sealed for StdIoWrapper<T> {}

#[cfg(feature = "std")]
impl<T> IoBase for StdIoWrapper<T> {
type Error = std::io::Error;
Expand Down

0 comments on commit cc5ef34

Please sign in to comment.