mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-06-22 17:21:35 +00:00
Copy doc comments from Rust to JS (#265)
* backend comments complete * better matching * gen comments * Add example * Move test bindings gen to own fn * move build step into build fn * add fn to read js, refactor gen_bindings/test to allow for this * Add comments test * Update readmes * add comments to travis * fix broken tests * +x on build.sh * fix wbg cmd in build.sh * Address fitzgen's comments
This commit is contained in:
committed by
Nick Fitzgerald
parent
3ad9bac599
commit
19d6cf1488
60
examples/comments/src/lib.rs
Normal file
60
examples/comments/src/lib.rs
Normal file
@ -0,0 +1,60 @@
|
||||
#![feature(proc_macro, wasm_custom_section, wasm_import_module)]
|
||||
|
||||
extern crate wasm_bindgen;
|
||||
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
#[wasm_bindgen]
|
||||
/// A user defined comment
|
||||
pub struct Comment {
|
||||
name: String,
|
||||
comment: String,
|
||||
/// The position this comment
|
||||
/// should exist at
|
||||
pub count: u32,
|
||||
color: Color,
|
||||
}
|
||||
|
||||
|
||||
#[wasm_bindgen]
|
||||
impl Comment {
|
||||
#[wasm_bindgen(method)]
|
||||
/// The name of the user who
|
||||
/// posted this comment
|
||||
pub fn name(&self) -> String {
|
||||
self.name.clone()
|
||||
}
|
||||
#[wasm_bindgen(method)]
|
||||
/// The content of this comment
|
||||
pub fn comment(&self) -> String {
|
||||
self.comment.clone()
|
||||
}
|
||||
|
||||
#[wasm_bindgen(constructor)]
|
||||
pub fn new(name: String, comment: String, count: u32) -> Comment {
|
||||
let color = if count % 2 == 0 {
|
||||
Color::Blue
|
||||
} else {
|
||||
Color::Pink
|
||||
};
|
||||
Comment {
|
||||
name,
|
||||
comment,
|
||||
count,
|
||||
color,
|
||||
}
|
||||
}
|
||||
#[wasm_bindgen(method)]
|
||||
/// What color should this comment be
|
||||
pub fn color(&self) -> Color {
|
||||
self.color.clone()
|
||||
}
|
||||
}
|
||||
|
||||
/// The border of a comment
|
||||
#[wasm_bindgen]
|
||||
#[derive(Clone)]
|
||||
pub enum Color {
|
||||
Blue,
|
||||
Pink,
|
||||
}
|
Reference in New Issue
Block a user