Instancing Rust Structs in JS and maintaining a list of them in Rust
I am struggling to create an extensions for
deno_core
that would allow me to create Rust Struct instances via JavaScript, but maintain those instances in Rust. What I mean is this:
I have a Rust Struct called Rect that I use as a Resource in deno.
For the sake of brevity I will reduce its fields in this example to two coordinates, top and left:
Now I have an op
to create a rect and add it to a Vec
, a List of Rect
s in Rust, for me to keep score and do stuff with those rects.
Now that does not really really work. op2
is missing GarbageCollected on the Arc
Mutex
, but I also (think I) need that because I will reference and mutate it in JS and also want to reference it in Rust.
My goal is to have that Struct as object in JavaScript and be able to create and mutate it there while also be able to use all instances in Rust at any given time.
Any help on how to do that is very appreaciated.0 Replies