Skip to content

Commit

Permalink
Represent C opaque structs as enums
Browse files Browse the repository at this point in the history
  • Loading branch information
crumblingstatue committed Aug 16, 2015
1 parent 41d07dd commit e7a0a7f
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 71 deletions.
12 changes: 4 additions & 8 deletions src/ffi/audio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ pub mod music {
use ffi::audio::sound_status::sfSoundStatus;
use ffi::sfml_types::SfBool;

#[repr(C)]
pub struct sfMusic;
pub enum sfMusic {}

extern "C" {
pub fn sfMusic_createFromFile(filename: *const c_char) -> *mut sfMusic;
Expand Down Expand Up @@ -92,8 +91,7 @@ pub mod sound {
use ffi::system::time::sfTime;
use ffi::sfml_types::SfBool;

#[repr(C)]
pub struct sfSound;
pub enum sfSound {}

extern "C" {
pub fn sfSound_create() -> *mut sfSound;
Expand Down Expand Up @@ -130,8 +128,7 @@ pub mod sound_buffer {
use ffi::system::time::sfTime;
use ffi::sfml_types::SfBool;

#[repr(C)]
pub struct sfSoundBuffer;
pub enum sfSoundBuffer {}

extern "C" {
pub fn sfSoundBuffer_createFromFile(filename: *const c_char) -> *mut sfSoundBuffer;
Expand All @@ -152,8 +149,7 @@ pub mod sound_buffer_recorder {
use ffi::audio::sound_buffer::sfSoundBuffer;
use ffi::sfml_types::SfBool;

#[repr(C)]
pub struct sfSoundBufferRecorder;
pub enum sfSoundBufferRecorder {}

extern "C" {
pub fn sfSoundBufferRecorder_create() -> *mut sfSoundBufferRecorder;
Expand Down
45 changes: 15 additions & 30 deletions src/ffi/graphics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ pub mod render_window {
use ffi::graphics::vertex_array::sfVertexArray;
use ffi::sfml_types::SfBool;

#[repr(C)]
pub struct sfRenderWindow;
pub enum sfRenderWindow {}

extern "C" {
pub fn sfRenderWindow_create(mode: sfVideoMode, title: *const c_char, style: c_uint, settings: *const ContextSettings) -> *mut sfRenderWindow;
Expand Down Expand Up @@ -107,8 +106,7 @@ pub mod circle_shape {
use ffi::graphics::texture::sfTexture;
use ffi::sfml_types::SfBool;

#[repr(C)]
pub struct sfCircleShape;
pub enum sfCircleShape {}

extern "C" {
pub fn sfCircleShape_create() -> *mut sfCircleShape;
Expand Down Expand Up @@ -169,8 +167,7 @@ pub mod convex_shape {
use ffi::graphics::texture::sfTexture;
use ffi::sfml_types::SfBool;

#[repr(C)]
pub struct sfConvexShape;
pub enum sfConvexShape {}

extern "C" {
pub fn sfConvexShape_create() -> *mut sfConvexShape;
Expand Down Expand Up @@ -217,8 +214,7 @@ pub mod font {
use ffi::sfml_types::SfBool;
use system::inputstream::InputStream as sfInputStream;

#[repr(C)]
pub struct sfFont;
pub enum sfFont {}

extern "C" {
pub fn sfFont_createFromFile(filename: *const c_char) -> *mut sfFont;
Expand All @@ -242,8 +238,7 @@ pub mod image {

use ffi::sfml_types::SfBool;

#[repr(C)]
pub struct sfImage;
pub enum sfImage {}

extern "C" {
pub fn sfImage_create(width: c_uint, height: c_uint) -> *mut sfImage;
Expand Down Expand Up @@ -289,8 +284,7 @@ pub mod rectangle_shape {
use ffi::graphics::texture::sfTexture;
use ffi::sfml_types::SfBool;

#[repr(C)]
pub struct sfRectangleShape;
pub enum sfRectangleShape {}

extern "C" {
pub fn sfRectangleShape_create() -> *mut sfRectangleShape;
Expand Down Expand Up @@ -355,8 +349,7 @@ pub mod shader {
use ffi::graphics::texture::sfTexture;
use ffi::sfml_types::SfBool;

#[repr(C)]
pub struct sfShader;
pub enum sfShader {}

extern "C" {
pub fn sfShader_createFromFile(vertexShaderFilename: *const c_char, fragmentShaderFilename: *const c_char) -> *mut sfShader;
Expand Down Expand Up @@ -397,8 +390,7 @@ pub mod render_texture {
use ffi::graphics::view::sfView;
use ffi::sfml_types::SfBool;

#[repr(C)]
pub struct sfRenderTexture;
pub enum sfRenderTexture {}

extern "C" {
pub fn sfRenderTexture_create(width: c_uint, height: c_uint, depthBuffer: SfBool) -> *mut sfRenderTexture;
Expand Down Expand Up @@ -440,8 +432,7 @@ pub mod shape {
use ffi::graphics::texture::sfTexture;
use ffi::sfml_types::SfBool;

#[repr(C)]
pub struct sfShape;
pub enum sfShape {}

extern "C" {
pub fn sfShape_create(getPointCount: extern "C" fn(*mut c_void) -> u32, getPoint: extern "C" fn(u32, *mut c_void) -> Vector2f, userData: *mut c_void) -> *mut sfShape;
Expand Down Expand Up @@ -487,8 +478,7 @@ pub mod sprite {
use ffi::graphics::texture::sfTexture;
use ffi::sfml_types::SfBool;

#[repr(C)]
pub struct sfSprite;
pub enum sfSprite {}

extern "C" {
pub fn sfSprite_create() -> *mut sfSprite;
Expand Down Expand Up @@ -526,8 +516,7 @@ pub mod text {

use ffi::graphics::font::sfFont;

#[repr(C)]
pub struct sfText;
pub enum sfText {}

extern "C" {
pub fn sfText_create() -> *mut sfText;
Expand Down Expand Up @@ -577,8 +566,7 @@ pub mod texture {
use ffi::window::window::sfWindow;
use ffi::sfml_types::SfBool;

#[repr(C)]
pub struct sfTexture;
pub enum sfTexture {}

extern "C" {
pub fn sfTexture_create(width: c_uint, height: c_uint) -> *mut sfTexture;
Expand Down Expand Up @@ -632,8 +620,7 @@ pub mod transformable {
use system::vector2::Vector2f;
use graphics::Transform;

#[repr(C)]
pub struct sfTransformable;
pub enum sfTransformable {}

extern "C" {
pub fn sfTransformable_create() -> *mut sfTransformable;
Expand Down Expand Up @@ -670,8 +657,7 @@ pub mod vertex_array {
pub const SFTRIANGLESFAN: sfPrimitiveType = 5;
pub const SFQUADS: sfPrimitiveType = 6;

#[repr(C)]
pub struct sfVertexArray;
pub enum sfVertexArray {}

extern "C" {
pub fn sfVertexArray_create() -> *mut sfVertexArray;
Expand All @@ -695,8 +681,7 @@ pub mod view {
use system::vector2::Vector2f;
use graphics::FloatRect;

#[repr(C)]
pub struct sfView;
pub enum sfView {}

extern "C" {
pub fn sfView_create() -> *mut sfView;
Expand Down
38 changes: 11 additions & 27 deletions src/ffi/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ pub mod packet {

use ffi::sfml_types::SfBool;

#[repr(C)]
pub struct sfPacket;
pub enum sfPacket {}

extern "C" {
pub fn sfPacket_create() -> *mut sfPacket;
Expand Down Expand Up @@ -118,8 +117,7 @@ pub mod tcp_listener {
use ffi::network::socket_status::SocketStatus;
use ffi::sfml_types::SfBool;

#[repr(C)]
pub struct sfTcpListener;
pub enum sfTcpListener {}

extern "C" {
pub fn sfTcpListener_create() -> *mut sfTcpListener;
Expand All @@ -141,8 +139,7 @@ pub mod tcp_socket {
use ffi::network::packet::sfPacket;
use ffi::sfml_types::SfBool;

#[repr(C)]
pub struct sfTcpSocket;
pub enum sfTcpSocket {}

extern "C" {
pub fn sfTcpSocket_create() -> *mut sfTcpSocket;
Expand Down Expand Up @@ -170,8 +167,7 @@ pub mod udp_socket {
use ffi::network::packet::sfPacket;
use ffi::sfml_types::SfBool;

#[repr(C)]
pub struct sfUdpSocket;
pub enum sfUdpSocket {}

extern "C" {
pub fn sfUdpSocket_create() -> *mut sfUdpSocket;
Expand Down Expand Up @@ -251,17 +247,10 @@ pub mod ftp {
pub const CONNECTIONCLOSED: Status = 1002;
pub const INVALIDFILE: Status = 1003;

#[repr(C)]
pub struct sfFtp;

#[repr(C)]
pub struct sfFtpDirectoryResponse;

#[repr(C)]
pub struct sfFtpListingResponse;

#[repr(C)]
pub struct sfFtpResponse;
pub enum sfFtp {}
pub enum sfFtpDirectoryResponse {}
pub enum sfFtpListingResponse {}
pub enum sfFtpResponse {}

extern "C" {
pub fn sfFtpListingResponse_destroy(ftpListingResponse: *mut sfFtpListingResponse);
Expand Down Expand Up @@ -339,14 +328,9 @@ pub mod http {
pub const INVALIDRESPONSE: Status = 1000;
pub const CONNECTIONFAILED: Status = 1001;

#[repr(C)]
pub struct sfHttpRequest;

#[repr(C)]
pub struct sfHttpResponse;

#[repr(C)]
pub struct sfHttp;
pub enum sfHttpRequest {}
pub enum sfHttpResponse {}
pub enum sfHttp {}

extern "C" {
pub fn sfHttpRequest_create() -> *mut sfHttpRequest;
Expand Down
3 changes: 1 addition & 2 deletions src/ffi/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@
pub mod clock {
use ffi::system::time::sfTime;

#[repr(C)]
pub struct sfClock;
pub enum sfClock {}

extern "C" {
pub fn sfClock_create() -> *mut sfClock;
Expand Down
6 changes: 2 additions & 4 deletions src/ffi/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ pub mod window {
use ffi::window::video_mode::sfVideoMode;
use ffi::sfml_types::SfBool;

#[repr(C)]
pub struct sfWindow;
pub enum sfWindow {}

extern "C" {
pub fn sfWindow_create(mode: sfVideoMode, title: *const c_char, style: c_uint, settings: *const ContextSettings) -> *mut sfWindow;
Expand Down Expand Up @@ -68,8 +67,7 @@ pub mod window {
pub mod context {
use ffi::sfml_types::SfBool;

#[repr(C)]
pub struct sfContext;
pub enum sfContext {}

extern "C" {
pub fn sfContext_create() -> *mut sfContext;
Expand Down

0 comments on commit e7a0a7f

Please sign in to comment.