Browse Source

Apply Clippy suggestions

pull/13/head
AzureMarker 3 years ago
parent
commit
f2b1b75224
No known key found for this signature in database
GPG Key ID: 47A133F3BF9D03D3
  1. 1
      ctru-rs/src/console.rs
  2. 36
      ctru-rs/src/services/fs.rs
  3. 16
      ctru-rs/src/services/hid.rs
  4. 20
      ctru-rs/src/thread.rs
  5. 1
      ctru-sys/src/lib.rs

1
ctru-rs/src/console.rs

@ -37,6 +37,7 @@ impl Console {
/// The first two arguments are the desired coordinates of the top-left corner /// The first two arguments are the desired coordinates of the top-left corner
/// of the console, and the second pair is the new width and height /// of the console, and the second pair is the new width and height
/// ///
/// # Safety
/// This function is unsafe because it does not validate that the input will produce /// This function is unsafe because it does not validate that the input will produce
/// a console that actually fits on the screen /// a console that actually fits on the screen
pub unsafe fn set_window(&mut self, x: i32, y: i32, width: i32, height: i32) { pub unsafe fn set_window(&mut self, x: i32, y: i32, width: i32, height: i32) {

36
ctru-rs/src/services/fs.rs

@ -233,7 +233,7 @@ pub struct Metadata {
/// .open("foo.txt") /// .open("foo.txt")
/// .unwrap(); /// .unwrap();
/// ``` /// ```
#[derive(Clone)] #[derive(Clone, Default)]
pub struct OpenOptions { pub struct OpenOptions {
read: bool, read: bool,
write: bool, write: bool,
@ -318,10 +318,7 @@ impl Fs {
if r < 0 { if r < 0 {
Err(crate::Error::from(r)) Err(crate::Error::from(r))
} else { } else {
Ok(Archive { Ok(Archive { handle, id })
handle: handle,
id: id,
})
} }
} }
} }
@ -430,10 +427,7 @@ impl File {
crate::Error::from(r), crate::Error::from(r),
)) ))
} else { } else {
Ok(Metadata { Ok(Metadata { attributes: 0, size })
attributes: 0,
size: size,
})
} }
} }
} }
@ -496,6 +490,9 @@ impl Metadata {
/// Returns the size, in bytes, this metadata is for. /// Returns the size, in bytes, this metadata is for.
/// ///
/// Directories return size = 0. /// Directories return size = 0.
// We don't want an is_empty function because directories always have a
// zero size.
#[allow(clippy::len_without_is_empty)]
pub fn len(&self) -> u64 { pub fn len(&self) -> u64 {
self.size self.size
} }
@ -506,14 +503,7 @@ impl OpenOptions {
/// ///
/// All options are initially set to `false` /// All options are initially set to `false`
pub fn new() -> OpenOptions { pub fn new() -> OpenOptions {
OpenOptions { Self::default()
read: false,
write: false,
append: false,
truncate: false,
create: false,
arch_handle: 0,
}
} }
/// Sets the option for read access. /// Sets the option for read access.
@ -753,8 +743,8 @@ pub fn create_dir_all<P: AsRef<Path>>(arch: &Archive, path: P) -> IoResult<()> {
/// Given a path, query the file system to get information about a file, directory, etc /// Given a path, query the file system to get information about a file, directory, etc
pub fn metadata<P: AsRef<Path>>(arch: &Archive, path: P) -> IoResult<Metadata> { pub fn metadata<P: AsRef<Path>>(arch: &Archive, path: P) -> IoResult<Metadata> {
let maybe_file = File::open(&arch, path.as_ref()); let maybe_file = File::open(arch, path.as_ref());
let maybe_dir = read_dir(&arch, path.as_ref()); let maybe_dir = read_dir(arch, path.as_ref());
match (maybe_file, maybe_dir) { match (maybe_file, maybe_dir) {
(Ok(file), _) => file.metadata(), (Ok(file), _) => file.metadata(),
(_, Ok(_dir)) => Ok(Metadata { (_, Ok(_dir)) => Ok(Metadata {
@ -828,8 +818,8 @@ pub fn read_dir<P: AsRef<Path>>(arch: &Archive, path: P) -> IoResult<ReadDir> {
} else { } else {
Ok(ReadDir { Ok(ReadDir {
handle: Dir(handle), handle: Dir(handle),
root: root, root,
arch: arch, arch,
}) })
} }
} }
@ -897,7 +887,7 @@ fn to_utf16(path: &Path) -> WideCString {
} }
// Adapted from sys/windows/fs.rs in libstd // Adapted from sys/windows/fs.rs in libstd
fn truncate_utf16_at_nul<'a>(v: &'a [u16]) -> &'a [u16] { fn truncate_utf16_at_nul(v: &[u16]) -> &[u16] {
match v.iter().position(|c| *c == 0) { match v.iter().position(|c| *c == 0) {
// don't include the 0 // don't include the 0
Some(i) => &v[..i], Some(i) => &v[..i],
@ -933,7 +923,7 @@ unsafe fn read_to_end_uninitialized(r: &mut dyn Read, buf: &mut Vec<u8>) -> IoRe
} }
let buf_slice = slice::from_raw_parts_mut( let buf_slice = slice::from_raw_parts_mut(
buf.as_mut_ptr().offset(buf.len() as isize), buf.as_mut_ptr().add(buf.len()),
buf.capacity() - buf.len(), buf.capacity() - buf.len(),
); );

16
ctru-rs/src/services/hid.rs

@ -106,10 +106,16 @@ impl Hid {
} }
} }
impl Default for TouchPosition {
fn default() -> Self {
TouchPosition(ctru_sys::touchPosition { px: 0, py: 0 })
}
}
impl TouchPosition { impl TouchPosition {
/// Create a new TouchPosition instance. /// Create a new TouchPosition instance.
pub fn new() -> Self { pub fn new() -> Self {
TouchPosition(ctru_sys::touchPosition { px: 0, py: 0 }) Self::default()
} }
/// Returns the current touch position in pixels. /// Returns the current touch position in pixels.
@ -121,10 +127,16 @@ impl TouchPosition {
} }
} }
impl Default for CirclePosition {
fn default() -> Self {
CirclePosition(ctru_sys::circlePosition { dx: 0, dy: 0 })
}
}
impl CirclePosition { impl CirclePosition {
/// Create a new CirclePosition instance. /// Create a new CirclePosition instance.
pub fn new() -> Self { pub fn new() -> Self {
CirclePosition(ctru_sys::circlePosition { dx: 0, dy: 0 }) Self::default()
} }
/// Returns the current circle pad position in (x, y) form. /// Returns the current circle pad position in (x, y) form.

20
ctru-rs/src/thread.rs

@ -49,7 +49,7 @@ use std::time::Duration;
/// Thread factory, which can be used in order to configure the properties of /// Thread factory, which can be used in order to configure the properties of
/// a new thread. /// a new thread.
#[derive(Debug)] #[derive(Debug, Default)]
pub struct Builder { pub struct Builder {
// The size of the stack for the spawned thread in bytes // The size of the stack for the spawned thread in bytes
stack_size: Option<usize>, stack_size: Option<usize>,
@ -78,11 +78,7 @@ impl Builder {
/// handler.join().unwrap(); /// handler.join().unwrap();
/// ``` /// ```
pub fn new() -> Builder { pub fn new() -> Builder {
Builder { Self::default()
stack_size: None,
priority: None,
affinity: None,
}
} }
/// Sets the size of the stack (in bytes) for the new thread. /// Sets the size of the stack (in bytes) for the new thread.
@ -102,6 +98,7 @@ impl Builder {
/// ``` /// ```
/// ///
/// [stack-size]: ./index.html#stack-size /// [stack-size]: ./index.html#stack-size
#[must_use]
pub fn stack_size(mut self, size: usize) -> Builder { pub fn stack_size(mut self, size: usize) -> Builder {
self.stack_size = Some(size); self.stack_size = Some(size);
self self
@ -112,6 +109,7 @@ impl Builder {
/// Low values gives the thread higher priority. For userland apps, this has /// Low values gives the thread higher priority. For userland apps, this has
/// to be within the range of 0x18 to 0x3F inclusive. The main thread usually /// to be within the range of 0x18 to 0x3F inclusive. The main thread usually
/// has a priority of 0x30, but not always. /// has a priority of 0x30, but not always.
#[must_use]
pub fn priority(mut self, priority: i32) -> Builder { pub fn priority(mut self, priority: i32) -> Builder {
self.priority = Some(priority); self.priority = Some(priority);
self self
@ -134,6 +132,7 @@ impl Builder {
/// ///
/// Processes in the BASE memory region can always create threads on /// Processes in the BASE memory region can always create threads on
/// processors #2 and #3. /// processors #2 and #3.
#[must_use]
pub fn affinity(mut self, affinity: i32) -> Builder { pub fn affinity(mut self, affinity: i32) -> Builder {
self.affinity = Some(affinity); self.affinity = Some(affinity);
self self
@ -188,7 +187,7 @@ impl Builder {
// If no priority value is specified, spawn with the same // If no priority value is specified, spawn with the same
// priority as the parent thread // priority as the parent thread
let priority = priority.unwrap_or_else(|| imp::Thread::priority()); let priority = priority.unwrap_or_else(imp::Thread::priority);
// If no affinity is specified, spawn on the default core (determined by // If no affinity is specified, spawn on the default core (determined by
// the application's Exheader) // the application's Exheader)
@ -434,6 +433,8 @@ pub fn park() {
} }
loop { loop {
m = thread.inner.cvar.wait(m).unwrap(); m = thread.inner.cvar.wait(m).unwrap();
#[allow(clippy::single_match)]
match thread match thread
.inner .inner
.state .state
@ -891,7 +892,6 @@ mod imp {
use std::convert::TryInto; use std::convert::TryInto;
use std::io; use std::io;
use std::mem; use std::mem;
use std::ptr;
use std::time::Duration; use std::time::Duration;
use libc; use libc;
@ -929,11 +929,11 @@ mod imp {
false, false,
); );
return if handle == ptr::null_mut() { return if handle.is_null() {
Err(io::Error::from_raw_os_error(libc::EAGAIN)) Err(io::Error::from_raw_os_error(libc::EAGAIN))
} else { } else {
mem::forget(p); // ownership passed to the new thread mem::forget(p); // ownership passed to the new thread
Ok(Thread { handle: handle }) Ok(Thread { handle })
}; };
extern "C" fn thread_func(start: *mut libc::c_void) { extern "C" fn thread_func(start: *mut libc::c_void) {

1
ctru-sys/src/lib.rs

@ -1,6 +1,7 @@
#![allow(non_upper_case_globals)] #![allow(non_upper_case_globals)]
#![allow(non_camel_case_types)] #![allow(non_camel_case_types)]
#![allow(non_snake_case)] #![allow(non_snake_case)]
#![allow(clippy::all)]
#![no_std] #![no_std]
include!("bindings.rs"); include!("bindings.rs");

Loading…
Cancel
Save