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 GraphicsContext::window_mut() an unsafe fn. #5

Merged
merged 1 commit into from
Aug 24, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,28 @@ impl<W: HasRawWindowHandle> GraphicsContext<W> {
})
}

/// Gets shared access to the underlying window
/// Gets shared access to the underlying window.
#[inline]
pub fn window(&self) -> &W {
&self.window
}

/// Gets mut/exclusive access to the underlying window
/// Gets mut/exclusive access to the underlying window.
///
/// This method is `unsafe` because it could be used to replace the window with another one,
/// thus dropping the original window and violating the property that this [`GraphicsContext`]
/// will always be destroyed before the window it writes into. This method should only be used
/// when the window type in use requires mutable access to perform some action on an existing
/// window.
///
/// # Safety
///
/// - After the returned mutable reference is dropped, the window must still be the same window
/// which this [`GraphicsContext`] was created for; and within that window, the
/// platform-specific configuration for 2D drawing must not have been modified. (For example,
/// on macOS the view hierarchy of the window must not have been modified.)
#[inline]
pub fn window_mut(&mut self) -> &mut W {
pub unsafe fn window_mut(&mut self) -> &mut W {
&mut self.window
}

Expand Down