From b46f4b5ebb0807aab787f9aff8f4bf887e3a2dfb Mon Sep 17 00:00:00 2001 From: Machtan Date: Wed, 10 Feb 2016 11:09:08 +0100 Subject: [PATCH] Rename module 'util' to 'common' to better reflect its usage --- src/sdl2/{util.rs => common.rs} | 0 src/sdl2/controller.rs | 6 +++--- src/sdl2/joystick.rs | 16 ++++++++-------- src/sdl2/lib.rs | 4 +++- src/sdl2/rect.rs | 2 +- src/sdl2/render.rs | 2 +- src/sdl2/video.rs | 2 +- 7 files changed, 17 insertions(+), 15 deletions(-) rename src/sdl2/{util.rs => common.rs} (100%) diff --git a/src/sdl2/util.rs b/src/sdl2/common.rs similarity index 100% rename from src/sdl2/util.rs rename to src/sdl2/common.rs diff --git a/src/sdl2/controller.rs b/src/sdl2/controller.rs index fdbc2dcd..f5c8ab7d 100644 --- a/src/sdl2/controller.rs +++ b/src/sdl2/controller.rs @@ -4,7 +4,7 @@ use std::ffi::{CString, CStr, NulError}; use GameControllerSubsystem; use get_error; use joystick; -use util::{validate_int, IdOrSdlError}; +use common::{validate_int, IdOrSdlError}; use sys::controller as ll; use sys::event::{SDL_QUERY, SDL_ENABLE}; @@ -41,7 +41,7 @@ impl GameControllerSubsystem { /// maximum number can be retreived using the `SDL_NumJoysticks` /// function. pub fn open(&self, id: u32) -> Result { - use util::IdOrSdlError::*; + use common::IdOrSdlError::*; let id = if let Some(i) = validate_int(id) { i } else { @@ -62,7 +62,7 @@ impl GameControllerSubsystem { /// Return the name of the controller at index `id` pub fn name_for_index(&self, id: u32) -> Result { - use util::IdOrSdlError::*; + use common::IdOrSdlError::*; let id = if let Some(i) = validate_int(id) { i } else { diff --git a/src/sdl2/joystick.rs b/src/sdl2/joystick.rs index 337c56a6..4e934248 100644 --- a/src/sdl2/joystick.rs +++ b/src/sdl2/joystick.rs @@ -7,7 +7,7 @@ use sys::event::{SDL_QUERY, SDL_ENABLE}; use std::ffi::{CString, CStr, NulError}; use std::fmt::{Display, Formatter, Error}; use libc::c_char; -use util::{validate_int, IdOrSdlError}; +use common::{validate_int, IdOrSdlError}; impl JoystickSubsystem { /// Retreive the total number of attached joysticks *and* controllers identified by SDL. @@ -23,7 +23,7 @@ impl JoystickSubsystem { /// Attempt to open the joystick at number `id` and return it. pub fn open(&self, id: u32) -> Result { - use util::IdOrSdlError::*; + use common::IdOrSdlError::*; let id = match validate_int(id) { Some(id) => id, None => return Err(IdTooBig(id)), @@ -43,7 +43,7 @@ impl JoystickSubsystem { /// Return the name of the joystick at index `id` pub fn name_for_index(&self, id: u32) -> Result { - use util::IdOrSdlError::*; + use common::IdOrSdlError::*; let id = match validate_int(id) { Some(id) => id, None => return Err(IdTooBig(id)), @@ -61,7 +61,7 @@ impl JoystickSubsystem { /// Get the GUID for the joystick number `id` pub fn device_guid(&self, id: u32) -> Result { - use util::IdOrSdlError::*; + use common::IdOrSdlError::*; let id = match validate_int(id) { Some(id) => id, None => return Err(IdTooBig(id)), @@ -163,7 +163,7 @@ impl Joystick { /// /// The function will fail if the joystick doesn't have the provided axis. pub fn axis(&self, axis: u32) -> Result { - use util::IdOrSdlError::*; + use common::IdOrSdlError::*; // This interface is a bit messed up: 0 is a valid position // but can also mean that an error occured. As far as I can // tell the only way to know if an error happened is to see if @@ -205,7 +205,7 @@ impl Joystick { /// /// The function will fail if the joystick doesn't have the provided button. pub fn button(&self, button: u32) -> Result { - use util::IdOrSdlError::*; + use common::IdOrSdlError::*; // Same deal as axis, 0 can mean both unpressed or // error... clear_error(); @@ -248,7 +248,7 @@ impl Joystick { /// Return a pair `(dx, dy)` containing the difference in axis /// position since the last poll pub fn ball(&self, ball: u32) -> Result<(i32, i32), IdOrSdlError> { - use util::IdOrSdlError::*; + use common::IdOrSdlError::*; let mut dx = 0; let mut dy = 0; @@ -279,7 +279,7 @@ impl Joystick { /// Return the position of `hat` for this joystick pub fn hat(&self, hat: u32) -> Result { - use util::IdOrSdlError::*; + use common::IdOrSdlError::*; // Guess what? This function as well uses 0 to report an error // but 0 is also a valid value (HatState::Centered). So we // have to use the same hack as `axis`... diff --git a/src/sdl2/lib.rs b/src/sdl2/lib.rs index 0f2d6cad..272c216f 100644 --- a/src/sdl2/lib.rs +++ b/src/sdl2/lib.rs @@ -34,4 +34,6 @@ pub mod version; pub mod messagebox; pub mod hint; -mod util; +mod common; +// Export return types and such from the common module. +pub use common::IdOrSdlError; diff --git a/src/sdl2/rect.rs b/src/sdl2/rect.rs index e525e8be..2bad7a7f 100644 --- a/src/sdl2/rect.rs +++ b/src/sdl2/rect.rs @@ -2,7 +2,7 @@ use sys::rect as ll; use std::mem; use std::ptr; use std::ops::{BitAnd, BitOr}; -use util::validate_int; +use common::validate_int; use get_error; /// Immutable point type, consisting of x and y. diff --git a/src/sdl2/render.rs b/src/sdl2/render.rs index 762f3c40..13c656e7 100644 --- a/src/sdl2/render.rs +++ b/src/sdl2/render.rs @@ -44,7 +44,7 @@ use std::ffi::CStr; use num::FromPrimitive; use std::vec::Vec; use std::rc::Rc; -use util::validate_int; +use common::validate_int; use sys::render as ll; diff --git a/src/sdl2/video.rs b/src/sdl2/video.rs index 1d051bef..ca54997b 100644 --- a/src/sdl2/video.rs +++ b/src/sdl2/video.rs @@ -12,7 +12,7 @@ use pixels; use VideoSubsystem; use EventPump; use num::FromPrimitive; -use util::validate_int; +use common::validate_int; use get_error;