Skip to content

Commit 582ebad

Browse files
committed
Return initialized buffers from method that read into an uninitialized buffer
1 parent 92aa33b commit 582ebad

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

src/futures/i2c.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,12 @@ pub trait WriteRead<A: AddressMode = SevenBitAddress> {
8282
/// Error type
8383
type Error;
8484
/// The future associated with the `write_read` method.
85-
type WriteReadFuture<'a>: Future<Output = Result<(), Self::Error>> + 'a
85+
type WriteReadFuture<'a>: Future<Output = Result<&'a [u8], Self::Error>> + 'a
8686
where
8787
Self: 'a;
8888

8989
/// Writes bytes to slave with address `address` and then reads enough bytes to fill `read` *in a
90-
/// single transaction*
90+
/// single transaction*. The returned buffer is the initialized `read` buffer.
9191
///
9292
/// # I2C Events (contract)
9393
///

src/futures/rng.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ pub trait Read {
1414
where
1515
Self: 'a;
1616

17-
/// Get a number of bytes from the RNG.
17+
/// Get a number of bytes from the RNG. The returned buffer is the initialized `buf`.
1818
fn read<'a>(&'a mut self, buf: &'a mut [MaybeUninit<u8>]) -> Self::ReadFuture<'a>;
1919
}

src/futures/spi.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
use core::{future::Future, mem::MaybeUninit};
44

55
/// Async read + write
6-
pub trait ReadWrite<Word> {
6+
pub trait ReadWrite<Word: 'static> {
77
/// Error type
88
type Error;
99

1010
/// Associated future for the `transfer` method.
11-
type ReadWriteFuture<'a>: Future<Output = Result<(), Self::Error>> + 'a
11+
type ReadWriteFuture<'a>: Future<Output = Result<&'a [Word], Self::Error>> + 'a
1212
where
1313
Self: 'a;
1414

@@ -18,17 +18,19 @@ pub trait ReadWrite<Word> {
1818
}
1919

2020
/// Async read + write in place.
21-
pub trait ReadWriteInPlace<Word> {
21+
pub trait ReadWriteInPlace<Word: 'static> {
2222
/// Error type
2323
type Error;
2424

2525
/// Associated future for the `transfer` method.
26-
type ReadWriteInPlaceFuture<'a>: Future<Output = Result<(), Self::Error>> + 'a
26+
type ReadWriteInPlaceFuture<'a>: Future<Output = Result<&'a [Word], Self::Error>> + 'a
2727
where
2828
Self: 'a;
2929

3030
/// Writes `words` to the slave from the `readwrite` buffer and reads words into the same buffer.
3131
/// This method uses a single `readwrite` buffer.
32+
///
33+
/// The returned buffer is the initialized `readwrite` buffer.
3234
fn readwrite_inplace<'a>(&'a mut self, readwrite: &'a mut [Word]) -> Self::ReadWriteInPlaceFuture<'a>;
3335
}
3436

@@ -47,17 +49,19 @@ pub trait Write<Word> {
4749
}
4850

4951
/// Async read
50-
pub trait Read<Word> {
52+
pub trait Read<Word: 'static> {
5153
/// Error type
5254
type Error;
5355

5456
/// Associated future for the `read` method.
55-
type ReadFuture<'a>: Future<Output = Result<(), Self::Error>> + 'a
57+
type ReadFuture<'a>: Future<Output = Result<&'a [Word], Self::Error>> + 'a
5658
where
5759
Self: 'a;
5860

5961
/// Reads words from the slave without specifying any data to write.
6062
/// The SPI hardware will send data, though what data it sends is not defined
61-
/// by this trait. Some hardware can configure what values (e.g. all zeroes, all ones), some cannot.
63+
/// by this trait. Some hardware can configure what values (e.g. 0x00, 0xFF), some cannot.
64+
///
65+
/// The returned buffer is the initialized `words` buffer.
6266
fn read<'a>(&'a mut self, words: &'a mut [MaybeUninit<Word>]) -> Self::ReadFuture<'a>;
6367
}

0 commit comments

Comments
 (0)