Revise required/forbidden features in examples.
This commit is contained in:
parent
f188f96974
commit
a95ef4c255
@ -82,6 +82,10 @@ name = "rhai-run"
|
||||
name = "rhai-dbg"
|
||||
required-features = ["debugging"]
|
||||
|
||||
[[example]]
|
||||
name = "serde"
|
||||
required-features = ["serde"]
|
||||
|
||||
[profile.release]
|
||||
lto = "fat"
|
||||
codegen-units = 1
|
||||
|
@ -1,5 +1,10 @@
|
||||
//! An example showing how to register a Rust type and use it with arrays.
|
||||
|
||||
#[cfg(any(feature = "no_index", feature = "no_object"))]
|
||||
fn main() {
|
||||
panic!("This example does not run under 'no_index' or 'no_object'.")
|
||||
}
|
||||
|
||||
use rhai::{Engine, EvalAltResult};
|
||||
|
||||
#[cfg(not(feature = "no_index"))]
|
||||
@ -60,8 +65,3 @@ fn main() -> Result<(), Box<EvalAltResult>> {
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "no_index", feature = "no_object"))]
|
||||
fn main() {
|
||||
panic!("This example does not run under 'no_index' or 'no_object'.")
|
||||
}
|
||||
|
@ -1,5 +1,10 @@
|
||||
//! An example showing how to register a Rust type and methods/getters/setters for it.
|
||||
|
||||
#[cfg(feature = "no_object")]
|
||||
fn main() {
|
||||
panic!("This example does not run under 'no_object'.");
|
||||
}
|
||||
|
||||
use rhai::{Engine, EvalAltResult};
|
||||
|
||||
#[cfg(not(feature = "no_object"))]
|
||||
@ -61,8 +66,3 @@ fn main() -> Result<(), Box<EvalAltResult>> {
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(feature = "no_object")]
|
||||
fn main() {
|
||||
panic!("This example does not run under 'no_object'.");
|
||||
}
|
||||
|
@ -1,43 +1,45 @@
|
||||
//! Implementation of the Event Handler With State Pattern - JS Style
|
||||
use rhai::{Dynamic, Engine, Scope, AST};
|
||||
|
||||
#[cfg(not(feature = "no_object"))]
|
||||
use rhai::Map;
|
||||
|
||||
use std::io::{stdin, stdout, Write};
|
||||
|
||||
const SCRIPT_FILE: &str = "event_handler_js/script.rhai";
|
||||
|
||||
#[derive(Debug)]
|
||||
struct Handler {
|
||||
pub engine: Engine,
|
||||
pub scope: Scope<'static>,
|
||||
pub states: Dynamic,
|
||||
pub ast: AST,
|
||||
}
|
||||
|
||||
fn print_scope(scope: &Scope) {
|
||||
for (i, (name, constant, value)) in scope.iter_raw().enumerate() {
|
||||
#[cfg(not(feature = "no_closure"))]
|
||||
let value_is_shared = if value.is_shared() { " (shared)" } else { "" };
|
||||
#[cfg(feature = "no_closure")]
|
||||
let value_is_shared = "";
|
||||
|
||||
println!(
|
||||
"[{}] {}{}{} = {:?}",
|
||||
i + 1,
|
||||
if constant { "const " } else { "" },
|
||||
name,
|
||||
value_is_shared,
|
||||
*value.read_lock::<Dynamic>().unwrap(),
|
||||
)
|
||||
}
|
||||
println!();
|
||||
#[cfg(any(feature = "no_function", feature = "no_object"))]
|
||||
pub fn main() {
|
||||
panic!("This example does not run under 'no_function' or 'no_object'.")
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "no_function"))]
|
||||
#[cfg(not(feature = "no_object"))]
|
||||
pub fn main() {
|
||||
use rhai::{Dynamic, Engine, Map, Scope, AST};
|
||||
use std::io::{stdin, stdout, Write};
|
||||
|
||||
const SCRIPT_FILE: &str = "event_handler_js/script.rhai";
|
||||
|
||||
#[derive(Debug)]
|
||||
struct Handler {
|
||||
pub engine: Engine,
|
||||
pub scope: Scope<'static>,
|
||||
pub states: Dynamic,
|
||||
pub ast: AST,
|
||||
}
|
||||
|
||||
fn print_scope(scope: &Scope) {
|
||||
for (i, (name, constant, value)) in scope.iter_raw().enumerate() {
|
||||
#[cfg(not(feature = "no_closure"))]
|
||||
let value_is_shared = if value.is_shared() { " (shared)" } else { "" };
|
||||
#[cfg(feature = "no_closure")]
|
||||
let value_is_shared = "";
|
||||
|
||||
println!(
|
||||
"[{}] {}{}{} = {:?}",
|
||||
i + 1,
|
||||
if constant { "const " } else { "" },
|
||||
name,
|
||||
value_is_shared,
|
||||
*value.read_lock::<Dynamic>().unwrap(),
|
||||
)
|
||||
}
|
||||
println!();
|
||||
}
|
||||
|
||||
println!("Events Handler Example - JS Style");
|
||||
println!("==================================");
|
||||
|
||||
@ -158,8 +160,3 @@ pub fn main() {
|
||||
|
||||
println!("Bye!");
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "no_function", feature = "no_object"))]
|
||||
pub fn main() {
|
||||
panic!("This example does not run under 'no_function' or 'no_object'.")
|
||||
}
|
||||
|
@ -1,38 +1,43 @@
|
||||
//! Implementation of the Event Handler With State Pattern - Main Style
|
||||
use rhai::{Dynamic, Engine, Scope, AST};
|
||||
|
||||
use std::io::{stdin, stdout, Write};
|
||||
|
||||
const SCRIPT_FILE: &str = "event_handler_main/script.rhai";
|
||||
|
||||
#[derive(Debug)]
|
||||
struct Handler {
|
||||
pub engine: Engine,
|
||||
pub scope: Scope<'static>,
|
||||
pub ast: AST,
|
||||
}
|
||||
|
||||
fn print_scope(scope: &Scope) {
|
||||
for (i, (name, constant, value)) in scope.iter_raw().enumerate() {
|
||||
#[cfg(not(feature = "no_closure"))]
|
||||
let value_is_shared = if value.is_shared() { " (shared)" } else { "" };
|
||||
#[cfg(feature = "no_closure")]
|
||||
let value_is_shared = "";
|
||||
|
||||
println!(
|
||||
"[{}] {}{}{} = {:?}",
|
||||
i + 1,
|
||||
if constant { "const " } else { "" },
|
||||
name,
|
||||
value_is_shared,
|
||||
*value.read_lock::<Dynamic>().unwrap(),
|
||||
)
|
||||
}
|
||||
println!();
|
||||
#[cfg(feature = "no_function")]
|
||||
pub fn main() {
|
||||
panic!("This example does not run under 'no_function'.")
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "no_function"))]
|
||||
pub fn main() {
|
||||
use rhai::{Dynamic, Engine, Scope, AST};
|
||||
use std::io::{stdin, stdout, Write};
|
||||
|
||||
const SCRIPT_FILE: &str = "event_handler_main/script.rhai";
|
||||
|
||||
#[derive(Debug)]
|
||||
struct Handler {
|
||||
pub engine: Engine,
|
||||
pub scope: Scope<'static>,
|
||||
pub ast: AST,
|
||||
}
|
||||
|
||||
fn print_scope(scope: &Scope) {
|
||||
for (i, (name, constant, value)) in scope.iter_raw().enumerate() {
|
||||
#[cfg(not(feature = "no_closure"))]
|
||||
let value_is_shared = if value.is_shared() { " (shared)" } else { "" };
|
||||
#[cfg(feature = "no_closure")]
|
||||
let value_is_shared = "";
|
||||
|
||||
println!(
|
||||
"[{}] {}{}{} = {:?}",
|
||||
i + 1,
|
||||
if constant { "const " } else { "" },
|
||||
name,
|
||||
value_is_shared,
|
||||
*value.read_lock::<Dynamic>().unwrap(),
|
||||
)
|
||||
}
|
||||
println!();
|
||||
}
|
||||
|
||||
println!("Events Handler Example - Main Style");
|
||||
println!("===================================");
|
||||
|
||||
@ -130,8 +135,3 @@ pub fn main() {
|
||||
|
||||
println!("Bye!");
|
||||
}
|
||||
|
||||
#[cfg(feature = "no_function")]
|
||||
pub fn main() {
|
||||
panic!("This example does not run under 'no_function'.")
|
||||
}
|
||||
|
@ -1,42 +1,44 @@
|
||||
//! Implementation of the Event Handler With State Pattern - Map Style
|
||||
use rhai::{Dynamic, Engine, Scope, AST};
|
||||
|
||||
#[cfg(not(feature = "no_object"))]
|
||||
use rhai::Map;
|
||||
|
||||
use std::io::{stdin, stdout, Write};
|
||||
|
||||
const SCRIPT_FILE: &str = "event_handler_map/script.rhai";
|
||||
|
||||
#[derive(Debug)]
|
||||
struct Handler {
|
||||
pub engine: Engine,
|
||||
pub scope: Scope<'static>,
|
||||
pub ast: AST,
|
||||
}
|
||||
|
||||
fn print_scope(scope: &Scope) {
|
||||
for (i, (name, constant, value)) in scope.iter_raw().enumerate() {
|
||||
#[cfg(not(feature = "no_closure"))]
|
||||
let value_is_shared = if value.is_shared() { " (shared)" } else { "" };
|
||||
#[cfg(feature = "no_closure")]
|
||||
let value_is_shared = "";
|
||||
|
||||
println!(
|
||||
"[{}] {}{}{} = {:?}",
|
||||
i + 1,
|
||||
if constant { "const " } else { "" },
|
||||
name,
|
||||
value_is_shared,
|
||||
*value.read_lock::<Dynamic>().unwrap(),
|
||||
)
|
||||
}
|
||||
println!();
|
||||
#[cfg(any(feature = "no_function", feature = "no_object"))]
|
||||
pub fn main() {
|
||||
panic!("This example does not run under 'no_function' or 'no_object'.")
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "no_function"))]
|
||||
#[cfg(not(feature = "no_object"))]
|
||||
pub fn main() {
|
||||
use rhai::{Dynamic, Engine, Map, Scope, AST};
|
||||
use std::io::{stdin, stdout, Write};
|
||||
|
||||
const SCRIPT_FILE: &str = "event_handler_map/script.rhai";
|
||||
|
||||
#[derive(Debug)]
|
||||
struct Handler {
|
||||
pub engine: Engine,
|
||||
pub scope: Scope<'static>,
|
||||
pub ast: AST,
|
||||
}
|
||||
|
||||
fn print_scope(scope: &Scope) {
|
||||
for (i, (name, constant, value)) in scope.iter_raw().enumerate() {
|
||||
#[cfg(not(feature = "no_closure"))]
|
||||
let value_is_shared = if value.is_shared() { " (shared)" } else { "" };
|
||||
#[cfg(feature = "no_closure")]
|
||||
let value_is_shared = "";
|
||||
|
||||
println!(
|
||||
"[{}] {}{}{} = {:?}",
|
||||
i + 1,
|
||||
if constant { "const " } else { "" },
|
||||
name,
|
||||
value_is_shared,
|
||||
*value.read_lock::<Dynamic>().unwrap(),
|
||||
)
|
||||
}
|
||||
println!();
|
||||
}
|
||||
|
||||
println!("Events Handler Example - Map Style");
|
||||
println!("==================================");
|
||||
|
||||
@ -147,8 +149,3 @@ pub fn main() {
|
||||
|
||||
println!("Bye!");
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "no_function", feature = "no_object"))]
|
||||
pub fn main() {
|
||||
panic!("This example does not run under 'no_function' or 'no_object'.")
|
||||
}
|
||||
|
@ -1,22 +1,12 @@
|
||||
//! An example to serialize and deserialize Rust types.
|
||||
|
||||
#[cfg(any(not(feature = "serde"), feature = "no_object"))]
|
||||
#[cfg(feature = "no_object")]
|
||||
fn main() {
|
||||
println!("This example requires the 'serde' feature to run.");
|
||||
println!("Try: cargo run --features serde --example serde");
|
||||
panic!("This example does not run under 'no_object'.")
|
||||
}
|
||||
|
||||
#[cfg(feature = "serde")]
|
||||
#[cfg(not(feature = "no_object"))]
|
||||
fn main() {
|
||||
example::ser();
|
||||
println!();
|
||||
example::de();
|
||||
}
|
||||
|
||||
#[cfg(feature = "serde")]
|
||||
#[cfg(not(feature = "no_object"))]
|
||||
mod example {
|
||||
use rhai::serde::{from_dynamic, to_dynamic};
|
||||
use rhai::{Dynamic, Engine, Map};
|
||||
use serde::{Deserialize, Serialize};
|
||||
@ -60,13 +50,13 @@ mod example {
|
||||
let result: Dynamic = engine
|
||||
.eval(
|
||||
r#"
|
||||
#{
|
||||
a: 42,
|
||||
b: [ "hello", "world" ],
|
||||
c: true,
|
||||
d: #{ x: 123.456, y: 999.0 }
|
||||
}
|
||||
"#,
|
||||
#{
|
||||
a: 42,
|
||||
b: [ "hello", "world" ],
|
||||
c: true,
|
||||
d: #{ x: 123.456, y: 999.0 }
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
@ -89,4 +79,8 @@ mod example {
|
||||
);
|
||||
println!("Deserialized to struct: {:#?}", x);
|
||||
}
|
||||
|
||||
ser();
|
||||
println!();
|
||||
de();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user