Skip to content

Commit

Permalink
Add constructors to some WASM structs (#1147)
Browse files Browse the repository at this point in the history
  • Loading branch information
rygine authored Oct 17, 2024
1 parent 9db28f6 commit 79904ae
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions bindings_wasm/src/encoded_content.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,24 @@ pub struct WasmContentTypeId {
pub version_minor: u32,
}

#[wasm_bindgen]
impl WasmContentTypeId {
#[wasm_bindgen(constructor)]
pub fn new(
authority_id: String,
type_id: String,
version_major: u32,
version_minor: u32,
) -> WasmContentTypeId {
WasmContentTypeId {
authority_id,
type_id,
version_major,
version_minor,
}
}
}

impl From<ContentTypeId> for WasmContentTypeId {
fn from(content_type_id: ContentTypeId) -> WasmContentTypeId {
WasmContentTypeId {
Expand Down Expand Up @@ -44,6 +62,26 @@ pub struct WasmEncodedContent {
pub content: Uint8Array,
}

#[wasm_bindgen]
impl WasmEncodedContent {
#[wasm_bindgen(constructor)]
pub fn new(
r#type: Option<WasmContentTypeId>,
parameters: JsValue,
fallback: Option<String>,
compression: Option<i32>,
content: Uint8Array,
) -> WasmEncodedContent {
WasmEncodedContent {
r#type,
parameters,
fallback,
compression,
content,
}
}
}

impl From<EncodedContent> for WasmEncodedContent {
fn from(content: EncodedContent) -> WasmEncodedContent {
let r#type = content.r#type.map(|v| v.into());
Expand Down

0 comments on commit 79904ae

Please sign in to comment.