1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-26 15:51:15 +02:00

Rust cleanup

This commit is contained in:
Eelco Dolstra 2019-09-10 21:55:32 +02:00
parent 343ebcc048
commit 8110b4ebb2
6 changed files with 74 additions and 63 deletions

14
nix-rust/src/foreign.rs Normal file
View file

@ -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)
}
}