Stream: general

Topic: ✔ Mutate resource self


view this post on Zulip Ari Seyhun (Mar 21 2022 at 07:17):

Paul Colomiets said:

You can use resource to keep state: https://github.com/bytecodealliance/wit-bindgen/blob/main/WIT.md#item-resource (or just use global/static variables in Rust).

I'm looking into using resources with the following .wit file:

resource aggregate {
  static new: function(id: string) -> aggregate
  apply-events: function(event: list<list<u8>>)
}

Which generates:

pub trait Aggregate {
    fn new(id: String,) -> wit_bindgen_rust::Handle<super::Aggregate>;
    fn apply_events(&self,event: Vec<Vec<u8>>,);
}

But using the online demo to see the generated rust code for export, the apply-events method takes &self. But what if I want to mutate self with &mut self? Is this possible?

view this post on Zulip Ari Seyhun (Mar 21 2022 at 13:40):

I've made a GH issue for it here:
https://github.com/bytecodealliance/wit-bindgen/issues/178

I'm looking into using resources with the following .wit file: resource aggregate { static new: function(id: string) -> aggregate apply-events: function(event: list<list<u8>>) } ...

view this post on Zulip Notification Bot (Mar 21 2022 at 15:16):

Ari Seyhun has marked this topic as resolved.


Last updated: Dec 23 2024 at 12:05 UTC