Skip to content

Add Rust implementation of CLASS#101

Closed
Peter9192 wants to merge 3 commits intomainfrom
rust
Closed

Add Rust implementation of CLASS#101
Peter9192 wants to merge 3 commits intomainfrom
rust

Conversation

@Peter9192
Copy link
Copy Markdown
Member

@Peter9192 Peter9192 commented Jan 15, 2025

I played around with the Rust+WebAssembly book/tutorial.

On build, a nice js/wasm package is created that can be used in the web app. It includes a class-rust.d.ts type definition file which should hopefully make for a smooth integration with the ts code.

To do:

Notes:

  • It probably makes sense to implement the run method in the client outside of Bmi(Light), as it returns a complex type that's hard to transfer between rust/ts. The same was seen in Running a python model instead #100
  • Would be useful to add update_until so you can update until next output time, that will reduce calls back and forth
  • Rust code is quite prone to duplication, e.g. each variable that must be availabe via get value is defined four times (on the type, in the constructor, in the getter, and possibly also in an enum for get_output_var_names). This could be optimized by using macros.
  • Local dev server doesn't appreciate being put in bg job with this branch
  • I was annoyed with the Option type in rust (having to always use .as_ref() or as_mut and expect(...), which made the code ugly and unreadable), so I spent some effort writing a wrapper around it with a default panic message. This is also due to the annoying fact that in BMI, the Model and Config are only set on initialize() call rather than in constructor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant