pub struct Context { /* private fields */ }
Expand description
This struct contains fend’s current context, including some settings as well as stored variables.
If you’re writing an interpreter it’s recommended to only instantiate this struct once so that variables and settings are preserved, but you can also manually serialise all variables and recreate the context for every calculation, depending on which is easier.
Implementations§
source§impl Context
impl Context
sourcepub fn set_current_time_v1(&mut self, _ms_since_1970: u64, _tz_offset_secs: i64)
pub fn set_current_time_v1(&mut self, _ms_since_1970: u64, _tz_offset_secs: i64)
This method currently has no effect!
Set the current time. This API will likely change in the future!
The first argument (ms_since_1970
) must be the number of elapsed milliseconds
since January 1, 1970 at midnight UTC, ignoring leap seconds in the same way
as unix time.
The second argument (tz_offset_secs
) is the current time zone
offset to UTC, in seconds.
sourcepub fn use_coulomb_and_farad(&mut self)
pub fn use_coulomb_and_farad(&mut self)
Define the units C
and F
as coulomb and farad instead of degrees
celsius and degrees fahrenheit.
sourcepub fn set_random_u32_fn(&mut self, random_u32: fn() -> u32)
pub fn set_random_u32_fn(&mut self, random_u32: fn() -> u32)
Set a random number generator
sourcepub fn disable_rng(&mut self)
pub fn disable_rng(&mut self)
Clear the random number generator after setting it with via Self::set_random_u32_fn
sourcepub fn set_output_mode_terminal(&mut self)
pub fn set_output_mode_terminal(&mut self)
Change the output mode to fixed-width terminal style. This enables ASCII graphs in the output.
sourcepub fn serialize_variables(&self, write: &mut impl Write) -> Result<(), String>
pub fn serialize_variables(&self, write: &mut impl Write) -> Result<(), String>
Serializes all variables defined in this context to a stream of bytes. Note that the specific format is NOT stable, and can change with any minor update.
§Errors
This function returns an error if the input cannot be serialized.
sourcepub fn deserialize_variables(
&mut self,
read: &mut impl Read
) -> Result<(), String>
pub fn deserialize_variables( &mut self, read: &mut impl Read ) -> Result<(), String>
Deserializes the given variables, replacing all prior variables in the given context.
§Errors
Returns an error if the input byte stream is invalid and cannot be deserialized.
sourcepub fn set_exchange_rate_handler_v1<T: ExchangeRateFn + 'static + Send + Sync>(
&mut self,
get_exchange_rate: T
)
pub fn set_exchange_rate_handler_v1<T: ExchangeRateFn + 'static + Send + Sync>( &mut self, get_exchange_rate: T )
Set a handler function for loading exchange rates.