pub struct Operators { /* private fields */ }Expand description
Canonical operator registry.
Use Operators::register to add host-specific operators (typically x.*).
Implementations§
Source§impl Operators
impl Operators
Sourcepub fn new() -> Self
pub fn new() -> Self
Build the default canonical operator registry.
Examples found in repository?
examples/run_data_eng.rs (line 34)
13fn main() {
14 let mut doc = read_program(WRANGLE_SCRIPT).unwrap_or_else(|e| {
15 eprintln!("parse: {:?}", e);
16 process::exit(1);
17 });
18
19 // Inject data from Rust (e.g. from DB, file, API)
20 let raw_data = json!([
21 { "region": "APAC", "amount": 100, "product": "A" },
22 { "region": "EMEA", "amount": 50, "product": "B" },
23 { "region": "APAC", "amount": 80, "product": "A" },
24 { "region": "Americas", "amount": 120, "product": "C" },
25 { "region": "EMEA", "amount": 30, "product": "B" },
26 { "region": "APAC", "amount": 60, "product": "C" },
27 ]);
28 doc["state"]["server"] = json!({ "raw_data": raw_data });
29
30 let program = parse_program(&doc).unwrap_or_else(|e| {
31 eprintln!("validate: {} - {}", e.code, e.message);
32 process::exit(1);
33 });
34 let operators = Operators::new();
35 let out = execute_program(&program, &operators).unwrap_or_else(|e| {
36 eprintln!("run: {} - {}", e.code, e.message);
37 process::exit(1);
38 });
39
40 println!("server.result (by region: count, total amount, desc):");
41 println!("{}", serde_json::to_string_pretty(&out.state.server["result"]).unwrap());
42}More examples
examples/run_josie.rs (line 32)
11fn main() {
12 let path = match env::args().nth(1) {
13 Some(p) => p,
14 None => {
15 eprintln!("Usage: run_josie <path.josie>");
16 eprintln!(" e.g. cargo run -p josie-core --example run_josie -- examples/hello.josie");
17 process::exit(1);
18 }
19 };
20 let src = fs::read_to_string(&path).unwrap_or_else(|e| {
21 eprintln!("read {}: {}", path, e);
22 process::exit(1);
23 });
24 let doc = read_program(&src).unwrap_or_else(|e| {
25 eprintln!("parse {}: {:?}", path, e);
26 process::exit(1);
27 });
28 let program = parse_program(&doc).unwrap_or_else(|e| {
29 eprintln!("validate {}: {} ({})", path, e.code, e.message);
30 process::exit(1);
31 });
32 let operators = Operators::new();
33 let out = execute_program(&program, &operators).unwrap_or_else(|e| {
34 eprintln!("run {}: {} - {}", path, e.code, e.message);
35 process::exit(1);
36 });
37 println!("value: {}", serde_json::to_string_pretty(&out.value).unwrap());
38 let state_json = serde_json::json!({
39 "client": out.state.client,
40 "server": out.state.server,
41 });
42 println!("state: {}", serde_json::to_string_pretty(&state_json).unwrap());
43}examples/run_backend.rs (line 61)
13fn main() {
14 let mut doc = read_program(BACKEND_SCRIPT).unwrap_or_else(|e| {
15 eprintln!("parse: {:?}", e);
16 process::exit(1);
17 });
18
19 // Inject people data (e.g. from DB or API)
20 let raw_people = json!([
21 {
22 "id": 1,
23 "first": "Jane",
24 "last": "Doe",
25 "age": 28,
26 "city": "London",
27 "country": "UK",
28 "email": "jane.doe@example.com",
29 "phone": "+44 20 7946 0958",
30 "tags": ["customer", "vip"]
31 },
32 {
33 "id": 2,
34 "first": "Bob",
35 "last": "Smith",
36 "age": 34,
37 "city": "Berlin",
38 "country": "DE",
39 "email": "bob.smith@example.com",
40 "phone": "+49 30 12345678",
41 "tags": ["partner"]
42 },
43 {
44 "id": 3,
45 "first": "Alice",
46 "last": "Wu",
47 "age": 41,
48 "city": "Singapore",
49 "country": "SG",
50 "email": "alice.wu@example.com",
51 "phone": null,
52 "tags": []
53 },
54 ]);
55 doc["state"]["server"] = json!({ "raw_people": raw_people });
56
57 let program = parse_program(&doc).unwrap_or_else(|e| {
58 eprintln!("validate: {} - {}", e.code, e.message);
59 process::exit(1);
60 });
61 let operators = Operators::new();
62 let out = execute_program(&program, &operators).unwrap_or_else(|e| {
63 eprintln!("run: {} - {}", e.code, e.message);
64 process::exit(1);
65 });
66
67 println!("server.response (custom JSON shape):");
68 println!("{}", serde_json::to_string_pretty(&out.state.server["response"]).unwrap());
69}Trait Implementations§
Auto Trait Implementations§
impl Freeze for Operators
impl RefUnwindSafe for Operators
impl Send for Operators
impl Sync for Operators
impl Unpin for Operators
impl UnsafeUnpin for Operators
impl UnwindSafe for Operators
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