pub struct Normal<E = Expr> { /* private fields */ }Expand description
Wolfram Language “normal” expression: f[...].
A normal expression is any expression that consists of a head and zero or more arguments.
Implementations§
Source§impl Normal
impl Normal
Sourcepub fn new<E>(head: E, contents: Vec<Expr>) -> Normal
pub fn new<E>(head: E, contents: Vec<Expr>) -> Normal
Construct a new normal expression from the head and elements.
Sourcepub fn elements(&self) -> &[Expr]
pub fn elements(&self) -> &[Expr]
The elements of this normal expression.
If head conceptually represents a function, these are the arguments that are
being applied to head.
Examples found in repository?
examples/wstp.rs (line 183)
176fn expr_string_join(link: &mut Link) {
177 let expr = link.get_expr().unwrap();
178
179 let list = expr.try_as_normal().unwrap();
180 assert!(list.has_head(&Symbol::new("System`List")));
181
182 let mut buffer = String::new();
183 for elem in list.elements() {
184 match elem.kind() {
185 ExprKind::String(str) => buffer.push_str(str),
186 _ => panic!("expected String argument, got: {:?}", elem),
187 }
188 }
189
190 link.put_str(buffer.as_str()).unwrap()
191}Sourcepub fn into_elements(self) -> Vec<Expr>
pub fn into_elements(self) -> Vec<Expr>
The elements of this normal expression.
Use Normal::elements() to get a reference to this value.
Sourcepub fn has_head(&self, sym: &Symbol) -> bool
pub fn has_head(&self, sym: &Symbol) -> bool
Returns true if the head of this expression is sym.
Examples found in repository?
examples/wstp.rs (line 180)
176fn expr_string_join(link: &mut Link) {
177 let expr = link.get_expr().unwrap();
178
179 let list = expr.try_as_normal().unwrap();
180 assert!(list.has_head(&Symbol::new("System`List")));
181
182 let mut buffer = String::new();
183 for elem in list.elements() {
184 match elem.kind() {
185 ExprKind::String(str) => buffer.push_str(str),
186 _ => panic!("expected String argument, got: {:?}", elem),
187 }
188 }
189
190 link.put_str(buffer.as_str()).unwrap()
191}Trait Implementations§
impl<E> Eq for Normal<E>where
E: Eq,
impl<E> StructuralPartialEq for Normal<E>
Auto Trait Implementations§
impl<E> Freeze for Normal<E>where
E: Freeze,
impl<E> RefUnwindSafe for Normal<E>where
E: RefUnwindSafe,
impl<E> Send for Normal<E>where
E: Send,
impl<E> Sync for Normal<E>where
E: Sync,
impl<E> Unpin for Normal<E>where
E: Unpin,
impl<E> UnwindSafe for Normal<E>where
E: UnwindSafe,
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