Skip to content

Commit cf21df6

Browse files
Use structs with empty byte array fields for opaque types
Using empty enums could potentially cause undefined behavior
1 parent 52709fd commit cf21df6

File tree

4 files changed

+16
-4
lines changed

4 files changed

+16
-4
lines changed

src/audio/sound_buffer.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,10 @@ use std::slice;
6161
/// [`Sound`]: crate::audio::Sound
6262
#[derive(Debug)]
6363
#[allow(missing_copy_implementations)]
64-
pub enum SoundBuffer {}
64+
#[repr(C)]
65+
pub struct SoundBuffer {
66+
_opaque: [u8; 0],
67+
}
6568

6669
impl SoundBuffer {
6770
/// Save a sound buffer to an audio file

src/graphics/font.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,10 @@ use std::io::{Read, Seek};
5151
/// [`Text`]: crate::graphics::Text
5252
#[derive(Debug)]
5353
#[allow(missing_copy_implementations)]
54-
pub enum Font {}
54+
#[repr(C)]
55+
pub struct Font {
56+
_opaque: [u8; 0],
57+
}
5558

5659
impl Font {
5760
/// Get the kerning value corresponding to a given pair of characters in a font

src/graphics/texture.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,10 @@ use std::ptr;
4949
/// [`Color`]: crate::graphics::Color
5050
#[derive(Debug)]
5151
#[allow(missing_copy_implementations)]
52-
pub enum Texture {}
52+
#[repr(C)]
53+
pub struct Texture {
54+
_opaque: [u8; 0],
55+
}
5356

5457
impl Texture {
5558
/// Return the size of the texture

src/graphics/view.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ use std::borrow::ToOwned;
1010
/// the way that your drawable objects are drawn.
1111
#[derive(Debug)]
1212
#[allow(missing_copy_implementations)]
13-
pub enum View {}
13+
#[repr(C)]
14+
pub struct View {
15+
_opaque: [u8; 0],
16+
}
1417

1518
impl View {
1619
/// Get the current orientation of a view

0 commit comments

Comments
 (0)