difftreelog
style fix formatting
in: master
31 files changed
crates/jrsonnet-evaluator/src/analyze.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/analyze.rs
+++ b/crates/jrsonnet-evaluator/src/analyze.rs
@@ -21,10 +21,10 @@
use jrsonnet_gcmodule::Acyclic;
use jrsonnet_interner::IStr;
use jrsonnet_ir::{
- function::FunctionSignature, ArgsDesc, AssertExpr, AssertStmt, BinaryOp, BinaryOpType,
- BindSpec, CompSpec, Destruct, Expr, ExprParams, FieldName, ForSpecData, IfElse, IfSpecData,
- ImportKind, LiteralType, NumValue, ObjBody, ObjComp, ObjMembers, Slice, SliceDesc, Span,
- Spanned, UnaryOpType, Visibility,
+ ArgsDesc, AssertExpr, AssertStmt, BinaryOp, BinaryOpType, BindSpec, CompSpec, Destruct, Expr,
+ ExprParams, FieldName, ForSpecData, IfElse, IfSpecData, ImportKind, LiteralType, NumValue,
+ ObjBody, ObjComp, ObjMembers, Slice, SliceDesc, Span, Spanned, UnaryOpType, Visibility,
+ function::FunctionSignature,
};
use rustc_hash::FxHashMap;
use smallvec::SmallVec;
crates/jrsonnet-evaluator/src/arr/mod.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/arr/mod.rs
+++ b/crates/jrsonnet-evaluator/src/arr/mod.rs
@@ -5,9 +5,9 @@
rc::Rc,
};
-use jrsonnet_gcmodule::{cc_dyn, Cc};
+use jrsonnet_gcmodule::{Cc, cc_dyn};
-use crate::{analyze::LExpr, function::NativeFn, typed::IntoUntyped, Context, Result, Thunk, Val};
+use crate::{Context, Result, Thunk, Val, analyze::LExpr, function::NativeFn, typed::IntoUntyped};
mod spec;
pub use spec::{ArrayLike, *};
crates/jrsonnet-evaluator/src/arr/spec.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/arr/spec.rs
+++ b/crates/jrsonnet-evaluator/src/arr/spec.rs
@@ -11,13 +11,13 @@
use super::ArrValue;
use crate::{
+ Context, Error, ObjValue, Result, Thunk, Val,
analyze::LExpr,
error::ErrorKind::InfiniteRecursionDetected,
evaluate::evaluate,
function::NativeFn,
typed::{IntoUntyped, Typed},
val::ThunkValue,
- Context, Error, ObjValue, Result, Thunk, Val,
};
pub trait ArrayLike: Any + Trace + Debug {
crates/jrsonnet-evaluator/src/ctx.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/ctx.rs
+++ b/crates/jrsonnet-evaluator/src/ctx.rs
@@ -4,7 +4,7 @@
use jrsonnet_gcmodule::{Cc, Trace};
use jrsonnet_interner::IStr;
-use crate::{analyze::LocalId, error, error::ErrorKind::*, Pending, Result, SupThis, Thunk, Val};
+use crate::{Pending, Result, SupThis, Thunk, Val, analyze::LocalId, error, error::ErrorKind::*};
#[derive(Debug, Trace, Clone, Educe)]
#[educe(PartialEq)]
crates/jrsonnet-evaluator/src/error.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/error.rs
+++ b/crates/jrsonnet-evaluator/src/error.rs
@@ -9,10 +9,10 @@
use thiserror::Error;
use crate::{
+ ObjValue, ResolvePathOwned,
function::{CallLocation, FunctionSignature, ParamName},
stdlib::format::FormatError,
typed::TypeLocError,
- ObjValue, ResolvePathOwned,
};
#[derive(Debug, Clone, Acyclic)]
@@ -286,11 +286,11 @@
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
- writeln!(f, "{}", self.0 .0)?;
- for el in &self.0 .1 .0 {
+ writeln!(f, "{}", self.0.0)?;
+ for el in &self.0.1.0 {
write!(f, "\t{}", el.desc)?;
if let Some(loc) = &el.location {
- write!(f, "at {}", loc.0 .0 .0)?;
+ write!(f, "at {}", loc.0.0.0)?;
loc.0.map_source_locations(&[loc.1, loc.2]);
}
writeln!(f)?;
crates/jrsonnet-evaluator/src/evaluate/compspec.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/evaluate/compspec.rs
+++ b/crates/jrsonnet-evaluator/src/evaluate/compspec.rs
@@ -7,12 +7,12 @@
evaluate_field_member_static, evaluate_field_member_unbound,
};
use crate::{
+ Context, ContextBuilder, ObjValue, ObjValueBuilder, Pending, Result, Thunk, Val,
analyze::{LArrComp, LBind, LCompSpec, LDestruct, LExpr, LFieldMember, LObjComp, LocalId},
arr::ArrValue,
bail,
error::ErrorKind::*,
evaluate::evaluate,
- Context, ContextBuilder, ObjValue, ObjValueBuilder, Pending, Result, Thunk, Val,
};
trait CompCollector {
crates/jrsonnet-evaluator/src/evaluate/destructure.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/evaluate/destructure.rs
+++ b/crates/jrsonnet-evaluator/src/evaluate/destructure.rs
@@ -3,10 +3,10 @@
use jrsonnet_gcmodule::Trace;
use crate::{
+ Context, ContextBuilder, Pending, Result, SupThis, Thunk, Unbound, Val,
analyze::{LBind, LDestruct, LDestructField, LDestructRest, LExpr, LocalId},
bail,
evaluate::evaluate,
- Context, ContextBuilder, Pending, Result, SupThis, Thunk, Unbound, Val,
};
#[allow(dead_code, reason = "not dead in exp-destruct")]
@@ -97,7 +97,7 @@
use jrsonnet_interner::IStr;
use rustc_hash::FxHashSet;
- use crate::{bail, ObjValueBuilder};
+ use crate::{ObjValueBuilder, bail};
let captured_fields: FxHashSet<IStr> = fields.iter().map(|f| f.name.clone()).collect();
let field_names: Vec<(IStr, bool)> = fields
crates/jrsonnet-evaluator/src/evaluate/mod.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/evaluate/mod.rs
+++ b/crates/jrsonnet-evaluator/src/evaluate/mod.rs
@@ -11,19 +11,20 @@
operator::evaluate_binary_op_special,
};
use crate::{
+ Context, Error, ObjValue, ObjValueBuilder, ObjectAssertion, Result, ResultExt as _, SupThis,
+ Unbound, Val,
analyze::{
LArgsDesc, LAssertStmt, LExpr, LFieldMember, LFieldName, LFunction, LIndexPart, LObjBody,
LObjMembers,
},
bail,
- error::{suggest_object_fields, ErrorKind::*},
+ error::{ErrorKind::*, suggest_object_fields},
evaluate::operator::evaluate_unary_op,
- function::{prepared::PreparedFuncVal, CallLocation, FuncDesc, FuncVal},
+ function::{CallLocation, FuncDesc, FuncVal, prepared::PreparedFuncVal},
in_frame, runtime_error,
typed::FromUntyped as _,
val::{CachedUnbound, Thunk},
- with_state, Context, Error, ObjValue, ObjValueBuilder, ObjectAssertion, Result, ResultExt as _,
- SupThis, Unbound, Val,
+ with_state,
};
pub mod compspec;
crates/jrsonnet-evaluator/src/evaluate/operator.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/evaluate/operator.rs
+++ b/crates/jrsonnet-evaluator/src/evaluate/operator.rs
@@ -3,6 +3,7 @@
use jrsonnet_ir::{BinaryOpType, UnaryOpType};
use crate::{
+ Context, Result, Val,
analyze::LExpr,
arr::ArrValue,
bail, error,
@@ -10,8 +11,7 @@
evaluate::evaluate,
stdlib::std_format,
typed::IntoUntyped as _,
- val::{equals, StrValue},
- Context, Result, Val,
+ val::{StrValue, equals},
};
pub fn evaluate_unary_op(op: UnaryOpType, b: &Val) -> Result<Val> {
crates/jrsonnet-evaluator/src/function/mod.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/function/mod.rs
+++ b/crates/jrsonnet-evaluator/src/function/mod.rs
@@ -8,13 +8,13 @@
use self::{
builtin::Builtin,
- prepared::{parse_prepared_builtin_call, PreparedCall},
+ prepared::{PreparedCall, parse_prepared_builtin_call},
};
use crate::{
+ Context, ContextBuilder, Result, Thunk, Val,
analyze::{LDestruct, LExpr, LFunction},
evaluate::{destructure::destruct, ensure_sufficient_stack, evaluate, evaluate_trivial},
function::builtin::BuiltinFunc,
- Context, ContextBuilder, Result, Thunk, Val,
};
pub mod builtin;
@@ -210,8 +210,7 @@
return false;
}
#[allow(irrefutable_let_patterns, reason = "refutable with exp-destruct")]
- let LDestruct::Full(id) = ¶m.destruct
- else {
+ let LDestruct::Full(id) = ¶m.destruct else {
return false;
};
matches!(&*desc.func.body, LExpr::Local(v) if v == id)
crates/jrsonnet-evaluator/src/function/parse.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/function/parse.rs
+++ b/crates/jrsonnet-evaluator/src/function/parse.rs
@@ -1,9 +1,9 @@
use std::rc::Rc;
use crate::{
+ Context, ContextBuilder, Result, Thunk,
analyze::LFunction,
evaluate::{destructure::destruct, evaluate},
- Context, ContextBuilder, Result, Thunk,
};
/// Creates Context with all argument default values applied
crates/jrsonnet-evaluator/src/function/prepared.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/function/prepared.rs
+++ b/crates/jrsonnet-evaluator/src/function/prepared.rs
@@ -5,10 +5,7 @@
use rustc_hash::FxHashSet;
use super::{CallLocation, FuncVal};
-use crate::{
- Result, Thunk, Val, bail,
- error::ErrorKind::*,
-};
+use crate::{Result, Thunk, Val, bail, error::ErrorKind::*};
#[derive(Debug, Trace, Clone)]
pub struct PreparedFuncVal {
crates/jrsonnet-evaluator/src/integrations/serde.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/integrations/serde.rs
+++ b/crates/jrsonnet-evaluator/src/integrations/serde.rs
@@ -3,16 +3,16 @@
use jrsonnet_interner::{IBytes, IStr};
use jrsonnet_ir::NumValue;
use serde::{
+ Deserialize, Serialize, Serializer,
de::{self, Visitor},
ser::{
Error, SerializeMap, SerializeSeq, SerializeStruct, SerializeStructVariant, SerializeTuple,
SerializeTupleStruct, SerializeTupleVariant,
},
- Deserialize, Serialize, Serializer,
};
use crate::{
- in_description_frame, runtime_error, Error as JrError, ObjValue, ObjValueBuilder, Result, Val,
+ Error as JrError, ObjValue, ObjValueBuilder, Result, Val, in_description_frame, runtime_error,
};
impl<'de> Deserialize<'de> for Val {
crates/jrsonnet-evaluator/src/lib.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/lib.rs
+++ b/crates/jrsonnet-evaluator/src/lib.rs
@@ -39,7 +39,7 @@
pub use evaluate::ensure_sufficient_stack;
use function::CallLocation;
pub use import::*;
-use jrsonnet_gcmodule::{cc_dyn, Cc, Trace};
+use jrsonnet_gcmodule::{Cc, Trace, cc_dyn};
pub use jrsonnet_interner::{IBytes, IStr};
use jrsonnet_ir::Expr;
pub use jrsonnet_ir::{NumValue, Source, SourcePath, Span};
crates/jrsonnet-evaluator/src/manifest.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/manifest.rs
+++ b/crates/jrsonnet-evaluator/src/manifest.rs
@@ -1,8 +1,7 @@
use std::{borrow::Cow, fmt::Write, hint::black_box, ptr};
use crate::{
- bail, evaluate::ensure_sufficient_stack, in_description_frame, Error,
- Result, ResultExt, Val,
+ Error, Result, ResultExt, Val, bail, evaluate::ensure_sufficient_stack, in_description_frame,
};
pub trait ManifestFormat {
crates/jrsonnet-evaluator/src/obj/mod.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/obj/mod.rs
+++ b/crates/jrsonnet-evaluator/src/obj/mod.rs
@@ -11,8 +11,8 @@
};
use educe::Educe;
-use im_rc::{vector, Vector};
-use jrsonnet_gcmodule::{cc_dyn, Acyclic, Cc, Trace, Weak};
+use im_rc::{Vector, vector};
+use jrsonnet_gcmodule::{Acyclic, Cc, Trace, Weak, cc_dyn};
use jrsonnet_interner::IStr;
use jrsonnet_ir::Span;
use rustc_hash::{FxHashMap, FxHashSet};
@@ -23,13 +23,13 @@
pub use oop::ObjValueBuilder;
use crate::{
+ CcUnbound, MaybeUnbound, Result, Thunk, Unbound, Val,
arr::{PickObjectKeyValues, PickObjectValues},
bail,
- error::{suggest_object_fields, ErrorKind::*},
+ error::{ErrorKind::*, suggest_object_fields},
evaluate::operator::evaluate_add_op,
identity_hash,
val::{ArrValue, ThunkValue},
- CcUnbound, MaybeUnbound, Result, Thunk, Unbound, Val,
};
#[cfg(not(feature = "exp-preserve-order"))]
crates/jrsonnet-evaluator/src/trace/mod.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/trace/mod.rs
+++ b/crates/jrsonnet-evaluator/src/trace/mod.rs
@@ -10,7 +10,7 @@
#[cfg(feature = "explaining-traces")]
use jrsonnet_ir::Span;
-use crate::{error::ErrorKind, Error};
+use crate::{Error, error::ErrorKind};
/// The way paths should be displayed
#[derive(Clone, Trace)]
@@ -259,7 +259,7 @@
struct ResetData {
loc: Span,
}
- use hi_doc::{source_to_ansi, Formatting, SnippetBuilder, Text};
+ use hi_doc::{Formatting, SnippetBuilder, Text, source_to_ansi};
write!(out, "{}", error.error())?;
if let ErrorKind::ImportSyntaxError { path, error } = error.error() {
@@ -277,14 +277,15 @@
use crate::analyze::DiagLevel;
let mut builder: Option<SnippetBuilder> = None;
let mut current_src: Option<&str> = None;
- let flush =
- |builder: Option<SnippetBuilder>, out: &mut dyn std::fmt::Write| -> Result<(), std::fmt::Error> {
- if let Some(b) = builder {
- let ansi = source_to_ansi(&b.build());
- write!(out, "\n{}", ansi.trim_end())?;
- }
- Ok(())
- };
+ let flush = |builder: Option<SnippetBuilder>,
+ out: &mut dyn std::fmt::Write|
+ -> Result<(), std::fmt::Error> {
+ if let Some(b) = builder {
+ let ansi = source_to_ansi(&b.build());
+ write!(out, "\n{}", ansi.trim_end())?;
+ }
+ Ok(())
+ };
for diag in diagnostics {
if let Some(span) = &diag.span {
let src = span.0.code();
@@ -295,14 +296,12 @@
}
let b = builder.as_mut().unwrap();
let ab = match diag.level {
- DiagLevel::Error => b.error(Text::fragment(
- diag.message.clone(),
- Formatting::default(),
- )),
- DiagLevel::Warning => b.warning(Text::fragment(
- diag.message.clone(),
- Formatting::default(),
- )),
+ DiagLevel::Error => {
+ b.error(Text::fragment(diag.message.clone(), Formatting::default()))
+ }
+ DiagLevel::Warning => {
+ b.warning(Text::fragment(diag.message.clone(), Formatting::default()))
+ }
};
ab.range(span.range()).build();
} else {
crates/jrsonnet-evaluator/src/val.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/val.rs
+++ b/crates/jrsonnet-evaluator/src/val.rs
@@ -17,7 +17,13 @@
pub use crate::arr::{ArrValue, ArrayLike};
use crate::{
- NumValue, ObjValue, Result, SupThis, Unbound, WeakSupThis, bail, error::{Error, ErrorKind::*}, evaluate::operator::{evaluate_compare_op, evaluate_mod_op}, function::FuncVal, gc::WithCapacityExt as _, manifest::{ManifestFormat, ToStringFormat}, typed::BoundedUsize
+ NumValue, ObjValue, Result, SupThis, Unbound, WeakSupThis, bail,
+ error::{Error, ErrorKind::*},
+ evaluate::operator::{evaluate_compare_op, evaluate_mod_op},
+ function::FuncVal,
+ gc::WithCapacityExt as _,
+ manifest::{ManifestFormat, ToStringFormat},
+ typed::BoundedUsize,
};
pub trait ThunkValue: Trace {
crates/jrsonnet-ir-parser/src/lib.rsdiffbeforeafterboth--- a/crates/jrsonnet-ir-parser/src/lib.rs
+++ b/crates/jrsonnet-ir-parser/src/lib.rs
@@ -1,11 +1,11 @@
use jrsonnet_gcmodule::Acyclic;
use jrsonnet_ir::{
- unescape, ArgsDesc, AssertExpr, AssertStmt, BinaryOp, BinaryOpType, BindSpec, CompSpec,
- Destruct, Expr, ExprParam, ExprParams, FieldMember, FieldName, ForSpecData, IStr, IfElse,
- IfSpecData, ImportKind, IndexPart, LiteralType, Member, NumValue, ObjBody, ObjComp, ObjMembers,
- Slice, SliceDesc, Source, Span, Spanned, UnaryOpType, Visibility,
+ ArgsDesc, AssertExpr, AssertStmt, BinaryOp, BinaryOpType, BindSpec, CompSpec, Destruct, Expr,
+ ExprParam, ExprParams, FieldMember, FieldName, ForSpecData, IStr, IfElse, IfSpecData,
+ ImportKind, IndexPart, LiteralType, Member, NumValue, ObjBody, ObjComp, ObjMembers, Slice,
+ SliceDesc, Source, Span, Spanned, UnaryOpType, Visibility, unescape,
};
-use jrsonnet_lexer::{collect_lexed_str_block, Lexeme, Lexer, Span as LexSpan, SyntaxKind, T};
+use jrsonnet_lexer::{Lexeme, Lexer, Span as LexSpan, SyntaxKind, T, collect_lexed_str_block};
pub struct ParserSettings {
pub source: Source,
crates/jrsonnet-ir/src/expr.rsdiffbeforeafterboth--- a/crates/jrsonnet-ir/src/expr.rs
+++ b/crates/jrsonnet-ir/src/expr.rs
@@ -7,9 +7,9 @@
use jrsonnet_interner::IStr;
use crate::{
+ NumValue,
function::{FunctionSignature, ParamDefault, ParamName, ParamParse},
source::Source,
- NumValue,
};
#[derive(Debug, PartialEq, Acyclic)]
crates/jrsonnet-macros/src/lib.rsdiffbeforeafterboth--- a/crates/jrsonnet-macros/src/lib.rs
+++ b/crates/jrsonnet-macros/src/lib.rs
@@ -3,14 +3,13 @@
use proc_macro2::TokenStream;
use quote::{quote, quote_spanned};
use syn::{
- parenthesized,
+ Attribute, DeriveInput, Error, Expr, ExprClosure, FnArg, GenericArgument, Ident, ItemFn,
+ LitStr, Meta, Pat, Path, PathArguments, Result, ReturnType, Token, Type, parenthesized,
parse::{Parse, ParseStream},
parse_macro_input,
punctuated::Punctuated,
spanned::Spanned,
token::Comma,
- Attribute, DeriveInput, Error, Expr, ExprClosure, FnArg, GenericArgument, Ident, ItemFn,
- LitStr, Meta, Pat, Path, PathArguments, Result, ReturnType, Token, Type,
};
use self::typed::{derive_from_untyped_inner, derive_into_untyped_inner, derive_typed_inner};
crates/jrsonnet-stdlib/src/arrays.rsdiffbeforeafterboth1#![allow(non_snake_case)]23use jrsonnet_evaluator::{4 bail, error,5 function::{builtin, NativeFn},6 runtime_error,7 typed::{BoundedUsize, Either2, FromUntyped},8 val::{equals, ArrValue, IndexableVal},9 Either, IStr, ObjValue, ObjValueBuilder, Result, ResultExt, Thunk, Val,10};1112pub fn eval_on_empty(on_empty: Option<Thunk<Val>>) -> Result<Val> {13 if let Some(on_empty) = on_empty {14 on_empty.evaluate()15 } else {16 bail!("expected non-empty array")17 }18}1920#[builtin]21pub fn builtin_make_array(sz: u32, func: NativeFn!((u32,) -> Val)) -> Result<ArrValue> {22 if sz == 0 {23 return Ok(ArrValue::empty());24 }25 // Try eager evaluation: call func(i) immediately for each element.26 'eager: {27 let mut out = Vec::with_capacity(sz as usize);28 for i in 0..sz {29 match func.call(i) {30 Ok(v) => out.push(v),31 Err(_) => break 'eager,32 }33 }34 return Ok(ArrValue::new(out));35 }36 Ok(ArrValue::make(sz, func))37}3839#[builtin]40pub fn builtin_repeat(what: Either![IStr, ArrValue], count: u32) -> Result<Val> {41 Ok(match what {42 Either2::A(s) => Val::string(s.repeat(count as usize)),43 Either2::B(arr) => Val::Arr(44 ArrValue::repeated(arr, count)45 .ok_or_else(|| runtime_error!("repeated length overflow"))?,46 ),47 })48}4950#[builtin]51pub fn builtin_slice(52 indexable: IndexableVal,53 index: Option<Option<i32>>,54 end: Option<Option<i32>>,55 step: Option<Option<BoundedUsize<1, { i32::MAX as usize }>>>,56) -> Result<Val> {57 indexable58 .slice(index.flatten(), end.flatten(), step.flatten())59 .map(Val::from)60}6162#[builtin]63pub fn builtin_map(func: NativeFn!((Val) -> Val), arr: IndexableVal) -> ArrValue {64 let arr = arr.to_array();65 arr.map(func)66}6768#[builtin]69pub fn builtin_map_with_index(func: NativeFn!((u32, Val) -> Val), arr: IndexableVal) -> ArrValue {70 let arr = arr.to_array();71 arr.map_with_index(func)72}7374#[builtin]75pub fn builtin_map_with_key(76 func: NativeFn!((IStr, Val) -> Val),77 obj: ObjValue,78) -> Result<ObjValue> {79 let mut out = ObjValueBuilder::new();80 for (k, v) in obj.iter(81 // Makes sense mapped object should be ordered the same way, should not break anything when the output is not ordered (the default).82 // The thrown error might be different, but jsonnet83 // does not specify the evaluation order.84 #[cfg(feature = "exp-preserve-order")]85 true,86 ) {87 let v = v?;88 out.field(k.clone()).value(func.call(k, v)?);89 }90 Ok(out.build())91}9293#[builtin]94pub fn builtin_flatmap(95 func: NativeFn!((Either![String, Val]) -> Val),96 arr: IndexableVal,97) -> Result<IndexableVal> {98 use std::fmt::Write;99 match arr {100 IndexableVal::Str(str) => {101 let mut out = String::new();102 for c in str.chars() {103 match func.call(Either2::A(c.to_string()))? {104 Val::Str(o) => write!(out, "{o}").unwrap(),105 Val::Null => {}106 _ => bail!("in std.join all items should be strings"),107 }108 }109 Ok(IndexableVal::Str(out.into()))110 }111 IndexableVal::Arr(a) => {112 let mut out = Vec::new();113 for el in a.iter() {114 let el = el?;115 match func.call(Either2::B(el))? {116 Val::Arr(o) => {117 for oe in o.iter() {118 out.push(oe?);119 }120 }121 Val::Null => {}122 _ => bail!("in std.join all items should be arrays"),123 }124 }125 Ok(IndexableVal::Arr(out.into()))126 }127 }128}129130type FilterFunc = NativeFn!((Thunk<Val>) -> bool);131132#[builtin]133pub fn builtin_filter(func: FilterFunc, arr: ArrValue) -> Result<ArrValue> {134 arr.filter(func)135}136137#[builtin]138pub fn builtin_filter_map(139 filter_func: FilterFunc,140 map_func: NativeFn!((Val) -> Val),141 arr: ArrValue,142) -> Result<ArrValue> {143 Ok(arr.filter(filter_func)?.map(map_func))144}145146#[builtin]147pub fn builtin_foldl(148 func: NativeFn!((Val, Either![Val, char]) -> Val),149 arr: Either![ArrValue, IStr],150 init: Val,151) -> Result<Val> {152 let mut acc = init;153 match arr {154 Either2::A(arr) => {155 for i in arr.iter() {156 acc = func.call(acc, Either2::A(i?))?;157 }158 }159 Either2::B(arr) => {160 for c in arr.chars() {161 acc = func.call(acc, Either2::B(c))?;162 }163 }164 }165 Ok(acc)166}167168#[builtin]169pub fn builtin_foldr(170 func: NativeFn!((Either![Val, char], Val) -> Val),171 arr: Either![ArrValue, IStr],172 init: Val,173) -> Result<Val> {174 let mut acc = init;175 match arr {176 Either2::A(arr) => {177 for i in arr.iter().rev() {178 acc = func.call(Either2::A(i?), acc)?;179 }180 }181 Either2::B(arr) => {182 for c in arr.chars().rev() {183 acc = func.call(Either2::B(c), acc)?;184 }185 }186 }187 Ok(acc)188}189190#[builtin]191pub fn builtin_range(from: i32, to: i32) -> Result<ArrValue> {192 if to < from {193 return Ok(ArrValue::empty());194 }195 Ok(ArrValue::range_inclusive(from, to))196}197198#[builtin]199pub fn builtin_join(sep: IndexableVal, arr: ArrValue) -> Result<IndexableVal> {200 use std::fmt::Write;201 Ok(match sep {202 IndexableVal::Arr(joiner_items) => {203 let mut out = Vec::new();204205 let mut first = true;206 for item in arr.iter() {207 let item = item?.clone();208 if let Val::Arr(items) = item {209 if !first {210 out.reserve(joiner_items.len() as usize);211 // TODO: extend212 for item in joiner_items.iter() {213 out.push(item?);214 }215 }216 first = false;217 out.reserve(items.len() as usize);218 for item in items.iter() {219 out.push(item?);220 }221 } else if matches!(item, Val::Null) {222 } else {223 bail!("in std.join all items should be arrays");224 }225 }226227 IndexableVal::Arr(out.into())228 }229 IndexableVal::Str(sep) => {230 let mut out = String::new();231232 let mut first = true;233 for item in arr.iter() {234 let item = item?.clone();235 if let Val::Str(item) = item {236 if !first {237 out += &sep;238 }239 first = false;240 write!(out, "{item}").unwrap();241 } else if matches!(item, Val::Null) {242 } else {243 bail!("in std.join all items should be strings");244 }245 }246247 IndexableVal::Str(out.into())248 }249 })250}251252#[builtin]253pub fn builtin_lines(arr: ArrValue) -> Result<IndexableVal> {254 builtin_join(255 IndexableVal::Str("\n".into()),256 ArrValue::extended(arr, ArrValue::new(vec![Val::string("")]))257 .ok_or_else(|| error!("array is too large"))?,258 )259}260261#[builtin]262pub fn builtin_resolve_path(f: String, r: String) -> String {263 let Some(pos) = f.rfind('/') else {264 return r;265 };266 format!("{}{}", &f[..=pos], r)267}268269pub fn deep_join_inner(out: &mut String, arr: IndexableVal) -> Result<()> {270 use std::fmt::Write;271 match arr {272 IndexableVal::Str(s) => write!(out, "{s}").expect("no error"),273 IndexableVal::Arr(arr) => {274 for ele in arr.iter() {275 let indexable = IndexableVal::from_untyped(ele?)?;276 deep_join_inner(out, indexable)?;277 }278 }279 }280 Ok(())281}282283#[builtin]284pub fn builtin_deep_join(arr: IndexableVal) -> Result<String> {285 let mut out = String::new();286 deep_join_inner(&mut out, arr)?;287 Ok(out)288}289290#[builtin]291pub fn builtin_reverse(arr: ArrValue) -> ArrValue {292 arr.reversed()293}294295#[builtin]296pub fn builtin_any(arr: ArrValue) -> Result<bool> {297 for v in arr.iter() {298 let v = bool::from_untyped(v?)?;299 if v {300 return Ok(true);301 }302 }303 Ok(false)304}305306#[builtin]307pub fn builtin_all(arr: ArrValue) -> Result<bool> {308 for v in arr.iter() {309 let v = bool::from_untyped(v?)?;310 if !v {311 return Ok(false);312 }313 }314 Ok(true)315}316317#[builtin]318pub fn builtin_member(arr: IndexableVal, x: Val) -> Result<bool> {319 match arr {320 IndexableVal::Str(str) => {321 let x: IStr = IStr::from_untyped(x)?;322 Ok(!x.is_empty() && str.contains(&*x))323 }324 IndexableVal::Arr(a) => {325 for item in a.iter() {326 let item = item?;327 if equals(&item, &x)? {328 return Ok(true);329 }330 }331 Ok(false)332 }333 }334}335336#[builtin]337pub fn builtin_find(value: Val, arr: ArrValue) -> Result<Vec<usize>> {338 let mut out = Vec::new();339 for (i, ele) in arr.iter().enumerate() {340 let ele = ele?;341 if equals(&ele, &value)? {342 out.push(i);343 }344 }345 Ok(out)346}347348#[builtin]349pub fn builtin_contains(arr: IndexableVal, elem: Val) -> Result<bool> {350 builtin_member(arr, elem)351}352353#[builtin]354pub fn builtin_count(arr: ArrValue, x: Val) -> Result<usize> {355 let mut count = 0;356 for item in arr.iter() {357 if equals(&item?, &x)? {358 count += 1;359 }360 }361 Ok(count)362}363364#[builtin]365pub fn builtin_avg(arr: Vec<f64>, onEmpty: Option<Thunk<Val>>) -> Result<Val> {366 if arr.is_empty() {367 return eval_on_empty(onEmpty);368 }369 #[expect(370 clippy::cast_precision_loss,371 reason = "array sizes are bounded to i32 len"372 )]373 Ok(Val::try_num(arr.iter().sum::<f64>() / (arr.len() as f64))?)374}375376#[builtin]377pub fn builtin_remove_at(arr: ArrValue, at: i32) -> Result<ArrValue> {378 let newArrLeft = arr.clone().slice(None, Some(at), None);379 let newArrRight = arr.slice(Some(at + 1), None, None);380381 Ok(ArrValue::extended(newArrLeft, newArrRight).ok_or_else(|| error!("array is too large"))?)382}383384#[builtin]385pub fn builtin_remove(arr: ArrValue, elem: Val) -> Result<ArrValue> {386 for (index, item) in arr.iter().enumerate() {387 if equals(&item?, &elem)? {388 #[expect(389 clippy::cast_possible_truncation,390 clippy::cast_possible_wrap,391 reason = "array sizes are bounded to i32 len"392 )]393 return builtin_remove_at(arr.clone(), index as i32);394 }395 }396 Ok(arr)397}398399#[builtin]400pub fn builtin_flatten_arrays(arrs: Vec<ArrValue>) -> Result<ArrValue> {401 pub fn flatten_inner(values: &[ArrValue]) -> Result<ArrValue> {402 if values.len() == 1 {403 return Ok(values[0].clone());404 } else if values.len() == 2 {405 return ArrValue::extended(values[0].clone(), values[1].clone())406 .ok_or_else(|| error!("array is too large"));407 }408 let (a, b) = values.split_at(values.len() / 2);409 ArrValue::extended(flatten_inner(a)?, flatten_inner(b)?)410 .ok_or_else(|| error!("array is too large"))411 }412 if arrs.is_empty() {413 return Ok(ArrValue::empty());414 } else if arrs.len() == 1 {415 return Ok(arrs.into_iter().next().expect("single"));416 }417 flatten_inner(&arrs)418}419420#[builtin]421pub fn builtin_flatten_deep_array(value: Val) -> Result<Vec<Val>> {422 fn process(value: Val, out: &mut Vec<Val>) -> Result<()> {423 match value {424 Val::Arr(arr) => {425 for ele in arr.iter() {426 process(ele?, out)?;427 }428 }429 _ => out.push(value),430 }431 Ok(())432 }433 let mut out = Vec::new();434 process(value, &mut out)?;435 Ok(out)436}437438#[builtin]439pub fn builtin_prune(440 a: Val,441442 #[default(false)]443 #[cfg(feature = "exp-preserve-order")]444 preserve_order: bool,445) -> Result<Val> {446 fn is_content(val: &Val) -> bool {447 match val {448 Val::Null => false,449 Val::Arr(a) => !a.is_empty(),450 Val::Obj(o) => !o.is_empty(),451 _ => true,452 }453 }454 Ok(match a {455 Val::Arr(a) => {456 let mut out = Vec::new();457 for (i, ele) in a.iter().enumerate() {458 let ele = ele459 .and_then(|v| {460 builtin_prune(461 v,462 #[cfg(feature = "exp-preserve-order")]463 preserve_order,464 )465 })466 .with_description(|| format!("elem <{i}> pruning"))?;467 if is_content(&ele) {468 out.push(ele);469 }470 }471 Val::arr(out)472 }473 Val::Obj(o) => {474 let mut out = ObjValueBuilder::new();475 for (name, value) in o.iter(476 #[cfg(feature = "exp-preserve-order")]477 preserve_order,478 ) {479 let value = value480 .and_then(|v| {481 builtin_prune(482 v,483 #[cfg(feature = "exp-preserve-order")]484 preserve_order,485 )486 })487 .with_description(|| format!("field <{name}> pruning"))?;488 if !is_content(&value) {489 continue;490 }491 out.field(name).value(value);492 }493 Val::Obj(out.build())494 }495 _ => a,496 })497}1#![allow(non_snake_case)]23use jrsonnet_evaluator::{4 Either, IStr, ObjValue, ObjValueBuilder, Result, ResultExt, Thunk, Val, bail, error,5 function::{NativeFn, builtin},6 runtime_error,7 typed::{BoundedUsize, Either2, FromUntyped},8 val::{ArrValue, IndexableVal, equals},9};1011pub fn eval_on_empty(on_empty: Option<Thunk<Val>>) -> Result<Val> {12 if let Some(on_empty) = on_empty {13 on_empty.evaluate()14 } else {15 bail!("expected non-empty array")16 }17}1819#[builtin]20pub fn builtin_make_array(sz: u32, func: NativeFn!((u32,) -> Val)) -> Result<ArrValue> {21 if sz == 0 {22 return Ok(ArrValue::empty());23 }24 // Try eager evaluation: call func(i) immediately for each element.25 'eager: {26 let mut out = Vec::with_capacity(sz as usize);27 for i in 0..sz {28 match func.call(i) {29 Ok(v) => out.push(v),30 Err(_) => break 'eager,31 }32 }33 return Ok(ArrValue::new(out));34 }35 Ok(ArrValue::make(sz, func))36}3738#[builtin]39pub fn builtin_repeat(what: Either![IStr, ArrValue], count: u32) -> Result<Val> {40 Ok(match what {41 Either2::A(s) => Val::string(s.repeat(count as usize)),42 Either2::B(arr) => Val::Arr(43 ArrValue::repeated(arr, count)44 .ok_or_else(|| runtime_error!("repeated length overflow"))?,45 ),46 })47}4849#[builtin]50pub fn builtin_slice(51 indexable: IndexableVal,52 index: Option<Option<i32>>,53 end: Option<Option<i32>>,54 step: Option<Option<BoundedUsize<1, { i32::MAX as usize }>>>,55) -> Result<Val> {56 indexable57 .slice(index.flatten(), end.flatten(), step.flatten())58 .map(Val::from)59}6061#[builtin]62pub fn builtin_map(func: NativeFn!((Val) -> Val), arr: IndexableVal) -> ArrValue {63 let arr = arr.to_array();64 arr.map(func)65}6667#[builtin]68pub fn builtin_map_with_index(func: NativeFn!((u32, Val) -> Val), arr: IndexableVal) -> ArrValue {69 let arr = arr.to_array();70 arr.map_with_index(func)71}7273#[builtin]74pub fn builtin_map_with_key(75 func: NativeFn!((IStr, Val) -> Val),76 obj: ObjValue,77) -> Result<ObjValue> {78 let mut out = ObjValueBuilder::new();79 for (k, v) in obj.iter(80 // Makes sense mapped object should be ordered the same way, should not break anything when the output is not ordered (the default).81 // The thrown error might be different, but jsonnet82 // does not specify the evaluation order.83 #[cfg(feature = "exp-preserve-order")]84 true,85 ) {86 let v = v?;87 out.field(k.clone()).value(func.call(k, v)?);88 }89 Ok(out.build())90}9192#[builtin]93pub fn builtin_flatmap(94 func: NativeFn!((Either![String, Val]) -> Val),95 arr: IndexableVal,96) -> Result<IndexableVal> {97 use std::fmt::Write;98 match arr {99 IndexableVal::Str(str) => {100 let mut out = String::new();101 for c in str.chars() {102 match func.call(Either2::A(c.to_string()))? {103 Val::Str(o) => write!(out, "{o}").unwrap(),104 Val::Null => {}105 _ => bail!("in std.join all items should be strings"),106 }107 }108 Ok(IndexableVal::Str(out.into()))109 }110 IndexableVal::Arr(a) => {111 let mut out = Vec::new();112 for el in a.iter() {113 let el = el?;114 match func.call(Either2::B(el))? {115 Val::Arr(o) => {116 for oe in o.iter() {117 out.push(oe?);118 }119 }120 Val::Null => {}121 _ => bail!("in std.join all items should be arrays"),122 }123 }124 Ok(IndexableVal::Arr(out.into()))125 }126 }127}128129type FilterFunc = NativeFn!((Thunk<Val>) -> bool);130131#[builtin]132pub fn builtin_filter(func: FilterFunc, arr: ArrValue) -> Result<ArrValue> {133 arr.filter(func)134}135136#[builtin]137pub fn builtin_filter_map(138 filter_func: FilterFunc,139 map_func: NativeFn!((Val) -> Val),140 arr: ArrValue,141) -> Result<ArrValue> {142 Ok(arr.filter(filter_func)?.map(map_func))143}144145#[builtin]146pub fn builtin_foldl(147 func: NativeFn!((Val, Either![Val, char]) -> Val),148 arr: Either![ArrValue, IStr],149 init: Val,150) -> Result<Val> {151 let mut acc = init;152 match arr {153 Either2::A(arr) => {154 for i in arr.iter() {155 acc = func.call(acc, Either2::A(i?))?;156 }157 }158 Either2::B(arr) => {159 for c in arr.chars() {160 acc = func.call(acc, Either2::B(c))?;161 }162 }163 }164 Ok(acc)165}166167#[builtin]168pub fn builtin_foldr(169 func: NativeFn!((Either![Val, char], Val) -> Val),170 arr: Either![ArrValue, IStr],171 init: Val,172) -> Result<Val> {173 let mut acc = init;174 match arr {175 Either2::A(arr) => {176 for i in arr.iter().rev() {177 acc = func.call(Either2::A(i?), acc)?;178 }179 }180 Either2::B(arr) => {181 for c in arr.chars().rev() {182 acc = func.call(Either2::B(c), acc)?;183 }184 }185 }186 Ok(acc)187}188189#[builtin]190pub fn builtin_range(from: i32, to: i32) -> Result<ArrValue> {191 if to < from {192 return Ok(ArrValue::empty());193 }194 Ok(ArrValue::range_inclusive(from, to))195}196197#[builtin]198pub fn builtin_join(sep: IndexableVal, arr: ArrValue) -> Result<IndexableVal> {199 use std::fmt::Write;200 Ok(match sep {201 IndexableVal::Arr(joiner_items) => {202 let mut out = Vec::new();203204 let mut first = true;205 for item in arr.iter() {206 let item = item?.clone();207 if let Val::Arr(items) = item {208 if !first {209 out.reserve(joiner_items.len() as usize);210 // TODO: extend211 for item in joiner_items.iter() {212 out.push(item?);213 }214 }215 first = false;216 out.reserve(items.len() as usize);217 for item in items.iter() {218 out.push(item?);219 }220 } else if matches!(item, Val::Null) {221 } else {222 bail!("in std.join all items should be arrays");223 }224 }225226 IndexableVal::Arr(out.into())227 }228 IndexableVal::Str(sep) => {229 let mut out = String::new();230231 let mut first = true;232 for item in arr.iter() {233 let item = item?.clone();234 if let Val::Str(item) = item {235 if !first {236 out += &sep;237 }238 first = false;239 write!(out, "{item}").unwrap();240 } else if matches!(item, Val::Null) {241 } else {242 bail!("in std.join all items should be strings");243 }244 }245246 IndexableVal::Str(out.into())247 }248 })249}250251#[builtin]252pub fn builtin_lines(arr: ArrValue) -> Result<IndexableVal> {253 builtin_join(254 IndexableVal::Str("\n".into()),255 ArrValue::extended(arr, ArrValue::new(vec![Val::string("")]))256 .ok_or_else(|| error!("array is too large"))?,257 )258}259260#[builtin]261pub fn builtin_resolve_path(f: String, r: String) -> String {262 let Some(pos) = f.rfind('/') else {263 return r;264 };265 format!("{}{}", &f[..=pos], r)266}267268pub fn deep_join_inner(out: &mut String, arr: IndexableVal) -> Result<()> {269 use std::fmt::Write;270 match arr {271 IndexableVal::Str(s) => write!(out, "{s}").expect("no error"),272 IndexableVal::Arr(arr) => {273 for ele in arr.iter() {274 let indexable = IndexableVal::from_untyped(ele?)?;275 deep_join_inner(out, indexable)?;276 }277 }278 }279 Ok(())280}281282#[builtin]283pub fn builtin_deep_join(arr: IndexableVal) -> Result<String> {284 let mut out = String::new();285 deep_join_inner(&mut out, arr)?;286 Ok(out)287}288289#[builtin]290pub fn builtin_reverse(arr: ArrValue) -> ArrValue {291 arr.reversed()292}293294#[builtin]295pub fn builtin_any(arr: ArrValue) -> Result<bool> {296 for v in arr.iter() {297 let v = bool::from_untyped(v?)?;298 if v {299 return Ok(true);300 }301 }302 Ok(false)303}304305#[builtin]306pub fn builtin_all(arr: ArrValue) -> Result<bool> {307 for v in arr.iter() {308 let v = bool::from_untyped(v?)?;309 if !v {310 return Ok(false);311 }312 }313 Ok(true)314}315316#[builtin]317pub fn builtin_member(arr: IndexableVal, x: Val) -> Result<bool> {318 match arr {319 IndexableVal::Str(str) => {320 let x: IStr = IStr::from_untyped(x)?;321 Ok(!x.is_empty() && str.contains(&*x))322 }323 IndexableVal::Arr(a) => {324 for item in a.iter() {325 let item = item?;326 if equals(&item, &x)? {327 return Ok(true);328 }329 }330 Ok(false)331 }332 }333}334335#[builtin]336pub fn builtin_find(value: Val, arr: ArrValue) -> Result<Vec<usize>> {337 let mut out = Vec::new();338 for (i, ele) in arr.iter().enumerate() {339 let ele = ele?;340 if equals(&ele, &value)? {341 out.push(i);342 }343 }344 Ok(out)345}346347#[builtin]348pub fn builtin_contains(arr: IndexableVal, elem: Val) -> Result<bool> {349 builtin_member(arr, elem)350}351352#[builtin]353pub fn builtin_count(arr: ArrValue, x: Val) -> Result<usize> {354 let mut count = 0;355 for item in arr.iter() {356 if equals(&item?, &x)? {357 count += 1;358 }359 }360 Ok(count)361}362363#[builtin]364pub fn builtin_avg(arr: Vec<f64>, onEmpty: Option<Thunk<Val>>) -> Result<Val> {365 if arr.is_empty() {366 return eval_on_empty(onEmpty);367 }368 #[expect(369 clippy::cast_precision_loss,370 reason = "array sizes are bounded to i32 len"371 )]372 Ok(Val::try_num(arr.iter().sum::<f64>() / (arr.len() as f64))?)373}374375#[builtin]376pub fn builtin_remove_at(arr: ArrValue, at: i32) -> Result<ArrValue> {377 let newArrLeft = arr.clone().slice(None, Some(at), None);378 let newArrRight = arr.slice(Some(at + 1), None, None);379380 Ok(ArrValue::extended(newArrLeft, newArrRight).ok_or_else(|| error!("array is too large"))?)381}382383#[builtin]384pub fn builtin_remove(arr: ArrValue, elem: Val) -> Result<ArrValue> {385 for (index, item) in arr.iter().enumerate() {386 if equals(&item?, &elem)? {387 #[expect(388 clippy::cast_possible_truncation,389 clippy::cast_possible_wrap,390 reason = "array sizes are bounded to i32 len"391 )]392 return builtin_remove_at(arr.clone(), index as i32);393 }394 }395 Ok(arr)396}397398#[builtin]399pub fn builtin_flatten_arrays(arrs: Vec<ArrValue>) -> Result<ArrValue> {400 pub fn flatten_inner(values: &[ArrValue]) -> Result<ArrValue> {401 if values.len() == 1 {402 return Ok(values[0].clone());403 } else if values.len() == 2 {404 return ArrValue::extended(values[0].clone(), values[1].clone())405 .ok_or_else(|| error!("array is too large"));406 }407 let (a, b) = values.split_at(values.len() / 2);408 ArrValue::extended(flatten_inner(a)?, flatten_inner(b)?)409 .ok_or_else(|| error!("array is too large"))410 }411 if arrs.is_empty() {412 return Ok(ArrValue::empty());413 } else if arrs.len() == 1 {414 return Ok(arrs.into_iter().next().expect("single"));415 }416 flatten_inner(&arrs)417}418419#[builtin]420pub fn builtin_flatten_deep_array(value: Val) -> Result<Vec<Val>> {421 fn process(value: Val, out: &mut Vec<Val>) -> Result<()> {422 match value {423 Val::Arr(arr) => {424 for ele in arr.iter() {425 process(ele?, out)?;426 }427 }428 _ => out.push(value),429 }430 Ok(())431 }432 let mut out = Vec::new();433 process(value, &mut out)?;434 Ok(out)435}436437#[builtin]438pub fn builtin_prune(439 a: Val,440441 #[default(false)]442 #[cfg(feature = "exp-preserve-order")]443 preserve_order: bool,444) -> Result<Val> {445 fn is_content(val: &Val) -> bool {446 match val {447 Val::Null => false,448 Val::Arr(a) => !a.is_empty(),449 Val::Obj(o) => !o.is_empty(),450 _ => true,451 }452 }453 Ok(match a {454 Val::Arr(a) => {455 let mut out = Vec::new();456 for (i, ele) in a.iter().enumerate() {457 let ele = ele458 .and_then(|v| {459 builtin_prune(460 v,461 #[cfg(feature = "exp-preserve-order")]462 preserve_order,463 )464 })465 .with_description(|| format!("elem <{i}> pruning"))?;466 if is_content(&ele) {467 out.push(ele);468 }469 }470 Val::arr(out)471 }472 Val::Obj(o) => {473 let mut out = ObjValueBuilder::new();474 for (name, value) in o.iter(475 #[cfg(feature = "exp-preserve-order")]476 preserve_order,477 ) {478 let value = value479 .and_then(|v| {480 builtin_prune(481 v,482 #[cfg(feature = "exp-preserve-order")]483 preserve_order,484 )485 })486 .with_description(|| format!("field <{name}> pruning"))?;487 if !is_content(&value) {488 continue;489 }490 out.field(name).value(value);491 }492 Val::Obj(out.build())493 }494 _ => a,495 })496}crates/jrsonnet-stdlib/src/compat.rsdiffbeforeafterboth--- a/crates/jrsonnet-stdlib/src/compat.rs
+++ b/crates/jrsonnet-stdlib/src/compat.rs
@@ -1,6 +1,6 @@
use std::cmp::Ordering;
-use jrsonnet_evaluator::{function::builtin, val::ArrValue, Result, Val};
+use jrsonnet_evaluator::{Result, Val, function::builtin, val::ArrValue};
#[builtin]
#[allow(non_snake_case)]
crates/jrsonnet-stdlib/src/lib.rsdiffbeforeafterboth--- a/crates/jrsonnet-stdlib/src/lib.rs
+++ b/crates/jrsonnet-stdlib/src/lib.rs
@@ -12,7 +12,12 @@
pub use encoding::*;
pub use hash::*;
use jrsonnet_evaluator::{
- IStr, InitialContextBuilder, NumValue, ObjValue, ObjValueBuilder, Source, Thunk, Val, error::Result, function::{CallLocation, FuncVal, builtin_id}, tla::TlaArg, trace::PathResolver, typed::SerializeTypedObj as _
+ IStr, InitialContextBuilder, NumValue, ObjValue, ObjValueBuilder, Source, Thunk, Val,
+ error::Result,
+ function::{CallLocation, FuncVal, builtin_id},
+ tla::TlaArg,
+ trace::PathResolver,
+ typed::SerializeTypedObj as _,
};
use jrsonnet_gcmodule::{Acyclic, Cc, Trace};
use jrsonnet_macros::{IntoUntyped, Typed};
crates/jrsonnet-stdlib/src/manifest/toml.rsdiffbeforeafterboth--- a/crates/jrsonnet-stdlib/src/manifest/toml.rs
+++ b/crates/jrsonnet-stdlib/src/manifest/toml.rs
@@ -1,7 +1,10 @@
use std::borrow::Cow;
use jrsonnet_evaluator::{
- Error, IStr, ObjValue, Result, ResultExt, Val, bail, ensure_sufficient_stack, in_description_frame, manifest::{ManifestFormat, escape_string_json_buf}, val::ArrValue
+ Error, IStr, ObjValue, Result, ResultExt, Val, bail, ensure_sufficient_stack,
+ in_description_frame,
+ manifest::{ManifestFormat, escape_string_json_buf},
+ val::ArrValue,
};
pub struct TomlFormat<'s> {
@@ -218,14 +221,16 @@
}
first = false;
path.push(k.clone());
- ensure_sufficient_stack(|| in_description_frame(
- || format!("section <{k}> manifestification"),
- || match v {
- Val::Obj(obj) => manifest_table(&obj, path, buf, cur_padding, options),
- Val::Arr(arr) => manifest_table_array(&arr, path, buf, cur_padding, options),
- _ => unreachable!("iterating over sections"),
- },
- ))?;
+ ensure_sufficient_stack(|| {
+ in_description_frame(
+ || format!("section <{k}> manifestification"),
+ || match v {
+ Val::Obj(obj) => manifest_table(&obj, path, buf, cur_padding, options),
+ Val::Arr(arr) => manifest_table_array(&arr, path, buf, cur_padding, options),
+ _ => unreachable!("iterating over sections"),
+ },
+ )
+ })?;
path.pop();
}
Ok(())
crates/jrsonnet-stdlib/src/misc.rsdiffbeforeafterboth--- a/crates/jrsonnet-stdlib/src/misc.rs
+++ b/crates/jrsonnet-stdlib/src/misc.rs
@@ -1,13 +1,12 @@
use std::{cell::RefCell, collections::BTreeSet};
use jrsonnet_evaluator::{
- bail,
+ Either, IStr, ObjValue, ObjValueBuilder, ResultExt, Thunk, Val, bail,
error::{ErrorKind::*, Result},
- function::{builtin, CallLocation, FuncVal},
+ function::{CallLocation, FuncVal, builtin},
manifest::JsonFormat,
typed::{Either2, Either4},
- val::{equals, ArrValue},
- Either, IStr, ObjValue, ObjValueBuilder, ResultExt, Thunk, Val,
+ val::{ArrValue, equals},
};
use jrsonnet_gcmodule::Cc;
crates/jrsonnet-stdlib/src/operator.rsdiffbeforeafterboth--- a/crates/jrsonnet-stdlib/src/operator.rs
+++ b/crates/jrsonnet-stdlib/src/operator.rs
@@ -2,11 +2,11 @@
//! However, in our case we instead implement them in native, and implement native functions on top of core for backwards compatibility
use jrsonnet_evaluator::{
+ IStr, NumValue, Result, Val,
function::builtin,
stdlib::std_format,
typed::{Either, Either2},
val::{equals, primitive_equals},
- IStr, NumValue, Result, Val,
};
#[builtin]
crates/jrsonnet-stdlib/src/sets.rsdiffbeforeafterboth--- a/crates/jrsonnet-stdlib/src/sets.rs
+++ b/crates/jrsonnet-stdlib/src/sets.rs
@@ -1,6 +1,6 @@
use std::cmp::Ordering;
-use jrsonnet_evaluator::{function::builtin, val::ArrValue, Result, Thunk, Val};
+use jrsonnet_evaluator::{Result, Thunk, Val, function::builtin, val::ArrValue};
use crate::keyf::KeyF;
crates/jrsonnet-stdlib/src/sort.rsdiffbeforeafterboth--- a/crates/jrsonnet-stdlib/src/sort.rs
+++ b/crates/jrsonnet-stdlib/src/sort.rs
@@ -3,10 +3,9 @@
use std::cmp::Ordering;
use jrsonnet_evaluator::{
- bail,
+ Result, Thunk, Val, bail,
function::builtin,
- val::{equals, ArrValue},
- Result, Thunk, Val,
+ val::{ArrValue, equals},
};
use crate::{eval_on_empty, keyf::KeyF};
tests/tests/builtin.rsdiffbeforeafterboth--- a/tests/tests/builtin.rs
+++ b/tests/tests/builtin.rs
@@ -1,7 +1,11 @@
mod common;
use jrsonnet_evaluator::{
- ContextInitializer, FileImportResolver, InitialContextBuilder, Result, Source, State, Thunk, Val, function::{CallLocation, FuncVal, builtin, builtin::{Builtin}}, trace::PathResolver, typed::FromUntyped
+ ContextInitializer, FileImportResolver, InitialContextBuilder, Result, Source, State, Thunk,
+ Val,
+ function::{CallLocation, FuncVal, builtin, builtin::Builtin},
+ trace::PathResolver,
+ typed::FromUntyped,
};
use jrsonnet_gcmodule::Trace;
use jrsonnet_stdlib::ContextInitializer as StdContextInitializer;
tests/tests/common.rsdiffbeforeafterboth--- a/tests/tests/common.rs
+++ b/tests/tests/common.rs
@@ -1,5 +1,7 @@
use jrsonnet_evaluator::{
- ContextBuilder, ContextInitializer as ContextInitializerT, InitialContextBuilder, ObjValueBuilder, Result, Thunk, Val, bail, function::{FuncVal, builtin}, Source
+ ContextBuilder, ContextInitializer as ContextInitializerT, InitialContextBuilder,
+ ObjValueBuilder, Result, Source, Thunk, Val, bail,
+ function::{FuncVal, builtin},
};
use jrsonnet_gcmodule::Trace;