<p align="center">
<img src="info/logo.png">
</p>
[![Build Status](https://api.travis-ci.org/koute/stdweb.svg)](https://travis-ci.org/koute/stdweb)
# A standard library for the client-side Web
[![Documentation](https://docs.rs/stdweb/badge.svg)](https://docs.rs/stdweb/*/stdweb/)
The goal of this crate is to provide Rust bindings to the Web APIs and to allow
a high degree of interoperability between Rust and JavaScript.
## Examples
You can directly embed JavaScript code into Rust:
```rust
let message = "Hello, 世界!";
let result = js! {
alert( @{message} );
return 2 + 2 * 2;
};
println!( "2 + 2 * 2 = {:?}", result );
```
Even closures are supported:
```rust
let print_hello = |name: String| {
println!( "Hello, {}!", name );
};
js! {
var print_hello = @{print_hello};
print_hello( "Bob" );
print_hello.drop(); // Necessary to clean up the closure on Rust's side.
}
```
You can also pass arbitrary structures thanks to [serde]:
```rust
#[derive(Serialize)]
struct Person {
name: String,
age: i32
}
js_serializable!( Person );
js! {
var person = @{person};
console.log( person.name + " is " + person.age + " years old." );
};
```
[serde]: https://serde.rs/
This crate also exposes a number of Web APIs, for example:
```rust
let button = document().query_selector( "#hide-button" ).unwrap();