Last active
November 15, 2018 20:11
-
-
Save tcr/9984ab3755c8a40788c985dc85d7ef18 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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, } } | |
; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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