diff options
Diffstat (limited to 'nix-rust/src/foreign.rs')
-rw-r--r-- | nix-rust/src/foreign.rs | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/nix-rust/src/foreign.rs b/nix-rust/src/foreign.rs new file mode 100644 index 000000000..7bce7753c --- /dev/null +++ b/nix-rust/src/foreign.rs @@ -0,0 +1,14 @@ +/// A wrapper around Nix's Source class that provides the Read trait. +#[repr(C)] +pub struct Source { + fun: extern "C" fn(this: *mut libc::c_void, data: &mut [u8]) -> usize, + this: *mut libc::c_void, +} + +impl std::io::Read for Source { + fn read(&mut self, buf: &mut [u8]) -> std::result::Result<usize, std::io::Error> { + let n = (self.fun)(self.this, buf); + assert!(n <= buf.len()); + Ok(n) + } +} |