Rename module 'util' to 'common' to better reflect its usage

This commit is contained in:
Machtan
2016-02-10 11:09:08 +01:00
parent 1bf2757aea
commit b46f4b5ebb
7 changed files with 17 additions and 15 deletions
+3 -3
View File
@@ -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<GameController, IdOrSdlError> {
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<String, IdOrSdlError> {
use util::IdOrSdlError::*;
use common::IdOrSdlError::*;
let id = if let Some(i) = validate_int(id) {
i
} else {
+8 -8
View File
@@ -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<Joystick, IdOrSdlError> {
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<String, IdOrSdlError> {
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<Guid, IdOrSdlError> {
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<i16, IdOrSdlError> {
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<bool, IdOrSdlError> {
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<HatState, IdOrSdlError> {
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`...
+3 -1
View File
@@ -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;
+1 -1
View File
@@ -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.
+1 -1
View File
@@ -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;
+1 -1
View File
@@ -12,7 +12,7 @@ use pixels;
use VideoSubsystem;
use EventPump;
use num::FromPrimitive;
use util::validate_int;
use common::validate_int;
use get_error;