Skip to content

Commit 0ec7dbf

Browse files
authored
Merge pull request #480 from wedsonaf/read-write
rust: use `impl` syntactic sugar to simplify read/write.
2 parents 24566f3 + ca31a6c commit 0ec7dbf

File tree

5 files changed

+13
-13
lines changed

5 files changed

+13
-13
lines changed

drivers/char/hw_random/bcm2835_rng_rust.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ impl FileOpener<()> for RngDevice {
3535
impl FileOperations for RngDevice {
3636
kernel::declare_file_operations!(read);
3737

38-
fn read<T: IoBufferWriter>(_: &Self, _: &File, data: &mut T, offset: u64) -> Result<usize> {
38+
fn read(_: &Self, _: &File, data: &mut impl IoBufferWriter, offset: u64) -> Result<usize> {
3939
// Succeed if the caller doesn't provide a buffer or if not at the start.
4040
if data.is_empty() || offset != 0 {
4141
return Ok(0);

rust/kernel/file_operations.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -622,10 +622,10 @@ pub trait FileOperations: Send + Sync + Sized {
622622
/// Reads data from this file to the caller's buffer.
623623
///
624624
/// Corresponds to the `read` and `read_iter` function pointers in `struct file_operations`.
625-
fn read<T: IoBufferWriter>(
625+
fn read(
626626
_this: &<<Self::Wrapper as PointerWrapper>::Borrowed as Deref>::Target,
627627
_file: &File,
628-
_data: &mut T,
628+
_data: &mut impl IoBufferWriter,
629629
_offset: u64,
630630
) -> Result<usize> {
631631
Err(Error::EINVAL)
@@ -634,10 +634,10 @@ pub trait FileOperations: Send + Sync + Sized {
634634
/// Writes data from the caller's buffer to this file.
635635
///
636636
/// Corresponds to the `write` and `write_iter` function pointers in `struct file_operations`.
637-
fn write<T: IoBufferReader>(
637+
fn write(
638638
_this: &<<Self::Wrapper as PointerWrapper>::Borrowed as Deref>::Target,
639639
_file: &File,
640-
_data: &mut T,
640+
_data: &mut impl IoBufferReader,
641641
_offset: u64,
642642
) -> Result<usize> {
643643
Err(Error::EINVAL)

samples/rust/rust_miscdev.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,10 @@ impl FileOperations for Token {
6868

6969
kernel::declare_file_operations!(read, write);
7070

71-
fn read<T: IoBufferWriter>(
71+
fn read(
7272
shared: &Ref<SharedState>,
7373
_: &File,
74-
data: &mut T,
74+
data: &mut impl IoBufferWriter,
7575
offset: u64,
7676
) -> Result<usize> {
7777
// Succeed if the caller doesn't provide a buffer or if not at the start.
@@ -101,10 +101,10 @@ impl FileOperations for Token {
101101
Ok(1)
102102
}
103103

104-
fn write<T: IoBufferReader>(
104+
fn write(
105105
shared: &Ref<SharedState>,
106106
_: &File,
107-
data: &mut T,
107+
data: &mut impl IoBufferReader,
108108
_offset: u64,
109109
) -> Result<usize> {
110110
{

samples/rust/rust_random.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ struct RandomFile;
2121
impl FileOperations for RandomFile {
2222
kernel::declare_file_operations!(read, write, read_iter, write_iter);
2323

24-
fn read<T: IoBufferWriter>(_this: &Self, file: &File, buf: &mut T, _: u64) -> Result<usize> {
24+
fn read(_this: &Self, file: &File, buf: &mut impl IoBufferWriter, _: u64) -> Result<usize> {
2525
let total_len = buf.len();
2626
let mut chunkbuf = [0; 256];
2727

@@ -39,7 +39,7 @@ impl FileOperations for RandomFile {
3939
Ok(total_len)
4040
}
4141

42-
fn write<T: IoBufferReader>(_this: &Self, _file: &File, buf: &mut T, _: u64) -> Result<usize> {
42+
fn write(_this: &Self, _file: &File, buf: &mut impl IoBufferReader, _: u64) -> Result<usize> {
4343
let total_len = buf.len();
4444
let mut chunkbuf = [0; 256];
4545
while !buf.is_empty() {

samples/rust/rust_semaphore.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ impl FileOpener<Ref<Semaphore>> for FileState {
7777
impl FileOperations for FileState {
7878
declare_file_operations!(read, write, ioctl);
7979

80-
fn read<T: IoBufferWriter>(this: &Self, _: &File, data: &mut T, offset: u64) -> Result<usize> {
80+
fn read(this: &Self, _: &File, data: &mut impl IoBufferWriter, offset: u64) -> Result<usize> {
8181
if data.is_empty() || offset > 0 {
8282
return Ok(0);
8383
}
@@ -87,7 +87,7 @@ impl FileOperations for FileState {
8787
Ok(1)
8888
}
8989

90-
fn write<T: IoBufferReader>(this: &Self, _: &File, data: &mut T, _offs: u64) -> Result<usize> {
90+
fn write(this: &Self, _: &File, data: &mut impl IoBufferReader, _offs: u64) -> Result<usize> {
9191
{
9292
let mut inner = this.shared.inner.lock();
9393
inner.count = inner.count.saturating_add(data.len());

0 commit comments

Comments
 (0)