primop (stash)

This commit is contained in:
do butterflies cry? 2026-03-15 03:18:39 +10:00
parent 03c72f7582
commit 6e22a8de3e
Signed by: cry
GPG key ID: F68745A836CA0412
3 changed files with 63 additions and 0 deletions

View file

@ -1,7 +1,9 @@
mod flake;
mod flakeref;
mod nix;
mod primop;
pub use flake::{Flake, FlakeBuilder, FlakeLockMode};
pub use flakeref::FlakeRef;
pub use nix::Nix;
pub use primop::PrimOp;

40
snow/src/nix/primop.rs Normal file
View file

@ -0,0 +1,40 @@
use std::ffi::{CStr, CString, NulError};
use anyhow::Result;
use nix_bindings_expr::{eval_state::EvalState, primop::PrimOpMeta, value::Value};
pub struct PrimOp<'a, const N: usize> {
// pub name: &'a CStr,
// pub doc: &'a CStr,
// pub args: [&'a CStr; N],
meta: PrimOpMeta<'a, N>,
// f: Box<dyn Fn(&mut EvalState, &[Value; N]) -> Result<Value>>,
}
impl<'a, const N: usize> PrimOp<'a, N> {
pub fn new<S>(name: S, doc: S, args: [&'a CStr; N]) -> Result<Self>
where
S: AsRef<str>,
{
let name = CString::new(name.as_ref())?.as_ref();
let doc = CString::new(doc.as_ref())?.as_ref();
// let args = args
// .iter()
// .map(|x| CString::new(x.as_ref()).as_ref())
// .collect::<Result<Vec<&CString>, &NulError>>()?
// .iter()
// .map(|x| x.as_ref())
// .collect::<Vec<&CStr>>()
// .as_slice();
Ok(PrimOp {
// name,
// doc,
// args,
meta: PrimOpMeta { name, doc, args },
})
// Ok(PrimOp {
// meta: PrimOpMeta { name, doc, args },
// })
}
}