Skip to content
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

Accept IntoIterators for transfer_multiple #7

Merged
merged 1 commit into from
Oct 25, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,9 @@ impl Spidev {
/// Chaining together multiple requests like this can reduce latency
/// and be used for conveniently and efficient implementing some
/// protocols without extra round trips back to userspace.
pub fn transfer_multiple(&self, transfers: &Vec<SpidevTransfer>) -> io::Result<()> {
pub fn transfer_multiple<'a, I>(&self, transfers: I) -> io::Result<()>
where I: IntoIterator<Item = &'a SpidevTransfer>
{
spidevioctl::transfer_multiple(self.devfile.as_raw_fd(), transfers)
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/spidevioctl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,11 @@ pub fn transfer(fd: RawFd, transfer: &mut SpidevTransfer) -> io::Result<()> {
Ok(())
}

pub fn transfer_multiple(fd: RawFd, transfers: &Vec<SpidevTransfer>) -> io::Result<()> {
pub fn transfer_multiple<'a, I>(fd: RawFd, transfers: I) -> io::Result<()>
where I: IntoIterator<Item = &'a SpidevTransfer>
{
// create a boxed slice containing several spi_ioc_transfers
let mut raw_transfers = transfers.iter()
let mut raw_transfers = transfers.into_iter()
.map(|transfer| transfer.as_spi_ioc_transfer())
.collect::<Vec<_>>()
.into_boxed_slice();
Expand Down