rhai/examples/no_std.rs

24 lines
456 B
Rust
Raw Normal View History

#![cfg_attr(feature = "no_std", no_std)]
2020-03-24 02:49:08 +01:00
use rhai::{Engine, EvalAltResult, INT};
2020-04-24 06:39:24 +02:00
#[cfg(feature = "no_std")]
extern crate alloc;
#[cfg(feature = "no_std")]
use alloc::boxed::Box;
fn main() -> Result<(), Box<EvalAltResult>> {
let engine = Engine::new();
2020-03-24 02:49:08 +01:00
let result = engine.eval::<INT>("40 + 2")?;
2020-03-24 04:21:09 +01:00
#[cfg(not(feature = "no_std"))]
println!("Answer: {}", result);
#[cfg(feature = "no_std")]
assert_eq!(result, 42);
Ok(())
}