-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Source and Dest traits with Vec<u8>
- Loading branch information
Showing
5 changed files
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
use crate::Dest; | ||
|
||
impl<T> Dest for Vec<T> {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
mod in_memory; | ||
|
||
pub use in_memory::*; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,18 @@ | ||
pub mod dests; | ||
pub mod sources; | ||
|
||
pub trait Dest: private::Sealed {} | ||
|
||
pub trait Source<Dest>: private::Sealed { | ||
/// Error returned by [`Self::capture`] | ||
type Error; | ||
|
||
/// Captures a frame from the `Source` and puts it in `Dest`. | ||
fn capture(&mut self, dest: &mut Dest) -> Result<(), Self::Error>; | ||
} | ||
|
||
mod private { | ||
pub trait Sealed {} | ||
|
||
impl<T> Sealed for Vec<T> {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
use std::convert::Infallible; | ||
|
||
use crate::Source; | ||
|
||
impl<T> Source<Vec<T>> for Vec<T> { | ||
type Error = Infallible; | ||
|
||
fn capture(&mut self, dest: &mut Vec<T>) -> Result<(), Self::Error> { | ||
std::mem::swap(dest, self); | ||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
mod in_memory; | ||
|
||
pub use in_memory::*; |