let's say I have a Struct
like this.
Struct MyStruct {
my_variable:bool
}
and an impl
impl MyStruct {
pub fn new() {
Self::my_variable = true; //Error
}
}
gives me
no function or associated item named
my_variable
found for structMyStruct
in the current scope
My goal here is to set an event callback to pass as an argument of a method from web_sys
;
basically I would like to convert this typescript class/behaviour to Rust
class Peer {
makingOffer = false;
peer:RTCPeerConnection
constructor() {
this.peer = new RTCPeerConnection();
this.peer.onnegotiationneeded = this.onNegotiationNeeded
}
onNegotiationNeeded = async () => {
this.makingOffer = true;
}
}
and here is my Rust implementation
Struct Peer {
peer:RtcPeerConnection
making_offer:bool
}
impl Peer {
pub fn new() -> Self {
let making_offer = false;
let peer: RtcPeerConnection= RtcPeerConnection::new().expect("failed to construct new peer connection");
peer.set_onnegotiationneeded(/*callback should go here*/);
Peer {
peer,
making_offer
}
}
}
I'm really new to rust and come from javascript where this kind of behaviour is fairly simple to me, so I don't master all of the code I wrote but some of it is taken from the wasm bingen
tutorials.