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

21
flake.lock generated
View file

@ -185,9 +185,30 @@
"microvm": "microvm",
"nixpkgs": "nixpkgs",
"nt": "nt",
"sops-nix": "sops-nix",
"systems": "systems_3"
}
},
"sops-nix": {
"inputs": {
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1773096132,
"narHash": "sha256-M3zEnq9OElB7zqc+mjgPlByPm1O5t2fbUrH3t/Hm5Ag=",
"owner": "Mic92",
"repo": "sops-nix",
"rev": "d1ff3b1034d5bab5d7d8086a7803c5a5968cd784",
"type": "github"
},
"original": {
"owner": "Mic92",
"repo": "sops-nix",
"type": "github"
}
},
"spectrum": {
"flake": false,
"locked": {

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 },
// })
}
}