mirror of
https://github.com/NixOS/nix
synced 2025-06-26 15:51:15 +02:00
Rust cleanup
This commit is contained in:
parent
343ebcc048
commit
8110b4ebb2
6 changed files with 74 additions and 63 deletions
14
nix-rust/src/foreign.rs
Normal file
14
nix-rust/src/foreign.rs
Normal 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)
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue