1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
//! The `WithOptions` token (`WithOptions.tokens`, `WithOptions.indexer`, ...) of the step-level
//! `with()` modulator.
use crate::script::*;
/// Scope marker that makes the dotted spelling `WithOptions.tokens` resolve.
///
/// Mirrors [`ScriptBarrier`]; the static module gives `WithOptions::tokens`. No bare constants.
/// The token itself is [`crate::value::WithOptions`], registered with Rhai as `WithOptions`.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct ScriptWithOptions;
#[export_module]
#[allow(non_snake_case, non_upper_case_globals)]
pub(crate) mod WithOptionsModule {
use crate::value::WithOptions;
use crate::value::literal::TokenLiteral;
/// `WithOptions.tokens`: the `valueMap()` tokens option.
pub const tokens: WithOptions = WithOptions::Tokens;
/// `WithOptions.none`: no token.
pub const none: WithOptions = WithOptions::None;
/// `WithOptions.ids`: the id token.
pub const ids: WithOptions = WithOptions::Ids;
/// `WithOptions.labels`: the label token.
pub const labels: WithOptions = WithOptions::Labels;
/// `WithOptions.keys`: the key token of a vertex property.
pub const keys: WithOptions = WithOptions::Keys;
/// `WithOptions.values`: the value token of a vertex property.
pub const values: WithOptions = WithOptions::Values;
/// `WithOptions.all`: every token.
pub const all: WithOptions = WithOptions::All;
/// `WithOptions.indexer`: the `index()` indexer option.
pub const indexer: WithOptions = WithOptions::Indexer;
/// `WithOptions.list`: the list indexer.
pub const list: WithOptions = WithOptions::List;
/// `WithOptions.map`: the map indexer.
pub const map: WithOptions = WithOptions::Map;
/// Printing
#[rhai_fn(global, name = "to_string", name = "to_debug", pure)]
pub fn to_string(option: &mut WithOptions) -> String {
option.token_literal()
}
/// Equality
#[rhai_fn(global, name = "==", pure)]
pub fn eq(left: &mut WithOptions, right: WithOptions) -> bool {
*left == right
}
/// Inequality
#[rhai_fn(global, name = "!=", pure)]
pub fn ne(left: &mut WithOptions, right: WithOptions) -> bool {
*left != right
}
}