foobarF
Denoβ€’3y agoβ€’
2 replies
foobar

WASM / Extract and manipulate Array of Date

I try to extract and manipulate an array of date in a function

The rust fn doesn't compile. How to manipulate Date and convert it ?

Does someone have a repository/link with example of Rust + Deno library ?

Cargo.toml
[dependencies]
wasm-bindgen = "=0.2.87"
time = { version = "0.3", features = ["parsing", "macros"] }
js-sys = "0.3.64"


mod.ts
import { instantiate } from "./lib/rs_lib.generated.js";

const { DateArrayToString } = await instantiate();

console.log(DateArrayToString( [new Date(2015, 11, 1 ), new Date(2016, 7, 1 ), new Date(2016, 7, 19 )]))


lib.rs
use wasm_bindgen::prelude::*;

use js_sys::Array;
use js_sys::Date;

#[wasm_bindgen]
pub fn DateArrayToString(arr:Array) -> JsString {
    let result : JsString;
    for i in 0..arr.length() {
        // problem is here
        let d : Date = arr.get(i).as_ref();
        // Concat
        result = result.concat(d.to_string());
    }
    return result;
}
Was this page helpful?