#![doc(html_root_url = "https://docs.rs/wasm-bindgen-shared/0.2")] #[macro_use] extern crate serde_derive; // The schema is so unstable right now we just force it to change whenever this // package's version changes, which happens on all publishes. pub const SCHEMA_VERSION: &str = env!("CARGO_PKG_VERSION"); #[derive(Deserialize)] pub struct ProgramOnlySchema { pub schema_version: String, pub version: String, } #[derive(Deserialize, Serialize)] pub struct Program { pub exports: Vec, pub enums: Vec, pub imports: Vec, pub structs: Vec, pub version: String, pub schema_version: String, } #[derive(Deserialize, Serialize)] pub struct Import { pub module: Option, pub js_namespace: Option, pub kind: ImportKind, } #[derive(Deserialize, Serialize)] #[serde(tag = "kind", rename_all = "lowercase")] pub enum ImportKind { Function(ImportFunction), Static(ImportStatic), Type(ImportType), Enum(ImportEnum), } #[derive(Deserialize, Serialize)] pub struct ImportFunction { pub shim: String, pub catch: bool, pub variadic: bool, pub method: Option, pub structural: bool, pub function: Function, } #[derive(Deserialize, Serialize)] pub struct MethodData { pub class: String, pub kind: MethodKind, } #[derive(Deserialize, Serialize)] pub enum MethodKind { Constructor, Operation(Operation), } #[derive(Deserialize, Serialize)] pub struct Operation { pub is_static: bool, pub kind: OperationKind, } #[derive(Deserialize, Serialize)] pub enum OperationKind { Regular, Getter(String), Setter(String), IndexingGetter, IndexingSetter, IndexingDeleter, } #[derive(Deserialize, Serialize)] pub struct ImportStatic { pub name: String, pub shim: String, } #[derive(Deserialize, Serialize)] pub struct ImportType { pub name: String, pub instanceof_shim: String, } #[derive(Deserialize, Serialize)] pub struct ImportEnum {} #[derive(Deserialize, Serialize)] pub struct Export { pub class: Option, pub method: bool, pub consumed: bool, pub constructor: Option, pub function: Function, pub comments: Vec, } #[derive(Deserialize, Serialize)] pub struct Enum { pub name: String, pub variants: Vec, pub comments: Vec, } #[derive(Deserialize, Serialize)] pub struct EnumVariant { pub name: String, pub value: u32, } #[derive(Deserialize, Serialize)] pub struct Function { pub name: String, } #[derive(Deserialize, Serialize)] pub struct Struct { pub name: String, pub fields: Vec, pub comments: Vec, } #[derive(Deserialize, Serialize)] pub struct StructField { pub name: String, pub readonly: bool, pub comments: Vec, } pub fn new_function(struct_name: &str) -> String { let mut name = format!("__wbg_"); name.extend(struct_name.chars().flat_map(|s| s.to_lowercase())); name.push_str("_new"); return name; } pub fn free_function(struct_name: &str) -> String { let mut name = format!("__wbg_"); name.extend(struct_name.chars().flat_map(|s| s.to_lowercase())); name.push_str("_free"); return name; } pub fn free_function_export_name(function_name: &str) -> String { function_name.to_string() } pub fn struct_function_export_name(struct_: &str, f: &str) -> String { let mut name = struct_ .chars() .flat_map(|s| s.to_lowercase()) .collect::(); name.push_str("_"); name.push_str(f); return name; } pub fn struct_field_get(struct_: &str, f: &str) -> String { let mut name = String::from("__wbg_get_"); name.extend(struct_.chars().flat_map(|s| s.to_lowercase())); name.push_str("_"); name.push_str(f); return name; } pub fn struct_field_set(struct_: &str, f: &str) -> String { let mut name = String::from("__wbg_set_"); name.extend(struct_.chars().flat_map(|s| s.to_lowercase())); name.push_str("_"); name.push_str(f); return name; } pub fn version() -> String { let mut v = env!("CARGO_PKG_VERSION").to_string(); if let Some(s) = option_env!("WBG_VERSION") { v.push_str(" ("); v.push_str(s); v.push_str(")"); } return v; }