difftreelog
feat(evaluator) Val::into_json
in: master
1 file changed
crates/jsonnet-evaluator/src/val.rsdiffbeforeafterboth1use crate::{1use crate::{2 create_error, evaluate, function::inline_parse_function_call, Context, Error, ObjValue, Result,2 create_error, evaluate, function::inline_parse_function_call, Context, Error, ObjValue, Result,3};3};4use jsonnet_parser::{ArgsDesc, LocExpr, ParamsDesc};4use jsonnet_parser::{el, Arg, ArgsDesc, Expr, LocExpr, ParamsDesc};5use std::{5use std::{6 cell::RefCell,6 cell::RefCell,7 fmt::{Debug, Display},7 fmt::{Debug, Display},173 Val::Lazy(_) => self.clone().unwrap_if_lazy()?.value_type()?,173 Val::Lazy(_) => self.clone().unwrap_if_lazy()?.value_type()?,174 })174 })175 }175 }176 pub fn into_json(self, padding: usize) -> Result<String> {177 let ctx = Context::new().with_var("__tmp__to_json__".to_owned(), self)?;178 if let Val::Str(result) = evaluate(179 ctx,180 &el!(Expr::Apply(181 el!(Expr::Index(182 el!(Expr::Var("std".to_owned())),183 el!(Expr::Str("manifestJsonEx".to_owned()))184 )),185 ArgsDesc(vec![186 Arg(None, el!(Expr::Var("__tmp__to_json__".to_owned()))),187 Arg(None, el!(Expr::Str(" ".repeat(padding))))188 ]),189 false190 )),191 )? {192 Ok(result)193 } else {194 unreachable!()195 }196 }176}197}177198