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 { @@ -37,6 +37,7 @@ impl Console {
/// 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
///
/// # Safety
/// This function is unsafe because it does not validate that the input will produce
/// a console that actually fits on the screen
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 { @@ -233,7 +233,7 @@ pub struct Metadata {
/// .open("foo.txt")
/// .unwrap();
/// ```
#[derive(Clone)]
#[derive(Clone, Default)]
pub struct OpenOptions {
read: bool,
write: bool,
@ -318,10 +318,7 @@ impl Fs { @@ -318,10 +318,7 @@ impl Fs {
if r < 0 {
Err(crate::Error::from(r))
} else {
Ok(Archive {
handle: handle,
id: id,
})
Ok(Archive { handle, id })
}
}
}
@ -430,10 +427,7 @@ impl File { @@ -430,10 +427,7 @@ impl File {
crate::Error::from(r),
))
} else {
Ok(Metadata {
attributes: 0,
size: size,
})
Ok(Metadata { attributes: 0, size })
}
}
}
@ -496,6 +490,9 @@ impl Metadata { @@ -496,6 +490,9 @@ impl Metadata {
/// Returns the size, in bytes, this metadata is for.
///
/// 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 {
self.size
}
@ -506,14 +503,7 @@ impl OpenOptions { @@ -506,14 +503,7 @@ impl OpenOptions {
///
/// All options are initially set to `false`
pub fn new() -> OpenOptions {
OpenOptions {
read: false,
write: false,
append: false,
truncate: false,
create: false,
arch_handle: 0,
}
Self::default()
}
/// Sets the option for read access.
@ -753,8 +743,8 @@ pub fn create_dir_all<P: AsRef<Path>>(arch: &Archive, path: P) -> IoResult<()> { @@ -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
pub fn metadata<P: AsRef<Path>>(arch: &Archive, path: P) -> IoResult<Metadata> {
let maybe_file = File::open(&arch, path.as_ref());
let maybe_dir = read_dir(&arch, path.as_ref());
let maybe_file = File::open(arch, path.as_ref());
let maybe_dir = read_dir(arch, path.as_ref());
match (maybe_file, maybe_dir) {
(Ok(file), _) => file.metadata(),
(_, Ok(_dir)) => Ok(Metadata {
@ -828,8 +818,8 @@ pub fn read_dir<P: AsRef<Path>>(arch: &Archive, path: P) -> IoResult<ReadDir> { @@ -828,8 +818,8 @@ pub fn read_dir<P: AsRef<Path>>(arch: &Archive, path: P) -> IoResult<ReadDir> {
} else {
Ok(ReadDir {
handle: Dir(handle),
root: root,
arch: arch,
root,
arch,
})
}
}
@ -897,7 +887,7 @@ fn to_utf16(path: &Path) -> WideCString { @@ -897,7 +887,7 @@ fn to_utf16(path: &Path) -> WideCString {
}
// 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) {
// don't include the 0
Some(i) => &v[..i],
@ -933,7 +923,7 @@ unsafe fn read_to_end_uninitialized(r: &mut dyn Read, buf: &mut Vec<u8>) -> IoRe @@ -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(
buf.as_mut_ptr().offset(buf.len() as isize),
buf.as_mut_ptr().add(buf.len()),
buf.capacity() - buf.len(),
);

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

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

20
ctru-rs/src/thread.rs

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

1
ctru-sys/src/lib.rs

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

Loading…
Cancel
Save