Skip to main content

Options

Struct Options 

Source
#[non_exhaustive]
pub struct Options { pub timeout: Option<Duration>, pub max_depth: Option<usize>, pub now: Option<i64>, pub seed: Option<u64>, pub cancel_token: Option<CancelToken>, pub max_string_length: Option<usize>, pub max_array_length: Option<usize>, pub max_result_size: Option<usize>, }
Expand description

Evaluation guardrails, and the clock and seed that make an evaluation reproducible.

The struct is #[non_exhaustive], so new options can be added without breaking callers: start from Options::new (or Options::default()) and chain the builder methods.

use jlens_core::Options;
use std::time::Duration;

let options = Options::new()
    .timeout(Duration::from_millis(100))
    .max_depth(500);
assert_eq!(options.max_depth, Some(500));

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§timeout: Option<Duration>

Maximum wall-clock time for one evaluation. Exceeding it raises D1012.

§max_depth: Option<usize>

Maximum evaluation depth (default 50,000; 500 on WebAssembly). Exceeding it raises D1011.

§now: Option<i64>

The evaluation’s timestamp, in milliseconds since the epoch, for $now() and $millis(). Default: the system clock, read once, the first time the evaluation needs it.

§seed: Option<u64>

Seed for $random() and $shuffle(). Default: one taken from the system clock.

§cancel_token: Option<CancelToken>

Stops the evaluation with U1003 once the token is cancelled, from any thread.

§max_string_length: Option<usize>

Maximum length, in bytes of UTF-8, of a string that the evaluation builds (default 268,435,456: 256 MiB). Exceeding it raises U1001.

§max_array_length: Option<usize>

Maximum number of items in an array or sequence that the evaluation builds (default 16,777,216). Exceeding it raises U1001.

§max_result_size: Option<usize>

Maximum size of the result as compact JSON text, in bytes (default 268,435,456: 256 MiB), which also limits the arguments of a host function. A value that appears several times counts each time, as it does in the text. Exceeding it raises U1001.

Implementations§

Source§

impl Options

Source

pub fn new() -> Self

Creates options with no timeout, the default depth and size limits, the system clock and an unseeded generator.

Source

pub fn now(self, millis: i64) -> Self

Fixes the evaluation’s timestamp ($now(), $millis()), in milliseconds since the epoch.

Source

pub fn seed(self, seed: u64) -> Self

Seeds $random() and $shuffle(): the same seed gives the same sequence.

Source

pub fn timeout(self, timeout: Duration) -> Self

Sets the maximum wall-clock time for one evaluation (D1012 when exceeded).

Source

pub fn max_depth(self, max_depth: usize) -> Self

Sets the maximum evaluation depth (D1011 when exceeded).

Source

pub fn max_string_length(self, bytes: usize) -> Self

Sets the maximum length, in bytes, of a string the evaluation builds (U1001 when exceeded).

Source

pub fn max_array_length(self, items: usize) -> Self

Sets the maximum number of items of an array the evaluation builds (U1001 when exceeded).

Source

pub fn max_result_size(self, bytes: usize) -> Self

Sets the maximum size, in bytes of compact JSON text, of the result and of the arguments of a host function (U1001 when exceeded).

Source

pub fn cancel_token(self, token: CancelToken) -> Self

Lets token stop the evaluation (U1003 once it is cancelled).

Trait Implementations§

Source§

impl Clone for Options

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Options

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Options

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.