Struct Console

Source
pub struct Console { /* private fields */ }

Implementations§

Source§

impl Console

Source

pub fn get() -> Console

Examples found in repository?
examples/console.rs (line 4)
3fn main() {
4    let con = Console::get();
5    con.log(&[Val::from("Hello from Emlite!")]);
6}
More examples
Hide additional examples
examples/eval.rs (line 4)
3fn main() {
4    let con = Console::get();
5    let ret = eval!(
6        r#"
7        let con = ValMap.toValue({});
8        con.log("Hello");
9        6
10    "#,
11        con.as_handle()
12    );
13    con.log(&[ret]);
14}
Source

pub fn log(&self, args: &[Val])

Examples found in repository?
examples/console.rs (line 5)
3fn main() {
4    let con = Console::get();
5    con.log(&[Val::from("Hello from Emlite!")]);
6}
More examples
Hide additional examples
examples/eval.rs (line 13)
3fn main() {
4    let con = Console::get();
5    let ret = eval!(
6        r#"
7        let con = ValMap.toValue({});
8        con.log("Hello");
9        6
10    "#,
11        con.as_handle()
12    );
13    con.log(&[ret]);
14}
Source

pub fn as_handle(&self) -> u32

Examples found in repository?
examples/eval.rs (line 11)
3fn main() {
4    let con = Console::get();
5    let ret = eval!(
6        r#"
7        let con = ValMap.toValue({});
8        con.log("Hello");
9        6
10    "#,
11        con.as_handle()
12    );
13    con.log(&[ret]);
14}

Methods from Deref<Target = Val>§

Source

pub fn get(&self, prop: &str) -> Val

Examples found in repository?
examples/dom.rs (line 15)
3fn main() {
4    let document = Val::global("document");
5    let elem = document.call("createElement", &argv!["BUTTON"]);
6    elem.set(&"textContent", Val::from("Click"));
7    let body = document.call("getElementsByTagName", &argv!["body"]).at(0);
8    elem.call(
9        "addEventListener",
10        &argv![
11            "click",
12            Val::make_js_function(|ev| {
13                let console = Val::global("console");
14                console.call("clear", &[]);
15                println!("client x: {}", Val::from_handle(ev).get("clientX").as_i32());
16                println!("hello from Rust");
17                Val::undefined().as_handle()
18            })
19        ],
20    );
21    body.call("appendChild", &argv![elem]);
22}
More examples
Hide additional examples
examples/audio.rs (line 17)
3fn main() {
4    #[allow(non_snake_case)]
5    let mut AudioContext = Val::global("AudioContext");
6    if !AudioContext.as_bool() {
7        println!("No global AudioContext, trying webkitAudioContext");
8        AudioContext = Val::global("webkitAudioContext");
9    }
10
11    println!("Got an AudioContext");
12    let context = AudioContext.new(&[]);
13    let oscillator = context.call("createOscillator", &[]);
14
15    println!("Configuring oscillator");
16    oscillator.set("type", Val::from("triangle"));
17    oscillator.get("frequency").set("value", Val::from(261.63)); // Middle C
18
19    Val::global_this().set("oscillator", oscillator);
20    Val::global_this().set("context", context);
21
22    let document = Val::global("document");
23    let elem = document.call("createElement", &argv!["BUTTON"]);
24    elem.set(&"textContent", Val::from("Click"));
25    let body = document.call("getElementsByTagName", &argv!["body"]).at(0);
26    elem.call(
27        "addEventListener",
28        &argv![
29            "click",
30            Val::make_js_function(|_| {
31                let oscillator = Val::global("oscillator");
32                let context = Val::global("context");
33                println!("Playing");
34                oscillator.call("connect", &argv![context.get("destination")]);
35                oscillator.call("start", &argv![0]);
36                println!("All done!");
37                Val::undefined().as_handle()
38            })
39        ],
40    );
41    body.call("appendChild", &argv![elem]);
42}
Source

pub fn as_handle(&self) -> u32

