Skip to content

Commit

Permalink
Added Source and Dest traits with Vec<u8>
Browse files Browse the repository at this point in the history
  • Loading branch information
TheButlah committed Nov 24, 2023
1 parent d657f44 commit cbbee08
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 0 deletions.
3 changes: 3 additions & 0 deletions crates/universal-capture/src/dests/in_memory.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
use crate::Dest;

impl<T> Dest for Vec<T> {}
3 changes: 3 additions & 0 deletions crates/universal-capture/src/dests/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
mod in_memory;

pub use in_memory::*;
17 changes: 17 additions & 0 deletions crates/universal-capture/src/lib.rs
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> {}
}
12 changes: 12 additions & 0 deletions crates/universal-capture/src/sources/in_memory.rs
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(())
}
}
3 changes: 3 additions & 0 deletions crates/universal-capture/src/sources/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
mod in_memory;

pub use in_memory::*;

0 comments on commit cbbee08

Please sign in to comment.