You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I think this "unsafe" is useless here, and the method is actually safe:
#[inline]/// Create a new `Window` without taking ownership of the `WindowContext`pubconstunsafefnfrom_ref(context:Rc<WindowContext>) -> Window{Window{ context }}
Having it is unsafe:
Is not useful.
It may confuse people who don't read. Go deeper to read the code.
It may lead to people seeing it preferring not to store the Rc<WindowContext> but to have a double indirection and reference counting: Rc<Window> which internally has Rc<WindowContext> for no reason but to avoid unsafe calls.
Another thing to improve is:
pubstructWindow{context:Rc<WindowContext>}
This struct can easily derive Clone due to having Rc inside; why doesn't it do so? Now, if we want to have the rich interface of Window, we must either keep it reference counted (Rc<Window>) or store the Rc<WindowContext> and create the Window object back from it when we need to use it: Window::from_ref(window_context). I think this experience is suboptimal and doesn't bring any benefit.
If it is agreed to change in favour, there is a PR: #1368
The text was updated successfully, but these errors were encountered:
iddm
changed the title
Remove unsafe from Window::from_ref
Remove unsafe from Window::from_ref and make Window clonable.
Jan 26, 2024
iddm
added a commit
to iddm/rust-sdl2
that referenced
this issue
Jan 26, 2024
I think this "unsafe" is useless here, and the method is actually safe:
Having it is unsafe:
Rc<WindowContext>
but to have a double indirection and reference counting:Rc<Window>
which internally hasRc<WindowContext>
for no reason but to avoid unsafe calls.Another thing to improve is:
This struct can easily derive
Clone
due to havingRc
inside; why doesn't it do so? Now, if we want to have the rich interface ofWindow
, we must either keep it reference counted (Rc<Window>
) or store theRc<WindowContext>
and create theWindow
object back from it when we need to use it:Window::from_ref(window_context)
. I think this experience is suboptimal and doesn't bring any benefit.If it is agreed to change in favour, there is a PR: #1368
The text was updated successfully, but these errors were encountered: