From e6b993a42ba1a479cdcec32f8c1e0c123676ef1a Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Wed, 2 Apr 2025 18:49:03 +0200 Subject: [PATCH] feat: nix_expr::value::__private Exposes the Value constructors, for use by other bindings like nix-flake, which needs to construct e.g. a flake outputs Value. See https://github.com/nixops4/nixops4/issues/25 > We have two related issues: > A bunch of implementation details cannot be made private, since they must be used from one of the other crates (e.g. Values are defined in the value module but used from eval_state > While we don't want users to need to use these features, it may be good to provide escape hatches so they can interface with the raw API if they need more control. > Problem (1) has been solved in other crates with a __private module with #[doc(hidden)] set. See for instance: I'm leaving docs turned on for (2). The issue has more thoughts about alternatives. (cherry picked from commit eb6744d1519febe5b6aa6233eb3f3e8a049f12d4) --- rust/nix-expr/src/value.rs | 2 ++ rust/nix-expr/src/value/__private.rs | 13 +++++++++++++ 2 files changed, 15 insertions(+) create mode 100644 rust/nix-expr/src/value/__private.rs diff --git a/rust/nix-expr/src/value.rs b/rust/nix-expr/src/value.rs index ca7b5a4..bfa7011 100644 --- a/rust/nix-expr/src/value.rs +++ b/rust/nix-expr/src/value.rs @@ -1,3 +1,5 @@ +pub mod __private; + use nix_c_raw as raw; use nix_util::{check_call, context::Context}; use std::ptr::{null_mut, NonNull}; diff --git a/rust/nix-expr/src/value/__private.rs b/rust/nix-expr/src/value/__private.rs new file mode 100644 index 0000000..6b5b2e8 --- /dev/null +++ b/rust/nix-expr/src/value/__private.rs @@ -0,0 +1,13 @@ +//! Functions that are relevant for other bindings modules, but normally not end users. +use super::Value; +use nix_c_raw as raw; + +/// See [Value::new]. +pub unsafe fn raw_value_new(ptr: *mut raw::Value) -> Value { + Value::new(ptr) +} + +/// See [Value::new_borrowed]. +pub unsafe fn raw_value_new_borrowed(ptr: *mut raw::Value) -> Value { + Value::new_borrowed(ptr) +}