feat: EvalState.realise_string

(cherry picked from commit f2b1142018fd64dd45ec97f1eccf0c48cc4a8c6d)
This commit is contained in:
Robert Hensing 2024-04-08 16:54:36 +02:00
parent 6736f05a3f
commit 87203ef394
3 changed files with 140 additions and 1 deletions

View file

@ -0,0 +1,33 @@
use anyhow::Result;
use nix_c_raw as raw;
use nix_util::string_return::{callback_get_vec_u8, callback_get_vec_u8_data};
pub struct StorePath {
raw: *mut raw::StorePath,
}
impl StorePath {
pub fn new_raw_clone(raw: *const raw::StorePath) -> Self {
Self::new_raw(unsafe { raw::store_path_clone(raw as *mut raw::StorePath) })
}
pub fn new_raw(raw: *mut raw::StorePath) -> Self {
StorePath { raw }
}
pub fn name(&self) -> Result<String> {
unsafe {
let mut vec = Vec::new();
raw::store_path_name(
self.raw,
Some(callback_get_vec_u8),
callback_get_vec_u8_data(&mut vec),
);
String::from_utf8(vec).map_err(|e| e.into())
}
}
}
impl Drop for StorePath {
fn drop(&mut self) {
unsafe {
raw::store_path_free(self.raw);
}
}
}