Compare commits
No commits in common. "2ac4bcfb9a95ba9ebb6b853e3fdabada0e2bfbf1" and "0d8468c71e7c79cdaadbae26989cb4015fe41954" have entirely different histories.
2ac4bcfb9a
...
0d8468c71e
15 changed files with 79 additions and 295 deletions
39
flake.lock
generated
39
flake.lock
generated
|
|
@ -1,26 +1,5 @@
|
|||
{
|
||||
"nodes": {
|
||||
"fenix": {
|
||||
"inputs": {
|
||||
"nixpkgs": [
|
||||
"nixpkgs"
|
||||
],
|
||||
"rust-analyzer-src": "rust-analyzer-src"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1774682177,
|
||||
"narHash": "sha256-OVbuJnJLlbHE28eRMudjtA6NXz/ifuXSho79gvh6GHY=",
|
||||
"owner": "nix-community",
|
||||
"repo": "fenix",
|
||||
"rev": "e0f515387df77b9fdbaaf81e7f866f0365474c18",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "nix-community",
|
||||
"repo": "fenix",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1773222311,
|
||||
|
|
@ -39,28 +18,10 @@
|
|||
},
|
||||
"root": {
|
||||
"inputs": {
|
||||
"fenix": "fenix",
|
||||
"nixpkgs": "nixpkgs",
|
||||
"systems": "systems"
|
||||
}
|
||||
},
|
||||
"rust-analyzer-src": {
|
||||
"flake": false,
|
||||
"locked": {
|
||||
"lastModified": 1774569884,
|
||||
"narHash": "sha256-E8iWEPzg7OnE0XXXjo75CX7xFauqzJuGZ5wSO9KS8Ek=",
|
||||
"owner": "rust-lang",
|
||||
"repo": "rust-analyzer",
|
||||
"rev": "443ddcddd0c73b07b799d052f5ef3b448c2f3508",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "rust-lang",
|
||||
"ref": "nightly",
|
||||
"repo": "rust-analyzer",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"systems": {
|
||||
"locked": {
|
||||
"lastModified": 1681028828,
|
||||
|
|
|
|||
97
flake.nix
97
flake.nix
|
|
@ -4,11 +4,6 @@
|
|||
inputs = {
|
||||
nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.11";
|
||||
systems.url = "github:nix-systems/default";
|
||||
|
||||
fenix = {
|
||||
url = "github:nix-community/fenix";
|
||||
inputs.nixpkgs.follows = "nixpkgs";
|
||||
};
|
||||
};
|
||||
|
||||
outputs = {
|
||||
|
|
@ -34,11 +29,8 @@
|
|||
pkgs = mkPkgs system nixpkgs;
|
||||
});
|
||||
in {
|
||||
overlays = {
|
||||
default = self: super: {
|
||||
libclang = super.llvmPackages_21.libclang;
|
||||
};
|
||||
fenix = inputs.fenix.overlays.default;
|
||||
overlays.default = self: super: {
|
||||
libclang = super.llvmPackages_21.libclang;
|
||||
};
|
||||
|
||||
devShells = forAllSystems (
|
||||
|
|
@ -115,91 +107,6 @@
|
|||
|
||||
shellHook = postConfigure;
|
||||
|
||||
env = let
|
||||
inherit (llvmPackages) llvm libclang;
|
||||
in {
|
||||
LD_LIBRARY_PATH = builtins.toString (lib.makeLibraryPath buildInputs);
|
||||
LIBCLANG_PATH = "${libclang.lib}/lib";
|
||||
|
||||
RUST_SRC_PATH = "${pkgs.rustPlatform.rustLibSrc}";
|
||||
BINDGEN_EXTRA_CLANG_ARGS = "--sysroot=${pkgs.glibc.dev}";
|
||||
|
||||
# `cargo-llvm-cov` reads these environment variables to find these binaries,
|
||||
# which are needed to run the tests
|
||||
LLVM_COV = "${llvm}/bin/llvm-cov";
|
||||
LLVM_PROFDATA = "${llvm}/bin/llvm-profdata";
|
||||
};
|
||||
};
|
||||
|
||||
nightly = let
|
||||
nixForBindings = pkgs.nixVersions.nix_2_32;
|
||||
inherit (pkgs.rustc) llvmPackages;
|
||||
in
|
||||
pkgs.mkShell rec {
|
||||
name = "nixide";
|
||||
shell = "${pkgs.bash}/bin/bash";
|
||||
strictDeps = true;
|
||||
|
||||
# packages we need at runtime
|
||||
packages = with pkgs; [
|
||||
llvmPackages.lld
|
||||
lldb
|
||||
(pkgs.fenix.complete.withComponents [
|
||||
"cargo"
|
||||
"clippy"
|
||||
"rust-src"
|
||||
"rustc"
|
||||
"rustfmt"
|
||||
])
|
||||
rust-analyzer-nightly
|
||||
|
||||
# cargo-c
|
||||
# cargo-llvm-cov
|
||||
# cargo-nextest
|
||||
];
|
||||
|
||||
# packages we need at build time
|
||||
nativeBuildInputs = with pkgs; [
|
||||
pkg-config
|
||||
glibc.dev
|
||||
nixForBindings.dev
|
||||
|
||||
rustPlatform.bindgenHook
|
||||
];
|
||||
|
||||
# packages we link against
|
||||
buildInputs = with pkgs; [
|
||||
stdenv.cc
|
||||
|
||||
nixForBindings
|
||||
];
|
||||
|
||||
# bindgen uses clang to generate bindings, but it doesn't know where to
|
||||
# find our stdenv cc's headers, so when it's gcc, we need to tell it.
|
||||
postConfigure = lib.optionalString pkgs.stdenv.cc.isGNU ''
|
||||
#!/usr/bin/env bash
|
||||
# REF: https://github.com/nixops4/nix-bindings-rust/blob/main/bindgen-gcc.sh
|
||||
# Rust bindgen uses Clang to generate bindings, but that means that it can't
|
||||
# find the "system" or compiler headers when the stdenv compiler is GCC.
|
||||
# This script tells it where to find them.
|
||||
|
||||
echo "Extending BINDGEN_EXTRA_CLANG_ARGS with system include paths..." 2>&1
|
||||
BINDGEN_EXTRA_CLANG_ARGS="$${BINDGEN_EXTRA_CLANG_ARGS:-}"
|
||||
export BINDGEN_EXTRA_CLANG_ARGS
|
||||
include_paths=$(
|
||||
echo | $NIX_CC_UNWRAPPED -v -E -x c - 2>&1 \
|
||||
| awk '/#include <...> search starts here:/{flag=1;next} \
|
||||
/End of search list./{flag=0} \
|
||||
flag==1 {print $1}'
|
||||
)
|
||||
for path in $include_paths; do
|
||||
echo " - $path" 2>&1
|
||||
BINDGEN_EXTRA_CLANG_ARGS="$BINDGEN_EXTRA_CLANG_ARGS -I$path"
|
||||
done
|
||||
'';
|
||||
|
||||
shellHook = postConfigure;
|
||||
|
||||
env = let
|
||||
inherit (llvmPackages) llvm libclang;
|
||||
in {
|
||||
|
|
|
|||
|
|
@ -82,7 +82,7 @@ impl EvalState {
|
|||
);
|
||||
value
|
||||
})
|
||||
.map(|ptr| Value::from((ptr, std::rc::Rc::new(std::cell::RefCell::new(self)))))
|
||||
.map(|ptr| Value::from((ptr, self)))
|
||||
}
|
||||
|
||||
/// Allocate a new value.
|
||||
|
|
@ -96,8 +96,7 @@ impl EvalState {
|
|||
sys::nix_alloc_value(ctx.as_ptr(), self.as_ptr())
|
||||
})?;
|
||||
|
||||
// Ok(Value::from((inner, self)))
|
||||
todo!()
|
||||
Ok(Value::from((inner, self)))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ use std::sync::Arc;
|
|||
|
||||
use serial_test::serial;
|
||||
|
||||
use super::{EvalStateBuilder, Value};
|
||||
use super::{EvalStateBuilder, ValueType};
|
||||
use crate::Store;
|
||||
|
||||
#[test]
|
||||
|
|
@ -29,12 +29,8 @@ fn test_simple_evaluation() {
|
|||
.eval_from_string("1 + 2", "<eval>")
|
||||
.expect("Failed to evaluate expression");
|
||||
|
||||
assert!(matches!(result, Value::Int(_)));
|
||||
if let Value::Int(value) = result {
|
||||
assert_eq!(value.as_int(), 3);
|
||||
} else {
|
||||
unreachable!();
|
||||
}
|
||||
assert_eq!(result.value_type(), ValueType::Int);
|
||||
assert_eq!(result.as_int().expect("Failed to get int value"), 3);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
@ -50,34 +46,22 @@ fn test_value_types() {
|
|||
let int_val = state
|
||||
.eval_from_string("42", "<eval>")
|
||||
.expect("Failed to evaluate int");
|
||||
assert!(matches!(int_val, Value::Int(_)));
|
||||
if let Value::Int(value) = int_val {
|
||||
assert_eq!(value.as_int(), 42);
|
||||
} else {
|
||||
unreachable!();
|
||||
}
|
||||
assert_eq!(int_val.value_type(), ValueType::Int);
|
||||
assert_eq!(int_val.as_int().expect("Failed to get int"), 42);
|
||||
|
||||
// Test boolean
|
||||
let bool_val = state
|
||||
.eval_from_string("true", "<eval>")
|
||||
.expect("Failed to evaluate bool");
|
||||
assert!(matches!(bool_val, Value::Bool(_)));
|
||||
if let Value::Bool(value) = bool_val {
|
||||
assert_eq!(value.as_bool(), true);
|
||||
} else {
|
||||
unreachable!();
|
||||
}
|
||||
assert_eq!(bool_val.value_type(), ValueType::Bool);
|
||||
assert!(bool_val.as_bool().expect("Failed to get bool"));
|
||||
|
||||
// Test string
|
||||
let string_val = state
|
||||
let str_val = state
|
||||
.eval_from_string("\"hello\"", "<eval>")
|
||||
.expect("Failed to evaluate string");
|
||||
assert!(matches!(string_val, Value::String(_)));
|
||||
if let Value::String(value) = string_val {
|
||||
assert_eq!(value.as_string(), "hello");
|
||||
} else {
|
||||
unreachable!();
|
||||
}
|
||||
assert_eq!(str_val.value_type(), ValueType::String);
|
||||
assert_eq!(str_val.as_string().expect("Failed to get string"), "hello");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
@ -94,29 +78,35 @@ fn test_value_formatting() {
|
|||
.eval_from_string("42", "<eval>")
|
||||
.expect("Failed to evaluate int");
|
||||
assert_eq!(format!("{int_val}"), "42");
|
||||
assert_eq!(format!("{int_val:?}"), "Value::Int(NixInt(42))");
|
||||
assert_eq!(format!("{int_val:?}"), "Value::Int(42)");
|
||||
assert_eq!(int_val.to_nix_string().expect("Failed to format"), "42");
|
||||
|
||||
// Test boolean formatting
|
||||
let true_val = state
|
||||
let bool_val = state
|
||||
.eval_from_string("true", "<eval>")
|
||||
.expect("Failed to evaluate bool");
|
||||
assert_eq!(format!("{true_val}"), "true");
|
||||
assert_eq!(format!("{true_val:?}"), "Value::Bool(NixBool(true))");
|
||||
assert_eq!(format!("{bool_val}"), "true");
|
||||
assert_eq!(format!("{bool_val:?}"), "Value::Bool(true)");
|
||||
assert_eq!(bool_val.to_nix_string().expect("Failed to format"), "true");
|
||||
|
||||
let false_val = state
|
||||
.eval_from_string("false", "<eval>")
|
||||
.expect("Failed to evaluate bool");
|
||||
assert_eq!(format!("{false_val}"), "false");
|
||||
assert_eq!(format!("{false_val:?}"), "Value::Bool(NixBool(false))");
|
||||
assert_eq!(
|
||||
false_val.to_nix_string().expect("Failed to format"),
|
||||
"false"
|
||||
);
|
||||
|
||||
// Test string formatting
|
||||
let str_val = state
|
||||
.eval_from_string("\"hello world\"", "<eval>")
|
||||
.expect("Failed to evaluate string");
|
||||
assert_eq!(format!("{str_val}"), "hello world");
|
||||
assert_eq!(format!("{str_val:?}"), "Value::String(\"hello world\")");
|
||||
assert_eq!(
|
||||
format!("{str_val:?}"),
|
||||
"Value::String(NixString(\"hello world\"))"
|
||||
str_val.to_nix_string().expect("Failed to format"),
|
||||
"\"hello world\""
|
||||
);
|
||||
|
||||
// Test string with quotes
|
||||
|
|
@ -125,8 +115,8 @@ fn test_value_formatting() {
|
|||
.expect("Failed to evaluate quoted string");
|
||||
assert_eq!(format!("{quoted_str}"), "say \"hello\"");
|
||||
assert_eq!(
|
||||
format!("{quoted_str:?}"),
|
||||
"Value::String(NixString(say \"hello\"))"
|
||||
quoted_str.to_nix_string().expect("Failed to format"),
|
||||
"\"say \\\"hello\\\"\""
|
||||
);
|
||||
|
||||
// Test null formatting
|
||||
|
|
@ -134,7 +124,8 @@ fn test_value_formatting() {
|
|||
.eval_from_string("null", "<eval>")
|
||||
.expect("Failed to evaluate null");
|
||||
assert_eq!(format!("{null_val}"), "null");
|
||||
assert_eq!(format!("{null_val:?}"), "Value::Null(NixNull)");
|
||||
assert_eq!(format!("{null_val:?}"), "Value::Null");
|
||||
assert_eq!(null_val.to_nix_string().expect("Failed to format"), "null");
|
||||
|
||||
// Test collection formatting
|
||||
let attrs_val = state
|
||||
|
|
|
|||
|
|
@ -28,13 +28,13 @@ impl Drop for NixAttrs {
|
|||
|
||||
impl Display for NixAttrs {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
|
||||
write!(f, "{{ <attrs> }}")
|
||||
write!(f, "<attrs>")
|
||||
}
|
||||
}
|
||||
|
||||
impl Debug for NixAttrs {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
|
||||
write!(f, "NixAttrs({{ <attrs> }})") // XXX: TODO: format attrNames into here
|
||||
write!(f, "NixAttrs")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -27,13 +27,13 @@ impl Drop for NixBool {
|
|||
|
||||
impl Display for NixBool {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
|
||||
write!(f, "{}", self.value())
|
||||
write!(f, "<bool>")
|
||||
}
|
||||
}
|
||||
|
||||
impl Debug for NixBool {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
|
||||
write!(f, "NixBool({})", self.value)
|
||||
write!(f, "NixBool(${})", self.value)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -80,12 +80,7 @@ impl NixBool {
|
|||
/// Returns a shared reference to the underlying value.
|
||||
///
|
||||
#[inline]
|
||||
pub fn value(&self) -> &bool {
|
||||
fn value(&self) -> &bool {
|
||||
&self.value
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn as_bool(&self) -> bool {
|
||||
self.value
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,13 +26,13 @@ impl Drop for NixFloat {
|
|||
|
||||
impl Display for NixFloat {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
|
||||
write!(f, "{}", self.value())
|
||||
write!(f, "<float>")
|
||||
}
|
||||
}
|
||||
|
||||
impl Debug for NixFloat {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
|
||||
write!(f, "NixFloat({})", self.value())
|
||||
write!(f, "NixFloat(${})", self.value())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -79,12 +79,7 @@ impl NixFloat {
|
|||
/// Returns a shared reference to the underlying value.
|
||||
///
|
||||
#[inline]
|
||||
pub fn value(&self) -> &f64 {
|
||||
fn value(&self) -> &f64 {
|
||||
&self.value
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn as_float(&self) -> f64 {
|
||||
self.value
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -74,8 +74,14 @@ impl NixValue for NixFunction {
|
|||
}
|
||||
}
|
||||
|
||||
// impl Fn<(Value,)> for NixFunction {
|
||||
// extern "rust-call" fn call(&self, args: (Value,)) -> Value {
|
||||
// args.0
|
||||
// }
|
||||
// }
|
||||
|
||||
impl NixFunction {
|
||||
pub fn call<T>(&self, arg: &T) -> Value
|
||||
fn call<T>(&self, arg: &T) -> Value
|
||||
where
|
||||
T: NixValue,
|
||||
{
|
||||
|
|
@ -98,7 +104,7 @@ impl NixFunction {
|
|||
Value::from((inner, self.state.clone()))
|
||||
}
|
||||
|
||||
pub fn call_many<T>(&self, args: &[&T]) -> Value
|
||||
fn call_many<T>(&self, args: &[&T]) -> Value
|
||||
where
|
||||
T: NixValue,
|
||||
{
|
||||
|
|
@ -122,13 +128,3 @@ impl NixFunction {
|
|||
Value::from((inner, self.state.clone()))
|
||||
}
|
||||
}
|
||||
|
||||
// #[cfg(nightly)]
|
||||
// impl<T> Fn<(&T,)> for NixFunction
|
||||
// where
|
||||
// T: NixValue,
|
||||
// {
|
||||
// extern "rust-call" fn call(&self, args: (&T,)) -> Value {
|
||||
// self.call(args.0)
|
||||
// }
|
||||
// }
|
||||
|
|
|
|||
|
|
@ -26,13 +26,13 @@ impl Drop for NixInt {
|
|||
|
||||
impl Display for NixInt {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
|
||||
write!(f, "{}", self.value())
|
||||
write!(f, "<int>")
|
||||
}
|
||||
}
|
||||
|
||||
impl Debug for NixInt {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
|
||||
write!(f, "NixInt({})", self.value())
|
||||
write!(f, "NixInt(${})", self.value())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -77,12 +77,7 @@ impl NixInt {
|
|||
/// Returns a shared reference to the underlying value.
|
||||
///
|
||||
#[inline]
|
||||
pub fn value(&self) -> &i64 {
|
||||
fn value(&self) -> &i64 {
|
||||
&self.value
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn as_int(&self) -> i64 {
|
||||
self.value
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,13 +26,13 @@ impl Drop for NixList {
|
|||
|
||||
impl Display for NixList {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
|
||||
write!(f, "[ <list> ]")
|
||||
write!(f, "<list>")
|
||||
}
|
||||
}
|
||||
|
||||
impl Debug for NixList {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
|
||||
write!(f, "NixList([ <list> ])")
|
||||
write!(f, "NixList")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -76,7 +76,7 @@ impl NixValue for NixList {
|
|||
impl NixList {
|
||||
/// Forces the evaluation on all elements of the list.
|
||||
///
|
||||
pub fn as_vec(&self) -> Vec<Value> {
|
||||
fn as_vec(&self) -> Vec<Value> {
|
||||
// XXX: TODO: should I just return a LazyArray instead?
|
||||
let mut value = Vec::new();
|
||||
for i in 0..self.len() {
|
||||
|
|
@ -86,7 +86,7 @@ impl NixList {
|
|||
value
|
||||
}
|
||||
|
||||
pub fn as_vec_lazy(&self) -> Vec<NixThunk> {
|
||||
fn as_vec_lazy(&self) -> Vec<NixThunk> {
|
||||
// XXX: TODO: should I just return a LazyArray instead?
|
||||
let mut value = Vec::new();
|
||||
for i in 0..self.len() {
|
||||
|
|
@ -99,14 +99,14 @@ impl NixList {
|
|||
/// Get the length of a list. This function preserves
|
||||
/// laziness and does not evaluate the internal fields.
|
||||
///
|
||||
pub fn len(&self) -> u32 {
|
||||
fn len(&self) -> u32 {
|
||||
wrap::nix_fn!(|ctx: &ErrorContext| unsafe {
|
||||
sys::nix_get_list_size(ctx.as_ptr(), self.as_ptr())
|
||||
})
|
||||
.unwrap_or_else(|err| panic_issue_call_failed!("{}", err))
|
||||
}
|
||||
|
||||
pub fn get(&self, index: u32) -> Value {
|
||||
fn get(&self, index: u32) -> Value {
|
||||
let inner = wrap::nix_ptr_fn!(|ctx: &ErrorContext| unsafe {
|
||||
sys::nix_get_list_byidx(
|
||||
ctx.as_ptr(),
|
||||
|
|
@ -120,7 +120,7 @@ impl NixList {
|
|||
Value::from((inner, self.state.clone()))
|
||||
}
|
||||
|
||||
pub fn get_lazy(&self, index: u32) -> NixThunk {
|
||||
fn get_lazy(&self, index: u32) -> NixThunk {
|
||||
let inner = wrap::nix_ptr_fn!(|ctx: &ErrorContext| unsafe {
|
||||
sys::nix_get_list_byidx_lazy(
|
||||
ctx.as_ptr(),
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ mod thunk;
|
|||
|
||||
pub use attrs::NixAttrs;
|
||||
pub use bool::NixBool;
|
||||
// pub use external::NixExternal;
|
||||
pub use external::NixExternal;
|
||||
// pub use failed::NixFailed; // only in latest nix version
|
||||
pub use float::NixFloat;
|
||||
pub use function::NixFunction;
|
||||
|
|
@ -24,7 +24,7 @@ pub use string::NixString;
|
|||
pub use thunk::NixThunk;
|
||||
|
||||
use std::cell::RefCell;
|
||||
use std::fmt::{Debug, Display, Formatter, Result as FmtResult};
|
||||
use std::fmt::{Debug, Display};
|
||||
use std::ptr::NonNull;
|
||||
use std::rc::Rc;
|
||||
|
||||
|
|
@ -107,8 +107,12 @@ pub enum Value {
|
|||
|
||||
/// TODO
|
||||
Function(NixFunction),
|
||||
// External(NixExternal),
|
||||
// Failed(NixFailed),
|
||||
|
||||
/// TODO
|
||||
External(NixExternal),
|
||||
|
||||
/// TODO
|
||||
Failed(NixFailed),
|
||||
}
|
||||
|
||||
impl From<(NonNull<sys::nix_value>, Rc<RefCell<EvalState>>)> for Value {
|
||||
|
|
@ -138,61 +142,13 @@ impl From<(NonNull<sys::nix_value>, Rc<RefCell<EvalState>>)> for Value {
|
|||
ValueType_NIX_TYPE_FUNCTION => {
|
||||
Value::Function(<NixFunction as NixValue>::from(inner, state))
|
||||
},
|
||||
// ValueType_NIX_TYPE_EXTERNAL => {
|
||||
// Value::External(<NixExternal as NixValue>::from(inner, state))
|
||||
// },
|
||||
// ValueType_NIX_TYPE_FAILED => {
|
||||
ValueType_NIX_TYPE_EXTERNAL => {
|
||||
Value::External(<NixExternal as NixValue>::from(inner, state))
|
||||
},
|
||||
// | sys::ValueType_NIX_TYPE_FAILED => {
|
||||
// Value::Failed(<NixFailed as NixValue>::from(inner, state))
|
||||
// },
|
||||
_ => unreachable!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for Value {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
|
||||
match self {
|
||||
Value::Thunk(value) => write!(f, "{value}"),
|
||||
Value::Int(value) => write!(f, "{value}"),
|
||||
Value::Float(value) => write!(f, "{value}"),
|
||||
Value::Bool(value) => write!(f, "{value}"),
|
||||
Value::String(value) => write!(f, "{value}"),
|
||||
Value::Path(value) => write!(f, "{value}"),
|
||||
Value::Null(value) => write!(f, "{value}"),
|
||||
Value::Attrs(value) => write!(f, "{value}"),
|
||||
Value::List(value) => write!(f, "{value}"),
|
||||
Value::Function(value) => write!(f, "{value}"),
|
||||
// Value::External(value) => write!(f, "{value}"),
|
||||
// Value::Failed(value) => write!(f, "{value}"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Debug for Value {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
|
||||
match self {
|
||||
Value::Thunk(value) => write!(f, "Value::Thunk({value:?})"),
|
||||
Value::Int(value) => write!(f, "Value::Int({value:?})"),
|
||||
Value::Float(value) => write!(f, "Value::Float({value:?})"),
|
||||
Value::Bool(value) => write!(f, "Value::Bool({value:?})"),
|
||||
Value::String(value) => write!(f, "Value::String({value:?})"),
|
||||
Value::Path(value) => write!(f, "Value::Path({value:?})"),
|
||||
Value::Null(value) => write!(f, "Value::Null({value:?})"),
|
||||
Value::Attrs(value) => write!(f, "Value::Attrs({value:?})"),
|
||||
Value::List(value) => write!(f, "Value::List({value:?})"),
|
||||
Value::Function(value) => write!(f, "Value::Function({value:?})"),
|
||||
// Value::External(value) => write!(f, "Value::External({value:?})"),
|
||||
// Value::Failed(value) => write!(f, "Value::Failed({value:?})"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// macro_rules! is_type {
|
||||
// ($expr:expr, $tt:tt) => {{
|
||||
// match $expr {
|
||||
// $tt => true,
|
||||
// _ => false,
|
||||
// }
|
||||
// }};
|
||||
// }
|
||||
// pub(self) use is_type;
|
||||
|
|
|
|||
|
|
@ -29,13 +29,13 @@ impl Drop for NixPath {
|
|||
|
||||
impl Display for NixPath {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
|
||||
write!(f, "{}", self.value.display())
|
||||
write!(f, "<path>")
|
||||
}
|
||||
}
|
||||
|
||||
impl Debug for NixPath {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
|
||||
write!(f, "NixPath(\"{}\")", self.value().display())
|
||||
write!(f, "NixPath(\"${}\")", self.value().display())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -82,12 +82,7 @@ impl NixPath {
|
|||
/// Returns a shared reference to the underlying value.
|
||||
///
|
||||
#[inline]
|
||||
pub fn value(&self) -> &PathBuf {
|
||||
fn value(&self) -> &PathBuf {
|
||||
&self.value
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn as_path(&self) -> PathBuf {
|
||||
self.value.clone()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,13 +28,13 @@ impl Drop for NixString {
|
|||
|
||||
impl Display for NixString {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
|
||||
write!(f, "{}", self.value())
|
||||
write!(f, "<string>")
|
||||
}
|
||||
}
|
||||
|
||||
impl Debug for NixString {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
|
||||
write!(f, "NixString(\"{}\")", self.value())
|
||||
write!(f, "NixString(\"${}\")", self.value())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -86,12 +86,7 @@ impl NixString {
|
|||
/// Returns a shared reference to the underlying value.
|
||||
///
|
||||
#[inline]
|
||||
pub fn value(&self) -> &String {
|
||||
fn value(&self) -> &String {
|
||||
&self.value
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn as_string(&self) -> String {
|
||||
self.value.clone()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -65,11 +65,11 @@ impl NixValue for NixThunk {
|
|||
}
|
||||
|
||||
impl NixThunk {
|
||||
// fn to_inner(self) -> NonNull<sys::nix_value> {
|
||||
// self.inner
|
||||
// }
|
||||
fn to_inner(self) -> NonNull<sys::nix_value> {
|
||||
self.inner
|
||||
}
|
||||
|
||||
pub fn eval(self) -> Value {
|
||||
fn eval(self) -> Value {
|
||||
wrap::nix_fn!(|ctx: &ErrorContext| unsafe {
|
||||
sys::nix_value_force(
|
||||
ctx.as_ptr(),
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
// #![warn(missing_docs)]
|
||||
|
||||
#![cfg_attr(nightly, feature(fn_traits))]
|
||||
#![cfg_attr(nightly, feature(unboxed_closures))]
|
||||
|
||||
pub extern crate libc;
|
||||
pub extern crate nixide_sys as sys;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue