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
58
59
60
61
62
use proc_macro_error;
use parse_macro_input;
/// A macro that makes it easy to define functions and properies on host
/// objects.
///
/// ```no_run
/// struct ExampleHostObject;
///
/// #[host_object]
/// impl ExampleHostObject {
/// pub fn time(&self, _rt: &mut RuntimeHandle) -> anyhow::Result<i64> {
/// Ok(3200)
/// }
/// }
/// ```
///
/// It is used on `impl` blocks and on the functions within the `impl` block.
///
/// - Add `#[host_object(getter)]` to designate an `fn` as a getter. This will
/// allow JavaScript code to read the member like a property instead of having
/// to call it like a function. Getters should be `fn(&self, &mut
/// RuntimeHandle) -> Result<T>` where `T: IntoValue`.
///
/// If the `fn` name in Rust starts with `get_`, this prefix will be removed.
///
/// - Add `#[host_object(setter)]` to designate an `fn` as a setter. This will
/// allow JavaScript code to write the like a property instead of having to
/// call it like a function. Setters should be `fn(&self, &mut RuntimeHandle,
/// value: JsiValue) -> Result<()>`.
///
/// If the `fn` name in Rust starts with `set_`, this prefix will be removed.
///
/// - All other methods will appear as methods on the host object in JavaScript.
/// The first two arguments should be `&self` and a `&mut Runtime`.
///
/// By default, all member names in a `host_object` block are converted from
/// `snake_case` to `camelCase` to give them idiomatic names in JavaScript. To
/// override this, you can set a name with `#[host_object(method as
/// custom_method_name)]` or `#[host_object(getter as custom_prop_name)]`.
///