2个不稳定版本
0.2.0 | 2018年9月26日 |
---|---|
0.1.0 | 2018年9月10日 |
#679 in 过程宏
41KB
763 行
WURST
Webby DOM抽象 web-sys。
项目目标
- 封装所有DOM API并提供一个易于使用的库
- 提供前端代码的编译时检查。
- 提供运行时检查的逃生口。
- 在DOM之上提供零成本的抽象
设置
目前此代码仅与nightly和最新的wasm-bindgen进行了测试。
鉴于我们目前处于未发布状态,请确保您有最新的wasm-bindgen二进制文件
rustup update
cargo install -f wasm-bindgen-cli
以启用格式化的生成代码
export WEBIDL_RUSTFMT_BINDINGS=1;
我目前也只在nightly上进行了检查。其他构建可能也可以工作。
示例
运行演示服务器
cd examples/form-example/;
source build.sh
用法
当前库的用法
let mut div = create_element!("div", {
// Element interface
id: "Boop",
// HTMLElement interface
title: "hey I am a title",
lang: "en-GB"
});
div.create();
div.add_to_body();
let mut input = create_element!("input", {
// Element interface
id: "Boop",
// Input interface
value: "hey!",
// HTMLElement interface
title: "2323",
lang: "boom"
});
input.create();
input.add_to_body();
input.attrs.id = Some("boo".into());
input.update();
上面的代码内部会返回一个实现Elementish
字段特质的El
。具体类型分别是DivElement
和InputElement
。
宏只会接受具体接口所接受的参数。因此,如果向宏提供了错误元素属性,则会在编译时失败。
error[E0560]: struct `wurst::elements::DivElement` has no field named `value`
--> src/main.rs:20:9
|
20 | value: "my value"
| ^^^^^ `wurst::elements::DivElement` does not have this field
|
= note: available fields are: `title`, `lang`, `dir`, `inner_text`, `access_key` ... and 3 others
error: aborting due to previous error
许可证
以下任一许可证下授权:
- Apache许可证,版本2.0 (LICENSE-APACHE 或 https://apache.ac.cn/licenses/LICENSE-2.0)
- MIT许可证 (LICENSE-MIT 或 http://opensource.org/licenses/MIT)
任由您选择。
贡献
除非您明确表示,否则您提交给作品以供包含的任何贡献,根据Apache-2.0许可证的定义,均应按上述方式双许可,而不附加任何额外条款或条件。
依赖项
~6.5–9MB
~173K SLoC