macro_rules! ion_sexp { ($($element:expr)*) => { ... }; }
Expand description
Constructs an s-expression Element
with the specified child values.
use ion_rs::ion_sexp;
use ion_rs::element::Element;
// Construct an s-expression Element from Rust values
let actual: Element = ion_sexp!("foo" 7 false ion_sexp!(1.5f64 8.25f64)).into();
// Construct an Element from serialized Ion data
let expected = Element::read_one(r#"("foo" 7 false (1.5e0 8.25e0))"#).unwrap();
// Compare the two Elements
assert_eq!(expected, actual);
Child values can be anything that implements Into<Element>
, which
includes existing Element values.
// Construct a s-expression Element from existing Elements
use ion_rs::ion_sexp;
use ion_rs::element::{Element, IntoAnnotatedElement};
let string_element: Element = "foo".into();
let bool_element: Element = true.into();
let actual: Element = ion_sexp!(
string_element
bool_element
10i64.with_annotations(["bar"]) // .with_annotations() constructs an Element
Element::clob("hello")
Element::symbol("world")
).into();
// Construct an Element from serialized Ion data
let expected = Element::read_one(r#"("foo" true bar::10 {{"hello"}} world)"#).unwrap();
// Compare the two Elements
assert_eq!(expected, actual);