Struct Program

Source
pub struct Program<'p> { /* private fields */ }
Expand description

Jsonnet program state and evaluator.

See the module-level documentation for more information.

Implementations§

Source§

impl<'p> Program<'p>

Source

pub fn new(arena: &'p Arena) -> Self

Creates a new Program.

Source

pub fn str_interner(&self) -> &StrInterner<'p>

Source

pub fn intern_str(&self, s: &str) -> InternedStr<'p>

Source

pub fn span_manager(&self) -> &SpanManager

Source

pub fn span_manager_mut(&mut self) -> &mut SpanManager

Source

pub fn gc(&mut self)

Runs garbage collection unconditionally.

Source

pub fn maybe_gc(&mut self)

Runs garbage collection under certain conditions.

Source

pub fn set_max_stack(&mut self, max_stack: usize)

Sets the maximum call stack size.

The default is 500.

Source

pub fn get_stdlib_source(&self) -> (SourceId, &[u8])

Returns the source of the part of the standard library that is implemented in Jsonnet.

Source

pub fn add_ext_var(&mut self, name: InternedStr<'p>, thunk: &Thunk<'p>)

Adds an external variable.

External variables can be accessed within a Jsonnet program with the std.extVar function.

Source

pub fn register_native_func( &mut self, name: InternedStr<'p>, params: &[InternedStr<'p>], )

Registers a native function.

Native functions can be accessed within a Jsonnet program with the std.native function.

The actual behavior of the native function should be implemented in Callbacks::native_call.

§Panics

Panics if a native function with the same name is already registered or if a parameter name is repeated.

Source

pub fn value_to_thunk(&mut self, value: &Value<'p>) -> Thunk<'p>

Creates a thunk with an already evaluated value.

Source

pub fn make_array(&mut self, items: &[Value<'p>]) -> Value<'p>

Creates an array value.

Source

pub fn make_object( &mut self, obj_fields: &[(InternedStr<'p>, Value<'p>)], ) -> Value<'p>

Creates an object value.

Source

pub fn load_source( &mut self, span_ctx: SpanContextId, input: &[u8], with_stdlib: bool, this_file: &str, ) -> Result<Thunk<'p>, LoadError>

Loads a Jsonnet source into a thunk.

with_stdlib specifies whether the standard library will be available as std. this_file will be the value of std.thisFile.

Source

pub fn eval_value( &mut self, thunk: &Thunk<'p>, callbacks: &mut dyn Callbacks<'p>, ) -> Result<Value<'p>, EvalError>

Evaluates a thunk into a value.

Source

pub fn eval_call( &mut self, func: &Thunk<'p>, pos_args: &[Thunk<'p>], named_args: &[(InternedStr<'p>, Thunk<'p>)], callbacks: &mut dyn Callbacks<'p>, ) -> Result<Value<'p>, EvalError>

Evaluates a function call.

Source

pub fn manifest_json( &mut self, value: &Value<'p>, multiline: bool, ) -> Result<String, EvalError>

Manifests a value as JSON.

Auto Trait Implementations§

§

impl<'p> !Freeze for Program<'p>

§

impl<'p> !RefUnwindSafe for Program<'p>

§

impl<'p> !Send for Program<'p>

§

impl<'p> !Sync for Program<'p>

§

impl<'p> Unpin for Program<'p>

§

impl<'p> !UnwindSafe for Program<'p>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.