Examples found in repository?
examples/dom.rs (line 17)
3fn main() {
4    let document = Val::global("document");
5    let elem = document.call("createElement", &argv!["BUTTON"]);
6    elem.set(&"textContent", Val::from("Click"));
7    let body = document.call("getElementsByTagName", &argv!["body"]).at(0);
8    elem.call(
9        "addEventListener",
10        &argv![
11            "click",
12            Val::make_js_function(|ev| {
13                let console = Val::global("console");
14                console.call("clear", &[]);
15                println!("client x: {}", Val::from_handle(ev).get("clientX").as_i32());
16                println!("hello from Rust");
17                Val::undefined().as_handle()
18            })
19        ],
20    );
21    body.call("appendChild", &argv![elem]);
22}
More examples
Hide additional examples
examples/audio.rs (line 37)
3fn main() {
4    #[allow(non_snake_case)]
5    let mut AudioContext = Val::global("AudioContext");
6    if !AudioContext.as_bool() {
7        println!("No global AudioContext, trying webkitAudioContext");
8        AudioContext = Val::global("webkitAudioContext");
9    }
10
11    println!("Got an AudioContext");
12    let context = AudioContext.new(&[]);
13    let oscillator = context.call("createOscillator", &[]);
14
15    println!("Configuring oscillator");
16    oscillator.set("type", Val::from("triangle"));
17    oscillator.get("frequency").set("value", Val::from(261.63)); // Middle C
18
19    Val::global_this().set("oscillator", oscillator);
20    Val::global_this().set("context", context);
21
22    let document = Val::global("document");
23    let elem = document.call("createElement", &argv!["BUTTON"]);
24    elem.set(&"textContent", Val::from("Click"));
25    let body = document.call("getElementsByTagName", &argv!["body"]).at(0);
26    elem.call(
27        "addEventListener",
28        &argv![
29            "click",
30            Val::make_js_function(|_| {
31                let oscillator = Val::global("oscillator");
32                let context = Val::global("context");
33                println!("Playing");
34                oscillator.call("connect", &argv![context.get("destination")]);
35                oscillator.call("start", &argv![0]);
36                println!("All done!");
37                Val::undefined().as_handle()
38            })
39        ],
40    );
41    body.call("appendChild", &argv![elem]);
42}
Source

pub fn set(&self, prop: &str, val: Val)

Examples found in repository?
examples/dom.rs (line 6)
3fn main() {
4    let document = Val::global("document");
5    let elem = document.call("createElement", &argv!["BUTTON"]);
6    elem.set(&"textContent", Val::from("Click"));
7    let body = document.call("getElementsByTagName", &argv!["body"]).at(0);
8    elem.call(
9        "addEventListener",
10        &argv![
11            "click",
12            Val::make_js_function(|ev| {
13                let console = Val::global("console");
14                console.call("clear", &[]);
15                println!("client x: {}", Val::from_handle(ev).get("clientX").as_i32());
16                println!("hello from Rust");
17                Val::undefined().as_handle()
18            })
19        ],
20    );
21    body.call("appendChild", &argv![elem]);
22}
More examples
Hide additional examples
examples/audio.rs (line 16)
3fn main() {
4    #[allow(non_snake_case)]
5    let mut AudioContext = Val::global("AudioContext");
6    if !AudioContext.as_bool() {
7        println!("No global AudioContext, trying webkitAudioContext");
8        AudioContext = Val::global("webkitAudioContext");
9    }
10
11    println!("Got an AudioContext");
12    let context = AudioContext.new(&[]);
13    let oscillator = context.call("createOscillator", &[]);
14
15    println!("Configuring oscillator");
16    oscillator.set("type", Val::from("triangle"));
17    oscillator.get("frequency").set("value", Val::from(261.63)); // Middle C
18
19    Val::global_this().set("oscillator", oscillator);
20    Val::global_this().set("context", context);
21
22    let document = Val::global("document");
23    let elem = document.call("createElement", &argv!["BUTTON"]);
24    elem.set(&"textContent", Val::from("Click"));
25    let body = document.call("getElementsByTagName", &argv!["body"]).at(0);
26    elem.call(
27        "addEventListener",
28        &argv![
29            "click",
30            Val::make_js_function(|_| {
31                let oscillator = Val::global("oscillator");
32                let context = Val::global("context");
33                println!("Playing");
34                oscillator.call("connect", &argv![context.get("destination")]);
35                oscillator.call("start", &argv![0]);
36                println!("All done!");
37                Val::undefined().as_handle()
38            })
39        ],
40    );
41    body.call("appendChild", &argv![elem]);
42}
Source

pub fn has(&self, prop: &str) -> bool

Source

pub fn has_own_property(&self, prop: &str) -> bool

Source

pub fn type_of(&self) -> String

Source

pub fn at(&self, idx: usize) -> Val

