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

Seal the HasContext trait #280

Merged
merged 1 commit into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
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
8 changes: 7 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ pub enum CompressedPixelUnpackData<'a> {
Slice(&'a [u8]),
}

pub trait HasContext {
pub trait HasContext : __private::Sealed {
type Shader: Copy + Clone + Debug + Eq + Hash + Ord + PartialEq + PartialOrd;
type Program: Copy + Clone + Debug + Eq + Hash + Ord + PartialEq + PartialOrd;
type Buffer: Copy + Clone + Debug + Eq + Hash + Ord + PartialEq + PartialOrd;
Expand Down Expand Up @@ -4175,3 +4175,9 @@ pub const XOR: u32 = 0x1506;
pub const ZERO: u32 = 0;

pub const ZERO_TO_ONE: u32 = 0x935F;

mod __private {
/// Prevents [`HasContext`] from being implemented outside of this crate.
#[doc(hidden)]
pub trait Sealed {}
}
2 changes: 2 additions & 0 deletions src/native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ pub struct NativeUniformLocation(pub native_gl::GLuint);
#[derive(Copy, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub struct NativeTransformFeedback(pub NonZeroU32);

impl crate::__private::Sealed for Context {}

impl HasContext for Context {
type Shader = NativeShader;
type Program = NativeProgram;
Expand Down
2 changes: 2 additions & 0 deletions src/web_sys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1359,6 +1359,8 @@ new_key_type! { pub struct WebRenderbufferKey; }
new_key_type! { pub struct WebQueryKey; }
new_key_type! { pub struct WebTransformFeedbackKey; }

impl crate::__private::Sealed for Context {}

impl HasContext for Context {
type Shader = WebShaderKey;
type Program = WebProgramKey;
Expand Down
Loading