diff --git a/rust/nix-expr/src/value.rs b/rust/nix-expr/src/value.rs index 77ef048..e15d5b9 100644 --- a/rust/nix-expr/src/value.rs +++ b/rust/nix-expr/src/value.rs @@ -54,11 +54,24 @@ pub struct Value { inner: NonNull, } 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() }