embedded-io-async-0.6.1/.cargo_vcs_info.json0000644000000001570000000000100143140ustar { "git": { "sha1": "a8c72e9efa978d52c832e09b86373ca34fcf9d89" }, "path_in_vcs": "embedded-io-async" }embedded-io-async-0.6.1/CHANGELOG.md000064400000000000000000000016731046102023000147210ustar 00000000000000# Changelog All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## Unreleased Add unreleased changes here ## 0.6.1 - 2023-11-28 - Use `feature()` on nightly toolchains only. This adds support for 1.75 beta and stable. ## 0.6.0 - 2023-10-02 - Prohibit `Write::write` implementations returning `Ok(0)` unless there is no data to write; consequently remove `WriteAllError`. Update the `&mut [u8]` impl to possibly return a new `SliceWriteError` if the slice is full instead of `Ok(0)`. - Add `WriteZero` variant to `ErrorKind` for implementations that previously may have returned `Ok(0)` to indicate no further data could be written. - `Write::write_all` now panics if the `write()` implementation returns `Ok(0)`. ## 0.5.0 - 2023-08-06 - First release embedded-io-async-0.6.1/Cargo.toml0000644000000021160000000000100123070ustar # THIS FILE IS AUTOMATICALLY GENERATED BY CARGO # # When uploading crates to the registry Cargo will automatically # "normalize" Cargo.toml files for maximal compatibility # with all versions of Cargo and also rewrite `path` dependencies # to registry (e.g., crates.io) dependencies. # # If you are reading this file be aware that the original Cargo.toml # will likely look very different (and much more reasonable). # See Cargo.toml.orig for the original contents. [package] edition = "2021" name = "embedded-io-async" version = "0.6.1" description = "Async embedded IO traits" readme = "README.md" categories = [ "embedded", "no-std", ] license = "MIT OR Apache-2.0" repository = "https://github.com/rust-embedded/embedded-hal" [package.metadata.docs.rs] features = ["std"] rustdoc-args = [ "--cfg", "docsrs", ] [dependencies.defmt-03] version = "0.3" optional = true package = "defmt" [dependencies.embedded-io] version = "0.6" [features] alloc = ["embedded-io/alloc"] defmt-03 = [ "dep:defmt-03", "embedded-io/defmt-03", ] std = [ "alloc", "embedded-io/std", ] embedded-io-async-0.6.1/Cargo.toml.orig000064400000000000000000000011611046102023000157670ustar 00000000000000[package] name = "embedded-io-async" version = "0.6.1" edition = "2021" description = "Async embedded IO traits" repository = "https://github.com/rust-embedded/embedded-hal" readme = "README.md" license = "MIT OR Apache-2.0" categories = [ "embedded", "no-std", ] [features] std = ["alloc", "embedded-io/std"] alloc = ["embedded-io/alloc"] defmt-03 = ["dep:defmt-03", "embedded-io/defmt-03"] [dependencies] embedded-io = { version = "0.6", path = "../embedded-io" } defmt-03 = { package = "defmt", version = "0.3", optional = true } [package.metadata.docs.rs] features = ["std"] rustdoc-args = ["--cfg", "docsrs"] embedded-io-async-0.6.1/LICENSE-APACHE000064400000000000000000000251371046102023000150350ustar 00000000000000 Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. embedded-io-async-0.6.1/LICENSE-MIT000064400000000000000000000020611046102023000145340ustar 00000000000000Copyright (c) 2023 The embedded-io-async authors Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. embedded-io-async-0.6.1/README.md000064400000000000000000000033041046102023000143600ustar 00000000000000[![crates.io](https://img.shields.io/crates/d/embedded-io-async.svg)](https://crates.io/crates/embedded-io-async) [![crates.io](https://img.shields.io/crates/v/embedded-io-async.svg)](https://crates.io/crates/embedded-io-async) [![Documentation](https://docs.rs/embedded-io-async/badge.svg)](https://docs.rs/embedded-io-async) # `embedded-io-async` Async IO traits for embedded systems. This crate contains asynchronous versions of the [`embedded-io`](https://crates.io/crates/embedded-io) traits and shares its scope and design goals. This project is developed and maintained by the [HAL team](https://github.com/rust-embedded/wg#the-hal-team). ## Optional Cargo features - **`std`**: Adds `From` impls to convert to/from `std::io` structs, adds `std::error::Error` impls. - **`alloc`**: Adds blanket impls for `Box`, adds `Write` impl to `Vec`. - **`defmt-03`**: Derive `defmt::Format` from `defmt` 0.3 for enums and structs. ## Minimum Supported Rust Version (MSRV) This crate requires Rust nightly newer than `nightly-2022-11-22`, due to requiring support for `async fn` in traits (AFIT), which is not stable yet. Keep in mind Rust nightlies can make backwards-incompatible changes to unstable features at any time. ## License Licensed under either of - Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or ) - MIT license ([LICENSE-MIT](LICENSE-MIT) or ) at your option. ### Contribution Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions. embedded-io-async-0.6.1/build.rs000064400000000000000000000007221046102023000145470ustar 00000000000000use std::env; use std::ffi::OsString; use std::process::Command; fn main() { println!("cargo:rerun-if-changed=build.rs"); let rustc = env::var_os("RUSTC").unwrap_or_else(|| OsString::from("rustc")); let output = Command::new(rustc) .arg("--version") .output() .expect("failed to run `rustc --version`"); if String::from_utf8_lossy(&output.stdout).contains("nightly") { println!("cargo:rustc-cfg=nightly"); } } embedded-io-async-0.6.1/src/impls/boxx.rs000064400000000000000000000023351046102023000163450ustar 00000000000000use crate::{BufRead, Read, Seek, SeekFrom, Write}; use alloc::boxed::Box; #[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))] impl Read for Box { #[inline] async fn read(&mut self, buf: &mut [u8]) -> Result { T::read(self, buf).await } } #[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))] impl BufRead for Box { #[inline] async fn fill_buf(&mut self) -> Result<&[u8], Self::Error> { T::fill_buf(self).await } #[inline] fn consume(&mut self, amt: usize) { T::consume(self, amt); } } #[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))] impl Write for Box { #[inline] async fn write(&mut self, buf: &[u8]) -> Result { T::write(self, buf).await } #[inline] async fn flush(&mut self) -> Result<(), Self::Error> { T::flush(self).await } } #[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))] impl Seek for Box { #[inline] async fn seek(&mut self, pos: SeekFrom) -> Result { T::seek(self, pos).await } } embedded-io-async-0.6.1/src/impls/mod.rs000064400000000000000000000001461046102023000161420ustar 00000000000000mod slice_mut; mod slice_ref; #[cfg(feature = "alloc")] mod boxx; #[cfg(feature = "alloc")] mod vec; embedded-io-async-0.6.1/src/impls/slice_mut.rs000064400000000000000000000016651046102023000173560ustar 00000000000000use core::mem; use embedded_io::SliceWriteError; use crate::Write; /// Write is implemented for `&mut [u8]` by copying into the slice, overwriting /// its data. /// /// Note that writing updates the slice to point to the yet unwritten part. /// The slice will be empty when it has been completely overwritten. /// /// If the number of bytes to be written exceeds the size of the slice, write operations will /// return short writes: ultimately, `Ok(0)`; in this situation, `write_all` returns an error of /// kind `ErrorKind::WriteZero`. impl Write for &mut [u8] { #[inline] async fn write(&mut self, buf: &[u8]) -> Result { let amt = core::cmp::min(buf.len(), self.len()); if !buf.is_empty() && amt == 0 { return Err(SliceWriteError::Full); } let (a, b) = mem::take(self).split_at_mut(amt); a.copy_from_slice(&buf[..amt]); *self = b; Ok(amt) } } embedded-io-async-0.6.1/src/impls/slice_ref.rs000064400000000000000000000017771046102023000173310ustar 00000000000000use crate::{BufRead, Read}; /// Read is implemented for `&[u8]` by copying from the slice. /// /// Note that reading updates the slice to point to the yet unread part. /// The slice will be empty when EOF is reached. impl Read for &[u8] { #[inline] async fn read(&mut self, buf: &mut [u8]) -> Result { let amt = core::cmp::min(buf.len(), self.len()); let (a, b) = self.split_at(amt); // First check if the amount of bytes we want to read is small: // `copy_from_slice` will generally expand to a call to `memcpy`, and // for a single byte the overhead is significant. if amt == 1 { buf[0] = a[0]; } else { buf[..amt].copy_from_slice(a); } *self = b; Ok(amt) } } impl BufRead for &[u8] { #[inline] async fn fill_buf(&mut self) -> Result<&[u8], Self::Error> { Ok(*self) } #[inline] fn consume(&mut self, amt: usize) { *self = &self[amt..]; } } embedded-io-async-0.6.1/src/impls/vec.rs000064400000000000000000000004441046102023000161410ustar 00000000000000use alloc::vec::Vec; use crate::Write; #[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))] impl Write for Vec { #[inline] async fn write(&mut self, buf: &[u8]) -> Result { self.extend_from_slice(buf); Ok(buf.len()) } } embedded-io-async-0.6.1/src/lib.rs000064400000000000000000000204261046102023000150100ustar 00000000000000#![cfg_attr(not(feature = "std"), no_std)] #![cfg_attr(docsrs, feature(doc_cfg))] #![warn(missing_docs)] #![doc = include_str!("../README.md")] // disable warning for already-stabilized features. // Needed to pass CI, because we deny warnings. // We don't immediately remove them to not immediately break older nightlies. // When all features are stable, we'll remove them. #![cfg_attr(nightly, allow(stable_features, unknown_lints))] #![cfg_attr(nightly, feature(async_fn_in_trait, impl_trait_projections))] #![allow(async_fn_in_trait)] #[cfg(feature = "alloc")] extern crate alloc; mod impls; pub use embedded_io::{ Error, ErrorKind, ErrorType, ReadExactError, ReadReady, SeekFrom, WriteReady, }; /// Async reader. /// /// This trait is the `embedded-io-async` equivalent of [`std::io::Read`]. pub trait Read: ErrorType { /// Read some bytes from this source into the specified buffer, returning how many bytes were read. /// /// If no bytes are currently available to read, this function waits until at least one byte is available. /// /// If bytes are available, a non-zero amount of bytes is read to the beginning of `buf`, and the amount /// is returned. It is not guaranteed that *all* available bytes are returned, it is possible for the /// implementation to read an amount of bytes less than `buf.len()` while there are more bytes immediately /// available. /// /// If the reader is at end-of-file (EOF), `Ok(0)` is returned. There is no guarantee that a reader at EOF /// will always be so in the future, for example a reader can stop being at EOF if another process appends /// more bytes to the underlying file. /// /// If `buf.len() == 0`, `read` returns without waiting, with either `Ok(0)` or an error. /// The `Ok(0)` doesn't indicate EOF, unlike when called with a non-empty buffer. /// /// Implementations are encouraged to make this function side-effect-free on cancel (AKA "cancel-safe"), i.e. /// guarantee that if you cancel (drop) a `read()` future that hasn't completed yet, the stream's /// state hasn't changed (no bytes have been read). /// /// This is not a requirement to allow implementations that read into the user's buffer straight from /// the hardware with e.g. DMA. /// /// Implementations should document whether they're actually side-effect-free on cancel or not. async fn read(&mut self, buf: &mut [u8]) -> Result; /// Read the exact number of bytes required to fill `buf`. /// /// This function calls `read()` in a loop until exactly `buf.len()` bytes have /// been read, waiting if needed. /// /// This function is not side-effect-free on cancel (AKA "cancel-safe"), i.e. if you cancel (drop) a returned /// future that hasn't completed yet, some bytes might have already been read, which will get lost. async fn read_exact(&mut self, mut buf: &mut [u8]) -> Result<(), ReadExactError> { while !buf.is_empty() { match self.read(buf).await { Ok(0) => break, Ok(n) => buf = &mut buf[n..], Err(e) => return Err(ReadExactError::Other(e)), } } if buf.is_empty() { Ok(()) } else { Err(ReadExactError::UnexpectedEof) } } } /// Async buffered reader. /// /// This trait is the `embedded-io-async` equivalent of [`std::io::BufRead`]. pub trait BufRead: ErrorType { /// Return the contents of the internal buffer, filling it with more data from the inner reader if it is empty. /// /// If no bytes are currently available to read, this function waits until at least one byte is available. /// /// If the reader is at end-of-file (EOF), an empty slice is returned. There is no guarantee that a reader at EOF /// will always be so in the future, for example a reader can stop being at EOF if another process appends /// more bytes to the underlying file. async fn fill_buf(&mut self) -> Result<&[u8], Self::Error>; /// Tell this buffer that `amt` bytes have been consumed from the buffer, so they should no longer be returned in calls to `fill_buf`. fn consume(&mut self, amt: usize); } /// Async writer. /// /// This trait is the `embedded-io-async` equivalent of [`std::io::Write`]. pub trait Write: ErrorType { /// Write a buffer into this writer, returning how many bytes were written. /// /// If the writer is not currently ready to accept more bytes (for example, its buffer is full), /// this function waits until it is ready to accept least one byte. /// /// If it's ready to accept bytes, a non-zero amount of bytes is written from the beginning of `buf`, and the amount /// is returned. It is not guaranteed that *all* available buffer space is filled, i.e. it is possible for the /// implementation to write an amount of bytes less than `buf.len()` while the writer continues to be /// ready to accept more bytes immediately. /// /// Implementations should never return `Ok(0)` when `buf.len() != 0`. Situations where the writer is not /// able to accept more bytes and likely never will are better indicated with errors. /// /// If `buf.len() == 0`, `write` returns without waiting, with either `Ok(0)` or an error. /// The `Ok(0)` doesn't indicate an error. /// /// Implementations are encouraged to make this function side-effect-free on cancel (AKA "cancel-safe"), i.e. /// guarantee that if you cancel (drop) a `write()` future that hasn't completed yet, the stream's /// state hasn't changed (no bytes have been written). /// /// This is not a requirement to allow implementations that write from the user's buffer straight to /// the hardware with e.g. DMA. /// /// Implementations should document whether they're actually side-effect-free on cancel or not. async fn write(&mut self, buf: &[u8]) -> Result; /// Flush this output stream, ensuring that all intermediately buffered contents reach their destination. async fn flush(&mut self) -> Result<(), Self::Error> { Ok(()) } /// Write an entire buffer into this writer. /// /// This function calls `write()` in a loop until exactly `buf.len()` bytes have /// been written, waiting if needed. /// /// This function is not side-effect-free on cancel (AKA "cancel-safe"), i.e. if you cancel (drop) a returned /// future that hasn't completed yet, some bytes might have already been written. async fn write_all(&mut self, buf: &[u8]) -> Result<(), Self::Error> { let mut buf = buf; while !buf.is_empty() { match self.write(buf).await { Ok(0) => panic!("write() returned Ok(0)"), Ok(n) => buf = &buf[n..], Err(e) => return Err(e), } } Ok(()) } } /// Async seek within streams. /// /// This trait is the `embedded-io-async` equivalent of [`std::io::Seek`]. pub trait Seek: ErrorType { /// Seek to an offset, in bytes, in a stream. async fn seek(&mut self, pos: SeekFrom) -> Result; /// Rewind to the beginning of a stream. async fn rewind(&mut self) -> Result<(), Self::Error> { self.seek(SeekFrom::Start(0)).await?; Ok(()) } /// Returns the current seek position from the start of the stream. async fn stream_position(&mut self) -> Result { self.seek(SeekFrom::Current(0)).await } } impl Read for &mut T { #[inline] async fn read(&mut self, buf: &mut [u8]) -> Result { T::read(self, buf).await } } impl BufRead for &mut T { async fn fill_buf(&mut self) -> Result<&[u8], Self::Error> { T::fill_buf(self).await } fn consume(&mut self, amt: usize) { T::consume(self, amt); } } impl Write for &mut T { #[inline] async fn write(&mut self, buf: &[u8]) -> Result { T::write(self, buf).await } #[inline] async fn flush(&mut self) -> Result<(), Self::Error> { T::flush(self).await } } impl Seek for &mut T { #[inline] async fn seek(&mut self, pos: SeekFrom) -> Result { T::seek(self, pos).await } }