pub struct BQNValue { /* private fields */ }
Expand description
Represents a BQN value
Implementations§
source§impl BQNValue
impl BQNValue
sourcepub fn has_field(&self, field: &str) -> Result<bool, Error>
pub fn has_field(&self, field: &str) -> Result<bool, Error>
Returns a boolean value indicating whether field
exists in a BQN namespace
As CBQN requires the searched field name to be in a string with all lowercase letters, this
function returns false
if it is supplied with a field
string that contains uppercase
characters.
sourcepub fn get_field(&self, field: &str) -> Result<Option<BQNValue>, Error>
pub fn get_field(&self, field: &str) -> Result<Option<BQNValue>, Error>
Returns field
from a BQN namespace as BQNValue
. Returns None
if the field cannot be
found.
As CBQN requires the searched field name to be in a string with all lowercase letters, this
function returns None
if it is supplied with a field
string that contains uppercase
characters.
sourcepub fn call1(&self, x: &BQNValue) -> Result<BQNValue, Error>
pub fn call1(&self, x: &BQNValue) -> Result<BQNValue, Error>
Calls BQNValue
as a function with one argument
sourcepub fn call2(&self, w: &BQNValue, x: &BQNValue) -> Result<BQNValue, Error>
pub fn call2(&self, w: &BQNValue, x: &BQNValue) -> Result<BQNValue, Error>
Calls BQNValue
as a function with two arguments
sourcepub fn to_char(&self) -> Result<Option<char>, Error>
pub fn to_char(&self) -> Result<Option<char>, Error>
Converts BQNValue
into char
Returns None
if the value is not an Unicode scalar value. Rust char
s cannot represent
characters that are not Unicode scalar values.
sourcepub fn to_u32(&self) -> Result<u32, Error>
pub fn to_u32(&self) -> Result<u32, Error>
Converts BQNValue
into u32
BQN characters can contain values that aren’t Unicode scalar values. Those characters can
be converted into a Rust type u32
using this function.
sourcepub fn to_bqnvalue_vec(&self) -> Result<Vec<BQNValue>, Error>
pub fn to_bqnvalue_vec(&self) -> Result<Vec<BQNValue>, Error>
Converts BQNValue
into a vector of BQNValue
s
sourcepub fn fn1(func: fn(_: &BQNValue) -> BQNValue) -> BQNValue
pub fn fn1(func: fn(_: &BQNValue) -> BQNValue) -> BQNValue
Generates a BQNValue from a Rust function
The function receives one argument.
Examples
let add_three = BQNValue::fn1(|x| BQNValue::from(x.to_f64().unwrap() + 3.0));
assert_eq!(BQN!(3, "{𝕏𝕨}", add_three).unwrap().to_f64().unwrap(), 6.0);
Panics
- If called from a BQNValue::fn1 or BQNValue::fn2 function
Implementation note
Calling this function will allocate memory that will last for the lifetime of the program. Calling it with two identical closures, but with different lifetimes, will allocate the memory multiple times.
Backend support
Not supported in WASI backend
sourcepub fn fn2(func: fn(_: &BQNValue, _: &BQNValue) -> BQNValue) -> BQNValue
pub fn fn2(func: fn(_: &BQNValue, _: &BQNValue) -> BQNValue) -> BQNValue
Generates a BQNValue from a Rust function
The function receives two arguments.
Examples
let multiply = BQNValue::fn2(|w, x| BQNValue::from(w.to_f64().unwrap() *
x.to_f64().unwrap()));
assert_eq!(BQN!(multiply, "{𝕎´𝕩}", [1,2,3,4,5]).unwrap().to_f64().unwrap(), 120.0);
Panics
- If called from a BQNValue::fn1 or BQNValue::fn2 function
Implementation note
Calling this function will allocate memory that will last for the lifetime of the program. Calling it with two identical closures, but with different lifetimes, will allocate the memory multiple times.
Backend support
Not supported in WASI backend