feat: nix-fetchers crate
(cherry picked from commit 27d572403ac98d83d652481da6c22ad50bb00168)
This commit is contained in:
parent
7ae38f296f
commit
bbf245ef1a
5 changed files with 73 additions and 2 deletions
38
rust/nix-fetchers/src/lib.rs
Normal file
38
rust/nix-fetchers/src/lib.rs
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
use anyhow::{Context as _, Result};
|
||||
use nix_c_raw as raw;
|
||||
use nix_util::context::{self, Context};
|
||||
use std::ptr::NonNull;
|
||||
|
||||
pub struct FetchersSettings {
|
||||
pub(crate) ptr: NonNull<raw::fetchers_settings>,
|
||||
}
|
||||
impl Drop for FetchersSettings {
|
||||
fn drop(&mut self) {
|
||||
unsafe {
|
||||
raw::fetchers_settings_free(self.ptr.as_ptr());
|
||||
}
|
||||
}
|
||||
}
|
||||
impl FetchersSettings {
|
||||
pub fn new() -> Result<Self> {
|
||||
let mut ctx = Context::new();
|
||||
let ptr = unsafe { context::check_call!(raw::fetchers_settings_new(&mut ctx))? };
|
||||
Ok(FetchersSettings {
|
||||
ptr: NonNull::new(ptr).context("fetchers_settings_new unexpectedly returned null")?,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn raw_ptr(&self) -> *mut raw::fetchers_settings {
|
||||
self.ptr.as_ptr()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn fetchers_settings_new() {
|
||||
let _ = FetchersSettings::new().unwrap();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue