-
Notifications
You must be signed in to change notification settings - Fork 132
allow to_extend to work with reference to write #210
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -250,6 +250,47 @@ where | |||||
| } | ||||||
| } | ||||||
|
|
||||||
| /// Wrapper over a [`core::iter::Extend<u8>`] that implements the flavor trait | ||||||
| /// | ||||||
| /// This is like [`ExtendFlavor`], but it takes the writer by reference instead of | ||||||
| /// by value. This allows you to remain in control of the writer. | ||||||
| pub struct ExtendRefFlavor<'a, T> { | ||||||
| iter: &'a mut T, | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe call it
Suggested change
|
||||||
| } | ||||||
|
|
||||||
| impl<'a, T> ExtendRefFlavor<'a, T> | ||||||
| where | ||||||
| T: core::iter::Extend<u8>, | ||||||
| { | ||||||
| /// Create a new [`Self`] flavor from a given [`core::iter::Extend<u8>`] | ||||||
| pub fn new(iter: &'a mut T) -> Self { | ||||||
| Self { iter } | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| impl<T> Flavor for ExtendRefFlavor<'_, T> | ||||||
| where | ||||||
| T: core::iter::Extend<u8>, | ||||||
| { | ||||||
| type Output = (); | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe return used size for convenience? |
||||||
|
|
||||||
| #[inline(always)] | ||||||
| fn try_push(&mut self, data: u8) -> Result<()> { | ||||||
| self.iter.extend([data]); | ||||||
| Ok(()) | ||||||
| } | ||||||
|
|
||||||
| #[inline(always)] | ||||||
| fn try_extend(&mut self, b: &[u8]) -> Result<()> { | ||||||
| self.iter.extend(b.iter().copied()); | ||||||
| Ok(()) | ||||||
| } | ||||||
|
|
||||||
| fn finalize(self) -> Result<Self::Output> { | ||||||
| Ok(()) | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| /// Support for the [`embedded-io`](crate::eio::embedded_io) traits | ||||||
| #[cfg(any(feature = "embedded-io-04", feature = "embedded-io-06"))] | ||||||
| pub mod eio { | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe use the word "mut" instead? When I see "ref", I usually expect
&.