feat: Value::new_borrowed

(cherry picked from commit 86e3828250d4de15f9cf49d19222eb382c77f7e2)
This commit is contained in:
Robert Hensing 2024-05-24 09:09:41 +02:00
parent 590a748e82
commit 9cebf1d131

View file

@ -54,11 +54,24 @@ pub struct Value {
inner: NonNull<raw::Value>,
}
impl Value {
/// Take ownership of a new Value.
///
/// This does not call `nix_gc_incref`, but does call `nix_gc_decref` when dropped.
pub(crate) fn new(inner: *mut raw::Value) -> Self {
Value {
inner: NonNull::new(inner).unwrap(),
}
}
/// Borrow a reference to a Value.
///
/// This calls `nix_gc_incref`, and the returned Value will call `nix_gc_decref` when dropped.
pub(crate) fn new_borrowed(inner: *mut raw::Value) -> Self {
let v = Value::new(inner);
unsafe { raw::value_incref(null_mut(), inner) };
v
}
pub(crate) fn raw_ptr(&self) -> *mut raw::Value {
self.inner.as_ptr()
}