Examples found in repository?
examples/dom.rs (line 7)
3fn main() {
4    let document = Val::global("document");
5    let elem = document.call("createElement", &argv!["BUTTON"]);
6    elem.set(&"textContent", Val::from("Click"));
7    let body = document.call("getElementsByTagName", &argv!["body"]).at(0);
8    elem.call(
9        "addEventListener",
10        &argv![
11            "click",
12            Val::make_js_function(|ev| {
13                let console = Val::global("console");
14                console.call("clear", &[]);
15                println!("client x: {}", Val::from_handle(ev).get("clientX").as_i32());
16                println!("hello from Rust");
17                Val::undefined().as_handle()
18            })
19        ],
20    );
21    body.call("appendChild", &argv![elem]);
22}
More examples
Hide additional examples
examples/audio.rs (line 25)
3fn main() {
4    #[allow(non_snake_case)]
5    let mut AudioContext = Val::global("AudioContext");
6    if !AudioContext.as_bool() {
7        println!("No global AudioContext, trying webkitAudioContext");
8        AudioContext = Val::global("webkitAudioContext");
9    }
10
11    println!("Got an AudioContext");
12    let context = AudioContext.new(&[]);
13    let oscillator = context.call("createOscillator", &[]);
14
15    println!("Configuring oscillator");
16    oscillator.set("type", Val::from("triangle"));
17    oscillator.get("frequency").set("value", Val::from(261.63)); // Middle C
18
19    Val::global_this().set("oscillator", oscillator);
20    Val::global_this().set("context", context);
21
22    let document = Val::global("document");
23    let elem = document.call("createElement", &argv!["BUTTON"]);
24    elem.set(&"textContent", Val::from("Click"));
25    let body = document.call("getElementsByTagName", &argv!["body"]).at(0);
26    elem.call(
27        "addEventListener",
28        &argv![
29            "click",
30            Val::make_js_function(|_| {
31                let oscillator = Val::global("oscillator");
32                let context = Val::global("context");
33                println!("Playing");
34                oscillator.call("connect", &argv![context.get("destination")]);
35                oscillator.call("start", &argv![0]);
36                println!("All done!");
37                Val::undefined().as_handle()
38            })
39        ],
40    );
41    body.call("appendChild", &argv![elem]);
42}
Source

pub fn as_i32(&self) -> i32

Examples found in repository?
examples/dom.rs (line 15)
3fn main() {
4    let document = Val::global("document");
5    let elem = document.call("createElement", &argv!["BUTTON"]);
6    elem.set(&"textContent", Val::from("Click"));
7    let body = document.call("getElementsByTagName", &argv!["body"]).at(0);
8    elem.call(
9        "addEventListener",
10        &argv![
11            "click",
12            Val::make_js_function(|ev| {
13                let console = Val::global("console");
14                console.call("clear", &[]);
15                println!("client x: {}", Val::from_handle(ev).get("clientX").as_i32());
16                println!("hello from Rust");
17                Val::undefined().as_handle()
18            })
19        ],
20    );
21    body.call("appendChild", &argv![elem]);
22}
Source

pub fn as_bool(&self) -> bool

Examples found in repository?
examples/audio.rs (line 6)
3fn main() {
4    #[allow(non_snake_case)]
5    let mut AudioContext = Val::global("AudioContext");
6    if !AudioContext.as_bool() {
7        println!("No global AudioContext, trying webkitAudioContext");
8        AudioContext = Val::global("webkitAudioContext");
9    }
10
11    println!("Got an AudioContext");
12    let context = AudioContext.new(&[]);
13    let oscillator = context.call("createOscillator", &[]);
14
15    println!("Configuring oscillator");
16    oscillator.set("type", Val::from("triangle"));
17    oscillator.get("frequency").set("value", Val::from(261.63)); // Middle C
18
19    Val::global_this().set("oscillator", oscillator);
20    Val::global_this().set("context", context);
21
22    let document = Val::global("document");
23    let elem = document.call("createElement", &argv!["BUTTON"]);
24    elem.set(&"textContent", Val::from("Click"));
25    let body = document.call("getElementsByTagName", &argv!["body"]).at(0);
26    elem.call(
27        "addEventListener",
28        &argv![
29            "click",
30            Val::make_js_function(|_| {
31                let oscillator = Val::global("oscillator");
32                let context = Val::global("context");
33                println!("Playing");
34                oscillator.call("connect", &argv![context.get("destination")]);
35                oscillator.call("start", &argv![0]);
36                println!("All done!");
37                Val::undefined().as_handle()
38            })
39        ],
40    );
41    body.call("appendChild", &argv![elem]);
42}
Source

pub fn as_f64(&self) -> f64

Source

