Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// Type output by wasm-bindgen to the .d.ts bindings. No JS code is generated, just type definitions
export type ControllerCommand =
| { "Keypress": { key_code: number, meta_key: boolean, shift_key: boolean, alt_key: boolean, } }
| { "Button": { button: number, } }
| { "Character": { char_code: number, } }
| { "InsertText": { text: string, } }
| { "RenameGroup": { tag: string, curspan: any, } }
| { "Cursor": { focus: any, anchor: any, } }
| { "RandomTarget": { position: number, } }
| { "Monkey": { enabled: boolean, } }
;
// Export type of this enum to typescript (and nothing else)
// Note that if you remove the "tagged_union" annotation, wasm-bindgen only supports C-style enums, so this would no longer compile
#[wasm_bindgen(tagged_union)]
#[derive(Clone, Serialize, Deserialize, Debug, PartialEq)]
pub enum ControllerCommand {
// Connect(String),
Keypress {
key_code: u32,
meta_key: bool,
shift_key: bool,
alt_key: bool,
},
Button {
button: u32
},
Character {
char_code: u32,
},
InsertText {
text: String,
},
RenameGroup {
tag: String,
curspan: JsonEncodable<CurSpan>,
},
// Load(DocSpan),
Cursor {
focus: JsonEncodable<Option<CurSpan>>,
anchor: JsonEncodable<Option<CurSpan>>,
},
// Target(CurSpan),
RandomTarget {
position: f64,
},
Monkey {
enabled: bool,
},
}
// vvvv supporting classes for specifying opaque "any" type that can be serialized with serde still
#[derive(Serialize, Deserialize, PartialEq, Eq, Debug, Clone)]
pub struct JsonEncodable<T>(T);
impl<T> WasmDescribe for JsonEncodable<T> {
fn describe() {
JsValue::describe();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.