fmt: tidy

This commit is contained in:
2026-01-03 17:17:36 +08:00
parent 40884c21ad
commit 159267c70b
3 changed files with 36 additions and 35 deletions

View File

@@ -111,9 +111,7 @@ fn op_import(#[string] path: String) -> std::result::Result<String, NixError> {
CONTEXT_HOLDER.with(|holder| {
let mut ptr = holder
.borrow()
.ok_or_else(|| -> NixError {
"No context available".to_string().into()
})?;
.ok_or_else(|| -> NixError { "No context available".to_string().into() })?;
let ctx = unsafe { ptr.as_mut() };
// 1. Resolve path relative to current file (or CWD if top-level)
@@ -137,10 +135,9 @@ fn op_import(#[string] path: String) -> std::result::Result<String, NixError> {
let _guard = ImportPathGuard::push(absolute_path.clone());
// 3. Read file
let content = std::fs::read_to_string(&absolute_path)
.map_err(|e| -> NixError {
format!("Failed to read {}: {}", absolute_path.display(), e).into()
})?;
let content = std::fs::read_to_string(&absolute_path).map_err(|e| -> NixError {
format!("Failed to read {}: {}", absolute_path.display(), e).into()
})?;
// 4. Parse
let root = rnix::Root::parse(&content);
@@ -149,22 +146,19 @@ fn op_import(#[string] path: String) -> std::result::Result<String, NixError> {
"Parse error in {}: {:?}",
absolute_path.display(),
root.errors()
).into());
)
.into());
}
// 5. Downgrade to IR
let expr = root
.tree()
.expr()
.ok_or_else(|| -> NixError {
"No expression in file".to_string().into()
})?;
.ok_or_else(|| -> NixError { "No expression in file".to_string().into() })?;
let expr_id = ctx
.downgrade_ctx()
.downgrade(expr)
.map_err(|e| -> NixError {
format!("Downgrade error: {}", e).into()
})?;
.map_err(|e| -> NixError { format!("Downgrade error: {}", e).into() })?;
// 6. Codegen - returns JS code string
Ok(ctx.get_ir(expr_id).compile(ctx))
@@ -175,9 +169,7 @@ fn op_import(#[string] path: String) -> std::result::Result<String, NixError> {
#[string]
fn op_read_file(#[string] path: String) -> std::result::Result<String, NixError> {
std::fs::read_to_string(&path)
.map_err(|e| -> NixError {
format!("Failed to read {}: {}", path, e).into()
})
.map_err(|e| -> NixError { format!("Failed to read {}: {}", path, e).into() })
}
#[deno_core::op2(fast)]
@@ -207,9 +199,7 @@ fn op_resolve_path(#[string] path: String) -> std::result::Result<String, NixErr
.join(&path)
.canonicalize()
.map(|p| p.to_string_lossy().to_string())
.map_err(|e| -> NixError {
format!("Failed to resolve path {}: {}", path, e).into()
})
.map_err(|e| -> NixError { format!("Failed to resolve path {}: {}", path, e).into() })
}
// Runtime context for V8 value conversion
@@ -271,7 +261,10 @@ pub fn run(script: String, ctx: &mut Context) -> Result<Value> {
// Initialize V8 once
INIT.call_once(|| {
JsRuntime::init_platform(Some(v8::new_default_platform(0, false).make_shared()), false);
JsRuntime::init_platform(
Some(v8::new_default_platform(0, false).make_shared()),
false,
);
});
// Create a new JsRuntime for each evaluation to avoid state issues
@@ -439,7 +432,8 @@ fn to_value_working() {
run(
"({
test: [1., 9223372036854775807n, true, false, 'hello world!']
})".into(),
})"
.into(),
&mut ctx
)
.unwrap(),