Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make cast_event unsafe #78

Closed
maxbla opened this issue Apr 11, 2020 · 1 comment
Closed

Make cast_event unsafe #78

maxbla opened this issue Apr 11, 2020 · 1 comment

Comments

@maxbla
Copy link

maxbla commented Apr 11, 2020

/// Casts the generic event to the right event. Assumes that the given
/// event is really the correct type.
pub fn cast_event<'r, T>(event : &'r GenericEvent) -> &'r T {
    // This isn't very safe... but other options incur yet more overhead
    // that I really don't want to.
    unsafe { mem::transmute(event) }
}

This is the code for cast_event(). Safe functions should (almost?) always be safe, no matter their arguments. My suggested fix is to change it to

pub unsafe fn cast_event<'r, T>(event : &'r GenericEvent) -> &'r T {
    mem::transmute(event)
}

This signals to callers that they have to be careful when calling cast_event.

@rtbo
Copy link
Collaborator

rtbo commented Nov 7, 2021

cast_event is unsafe since 0.8.0.

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

No branches or pull requests

2 participants