Struct cbqn::BQNValue

source ·
pub struct BQNValue { /* private fields */ }
Expand description

Represents a BQN value

Implementations§

source§

impl BQNValue

source

pub fn null() -> BQNValue

Constructs a BQN null value @

Examples
BQN!('a', "-", BQNValue::null()).unwrap();
source

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.

source

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.

source

pub fn call1(&self, x: &BQNValue) -> Result<BQNValue, Error>

Calls BQNValue as a function with one argument

source

pub fn call2(&self, w: &BQNValue, x: &BQNValue) -> Result<BQNValue, Error>

Calls BQNValue as a function with two arguments

source

pub fn bqn_type(&self) -> BQNType

Returns the BQN type of the BQNValue

source

pub fn to_f64(&self) -> Result<f64, Error>

Converts BQNValue into f64

source

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 chars cannot represent characters that are not Unicode scalar values.

source

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.

source

pub fn to_f64_vec(&self) -> Result<Vec<f64>, Error>

Converts BQNValue into a vector of f64s

source

pub fn to_bqnvalue_vec(&self) -> Result<Vec<BQNValue>, Error>

Converts BQNValue into a vector of BQNValues

source

pub fn to_char_vec(&self) -> Result<Vec<char>, Error>

Converts BQNValue into vector of chars

source

pub fn to_string(&self) -> Result<String, Error>

Converts BQNValue into a String

source

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

source

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

Trait Implementations§

source§

impl Clone for BQNValue

source§

fn clone(&self) -> BQNValue

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl Debug for BQNValue

source§

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

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

impl Drop for BQNValue

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl From<&[BQNValue]> for BQNValue

source§

fn from(arr: &[BQNValue]) -> BQNValue

Converts to this type from the input type.
source§

impl From<&[f64]> for BQNValue

source§

fn from(arr: &[f64]) -> BQNValue

Converts to this type from the input type.
source§

impl From<&[i16]> for BQNValue

source§

fn from(arr: &[i16]) -> BQNValue

Converts to this type from the input type.
source§

impl From<&[i32]> for BQNValue

source§

fn from(arr: &[i32]) -> BQNValue

Converts to this type from the input type.
source§

impl From<&[i8]> for BQNValue

source§

fn from(arr: &[i8]) -> BQNValue

Converts to this type from the input type.
source§

impl From<&String> for BQNValue

source§

fn from(v: &String) -> BQNValue

Converts to this type from the input type.
source§

impl From<&str> for BQNValue

source§

fn from(v: &str) -> BQNValue

Converts to this type from the input type.
source§

impl<const N: usize> From<[&str; N]> for BQNValue

source§

fn from(arr: [&str; N]) -> BQNValue

Converts to this type from the input type.
source§

impl<const N: usize> From<[BQNValue; N]> for BQNValue

source§

fn from(arr: [BQNValue; N]) -> BQNValue

Converts to this type from the input type.
source§

impl<const N: usize> From<[String; N]> for BQNValue

source§

fn from(arr: [String; N]) -> BQNValue

Converts to this type from the input type.
source§

impl<const N: usize> From<[f64; N]> for BQNValue

source§

fn from(arr: [f64; N]) -> BQNValue

Converts to this type from the input type.
source§

impl<const N: usize> From<[i16; N]> for BQNValue

source§

fn from(arr: [i16; N]) -> BQNValue

Converts to this type from the input type.
source§

impl<const N: usize> From<[i32; N]> for BQNValue

source§

fn from(arr: [i32; N]) -> BQNValue

Converts to this type from the input type.
source§

impl<const N: usize> From<[i8; N]> for BQNValue

source§

fn from(arr: [i8; N]) -> BQNValue

Converts to this type from the input type.
source§

impl From<String> for BQNValue

source§

fn from(v: String) -> BQNValue

Converts to this type from the input type.
source§

impl From<Vec<&String, Global>> for BQNValue

source§

fn from(arr: Vec<&String>) -> BQNValue

Converts to this type from the input type.
source§

impl From<Vec<&str, Global>> for BQNValue

source§

fn from(arr: Vec<&str>) -> BQNValue

Converts to this type from the input type.
source§

impl From<Vec<BQNValue, Global>> for BQNValue

source§

fn from(arr: Vec<BQNValue>) -> BQNValue

Converts to this type from the input type.
source§

impl From<Vec<String, Global>> for BQNValue

source§

fn from(arr: Vec<String>) -> BQNValue

Converts to this type from the input type.
source§

impl From<Vec<f64, Global>> for BQNValue

source§

fn from(arr: Vec<f64>) -> BQNValue

Converts to this type from the input type.
source§

impl From<Vec<i16, Global>> for BQNValue

source§

fn from(arr: Vec<i16>) -> BQNValue

Converts to this type from the input type.
source§

impl From<Vec<i32, Global>> for BQNValue

source§

fn from(arr: Vec<i32>) -> BQNValue

Converts to this type from the input type.
source§

impl From<Vec<i8, Global>> for BQNValue

source§

fn from(arr: Vec<i8>) -> BQNValue

Converts to this type from the input type.
source§

impl From<char> for BQNValue

source§

fn from(v: char) -> BQNValue

Converts to this type from the input type.
source§

impl From<f64> for BQNValue

source§

fn from(v: f64) -> BQNValue

Converts to this type from the input type.
source§

impl From<i32> for BQNValue

source§

fn from(v: i32) -> BQNValue

Converts to this type from the input type.
source§

impl FromIterator<BQNValue> for BQNValue

source§

fn from_iter<T>(iter: T) -> BQNValuewhere T: IntoIterator<Item = BQNValue>,

Creates a value from an iterator. Read more
source§

impl FromIterator<f64> for BQNValue

source§

fn from_iter<T>(iter: T) -> BQNValuewhere T: IntoIterator<Item = f64>,

Creates a value from an iterator. Read more
source§

impl FromIterator<i16> for BQNValue

source§

fn from_iter<T>(iter: T) -> BQNValuewhere T: IntoIterator<Item = i16>,

Creates a value from an iterator. Read more
source§

impl FromIterator<i32> for BQNValue

source§

fn from_iter<T>(iter: T) -> BQNValuewhere T: IntoIterator<Item = i32>,

Creates a value from an iterator. Read more
source§

impl FromIterator<i8> for BQNValue

source§

fn from_iter<T>(iter: T) -> BQNValuewhere T: IntoIterator<Item = i8>,

Creates a value from an iterator. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

const: unstable · 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 Twhere T: Clone,

§

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 Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.