pub fn as_string(&self) -> String

Source

pub fn to_vec_i32(&self) -> Vec<i32>

Source

pub fn to_vec_f64(&self) -> Vec<f64>

Source

pub fn call(&self, f: &str, args: &[Val]) -> Val

Examples found in repository?
examples/dom.rs (line 5)
3fn main() {
4    let document = Val::global("document");
5    let elem = document.call("createElement", &argv!["BUTTON"]);
6    elem.set(&"textContent", Val::from("Click"));
7    let body = document.call("getElementsByTagName", &argv!["body"]).at(0);
8    elem.call(
9        "addEventListener",
10        &argv![
11            "click",
12            Val::make_js_function(|ev| {
13                let console = Val::global("console");
14                console.call("clear", &[]);
15                println!("client x: {}", Val::from_handle(ev).get("clientX").as_i32());
16                println!("hello from Rust");
17                Val::undefined().as_handle()
18            })
19        ],
20    );
21    body.call("appendChild", &argv![elem]);
22}
More examples
Hide additional examples
examples/audio.rs (line 13)
3fn main() {
4    #[allow(non_snake_case)]
5    let mut AudioContext = Val::global("AudioContext");
6    if !AudioContext.as_bool() {
7        println!("No global AudioContext, trying webkitAudioContext");
8        AudioContext = Val::global("webkitAudioContext");
9    }
10
11    println!("Got an AudioContext");
12    let context = AudioContext.new(&[]);
13    let oscillator = context.call("createOscillator", &[]);
14
15    println!("Configuring oscillator");
16    oscillator.set("type", Val::from("triangle"));
17    oscillator.get("frequency").set("value", Val::from(261.63)); // Middle C
18
19    Val::global_this().set("oscillator", oscillator);
20    Val::global_this().set("context", context);
21
22    let document = Val::global("document");
23    let elem = document.call("createElement", &argv!["BUTTON"]);
24    elem.set(&"textContent", Val::from("Click"));
25    let body = document.call("getElementsByTagName", &argv!["body"]).at(0);
26    elem.call(
27        "addEventListener",
28        &argv![
29            "click",
30            Val::make_js_function(|_| {
31                let oscillator = Val::global("oscillator");
32                let context = Val::global("context");
33                println!("Playing");
34                oscillator.call("connect", &argv![context.get("destination")]);
35                oscillator.call("start", &argv![0]);
36                println!("All done!");
37                Val::undefined().as_handle()
38            })
39        ],
40    );
41    body.call("appendChild", &argv![elem]);
42}
Source

pub fn new(&self, args: &[Val]) -> Val

Examples found in repository?
examples/audio.rs (line 12)
3fn main() {
4    #[allow(non_snake_case)]
5    let mut AudioContext = Val::global("AudioContext");
6    if !AudioContext.as_bool() {
7        println!("No global AudioContext, trying webkitAudioContext");
8        AudioContext = Val::global("webkitAudioContext");
9    }
10
11    println!("Got an AudioContext");
12    let context = AudioContext.new(&[]);
13    let oscillator = context.call("createOscillator", &[]);
14
15    println!("Configuring oscillator");
16    oscillator.set("type", Val::from("triangle"));
17    oscillator.get("frequency").set("value", Val::from(261.63)); // Middle C
18
19    Val::global_this().set("oscillator", oscillator);
20    Val::global_this().set("context", context);
21
22    let document = Val::global("document");
23    let elem = document.call("createElement", &argv!["BUTTON"]);
24    elem.set(&"textContent", Val::from("Click"));
25    let body = document.call("getElementsByTagName", &argv!["body"]).at(0);
26    elem.call(
27        "addEventListener",
28        &argv![
29            "click",
30            Val::make_js_function(|_| {
31                let oscillator = Val::global("oscillator");
32                let context = Val::global("context");
33                println!("Playing");
34                oscillator.call("connect", &argv![context.get("destination")]);
35                oscillator.call("start", &argv![0]);
36                println!("All done!");
37                Val::undefined().as_handle()
38            })
39        ],
40    );
41    body.call("appendChild", &argv![elem]);
42}
Source

pub fn invoke(&self, args: &[Val]) -> Val

Source

pub fn await_(&self) -> Val

Source

pub fn instanceof(&self, v: Val) -> bool

Trait Implementations§

Source§

impl Clone for Console

Source§

fn clone(&self) -> Console

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Console

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Deref for Console

Source§

type Target = Val

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl DerefMut for Console

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
Source§

impl Copy for Console

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.