pub struct Data { /* private fields */ }Expand description
Named values bound as variables when a program is compiled: the observed data, and any scalar settings a host wants to pass in.
use fugue::program::{Data, Value};
let from_rust = Data::new()
.with("y", vec![1.3, 0.7, 2.1])
.with("n", 3)
.with("strict", true);
let from_json = Data::from_json(r#"{"y": [1.3, 0.7, 2.1], "n": 3, "strict": true}"#).unwrap();
assert_eq!(from_rust, from_json);
assert_eq!(from_json.get("n"), Some(&Value::Int(3)));
// A bare array binds `data`, as the playground has always read it.
let bare = Data::from_json("[1, 0, 1]").unwrap();
assert_eq!(bare.get("data").and_then(Value::as_array), Some(&[1.0, 0.0, 1.0][..]));Implementations§
Source§impl Data
impl Data
Sourcepub fn from_json(json: &str) -> Result<Data, ProgramError>
pub fn from_json(json: &str) -> Result<Data, ProgramError>
Read bindings from JSON: an object whose values are numbers, booleans,
or arrays of numbers/booleans; a bare array (bound to data); or an
empty string / null for none.
Arrays become Value::Arr (booleans read as 1.0/0.0). A scalar
integer becomes Value::Int (or Value::U64 above i64::MAX),
any other number Value::F64, a boolean Value::Bool.
Sourcepub fn with(self, name: impl Into<String>, value: impl Into<Value>) -> Data
pub fn with(self, name: impl Into<String>, value: impl Into<Value>) -> Data
These bindings plus name bound to value (builder style).
Trait Implementations§
impl StructuralPartialEq for Data
Auto Trait Implementations§
impl Freeze for Data
impl RefUnwindSafe for Data
impl Send for Data
impl Sync for Data
impl Unpin for Data
impl UnsafeUnpin for Data
impl UnwindSafe for Data
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more