-
Notifications
You must be signed in to change notification settings - Fork 153
Add Typed Version of add_route. #242
Copy link
Copy link
Closed
Description
Currently add_route is defined as:
pub fn add_route(&self, receiver: OpaqueIpcReceiver, callback: RouterHandler);
pub type RouterHandler = Box<FnMut(OpaqueIpcMessage) + Send>;It is up to the user to remember and properly turn the OpaqueIpcMessage into the correct type. This leads to wrong types being used as in servo/servo#23818
Instead I recommend adding a typed version as:
pub fn add_route<T>(&self, receiver: IpcReceiver<T>, mut callback: RouterHandler<T>)The user no longer has to learn about OpaqueIpcReceiver and it is compile-time checked, so the type can never be used wrong! Internally, the implementation converts the OpaqueIpcMessage into T so it can never be misused:
|msg: OpaqueIpcMessage| callback(msg.to::<T>().unwrap());Eventually the existing add_route could be deprecated in favor of the typed one.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels