diff --git a/ctru-rs/src/error.rs b/ctru-rs/src/error.rs index d47d24c..73b78b5 100644 --- a/ctru-rs/src/error.rs +++ b/ctru-rs/src/error.rs @@ -22,7 +22,7 @@ impl Try for LibCtruError { fn branch(self) -> ControlFlow { match self.0 { 0 => ControlFlow::Continue(()), - _ => ControlFlow::Break(Err(self.into())) + _ => ControlFlow::Break(Err(self.into())), } } } diff --git a/ctru-rs/src/romfs.rs b/ctru-rs/src/romfs.rs index ba67574..0b706b4 100644 --- a/ctru-rs/src/romfs.rs +++ b/ctru-rs/src/romfs.rs @@ -10,10 +10,10 @@ //! romfs_dir = "romfs" //! ``` +use crate::error::LibCtruError; use once_cell::sync::Lazy; use std::ffi::CStr; use std::sync::Mutex; -use crate::error::LibCtruError; use crate::services::ServiceReference; diff --git a/ctru-rs/src/services/cam.rs b/ctru-rs/src/services/cam.rs index 18960db..86dd83f 100644 --- a/ctru-rs/src/services/cam.rs +++ b/ctru-rs/src/services/cam.rs @@ -3,11 +3,11 @@ //! The CAM service provides access to the cameras. Cameras can return 2D images //! in the form of byte vectors which can be used for display or other usages. +use crate::error::LibCtruError; use crate::services::gspgpu::FramebufferFormat; use bitflags::bitflags; use ctru_sys::Handle; use std::time::Duration; -use crate::error::LibCtruError; /// A reference-counted handle to the CAM service and the usable cameras. /// The service is closed when all instances of this struct fall out of scope. @@ -268,14 +268,19 @@ impl BothOutwardCam { brightness_synchronization: bool, ) -> crate::Result<()> { unsafe { - LibCtruError(ctru_sys::CAMU_SetBrightnessSynchronization(brightness_synchronization))?; + LibCtruError(ctru_sys::CAMU_SetBrightnessSynchronization( + brightness_synchronization, + ))?; Ok(()) } } fn synchronize_vsync_timing(&self) -> crate::Result<()> { unsafe { - LibCtruError(ctru_sys::CAMU_SynchronizeVsyncTiming(ctru_sys::SELECT_OUT1, ctru_sys::SELECT_OUT2))?; + LibCtruError(ctru_sys::CAMU_SynchronizeVsyncTiming( + ctru_sys::SELECT_OUT1, + ctru_sys::SELECT_OUT2, + ))?; Ok(()) } } @@ -315,7 +320,10 @@ pub trait Camera { fn get_transfer_bytes(&self) -> crate::Result { unsafe { let mut transfer_bytes = 0; - LibCtruError(ctru_sys::CAMU_GetTransferBytes(&mut transfer_bytes, self.port_as_raw()))?; + LibCtruError(ctru_sys::CAMU_GetTransferBytes( + &mut transfer_bytes, + self.port_as_raw(), + ))?; Ok(transfer_bytes) } } @@ -409,7 +417,10 @@ pub trait Camera { /// Sets the white balance mod of the camera based on the passed [CamWhiteBalance] argument fn set_white_balance(&mut self, white_balance: CamWhiteBalance) -> crate::Result<()> { unsafe { - LibCtruError(ctru_sys::CAMU_SetWhiteBalance(self.camera_as_raw(), white_balance.bits()))?; + LibCtruError(ctru_sys::CAMU_SetWhiteBalance( + self.camera_as_raw(), + white_balance.bits(), + ))?; Ok(()) } } @@ -440,7 +451,10 @@ pub trait Camera { /// Sets whether auto exposure is enabled or disabled for the camera fn set_auto_exposure(&mut self, enabled: bool) -> crate::Result<()> { unsafe { - LibCtruError(ctru_sys::CAMU_SetAutoExposure(self.camera_as_raw(), enabled))?; + LibCtruError(ctru_sys::CAMU_SetAutoExposure( + self.camera_as_raw(), + enabled, + ))?; Ok(()) } } @@ -449,7 +463,10 @@ pub trait Camera { fn is_auto_exposure_enabled(&self) -> crate::Result { unsafe { let mut enabled = false; - LibCtruError(ctru_sys::CAMU_IsAutoExposure(&mut enabled, self.camera_as_raw()))?; + LibCtruError(ctru_sys::CAMU_IsAutoExposure( + &mut enabled, + self.camera_as_raw(), + ))?; Ok(enabled) } } @@ -457,7 +474,10 @@ pub trait Camera { /// Sets whether auto white balance is enabled or disabled for the camera fn set_auto_white_balance(&mut self, enabled: bool) -> crate::Result<()> { unsafe { - LibCtruError(ctru_sys::CAMU_SetAutoWhiteBalance(self.camera_as_raw(), enabled))?; + LibCtruError(ctru_sys::CAMU_SetAutoWhiteBalance( + self.camera_as_raw(), + enabled, + ))?; Ok(()) } } @@ -466,7 +486,10 @@ pub trait Camera { fn is_auto_white_balance_enabled(&self) -> crate::Result { unsafe { let mut enabled = false; - LibCtruError(ctru_sys::CAMU_IsAutoWhiteBalance(&mut enabled, self.camera_as_raw()))?; + LibCtruError(ctru_sys::CAMU_IsAutoWhiteBalance( + &mut enabled, + self.camera_as_raw(), + ))?; Ok(enabled) } } @@ -474,7 +497,11 @@ pub trait Camera { /// Sets the flip direction of the camera's image based on the passed [CamFlip] argument fn flip_image(&mut self, flip: CamFlip) -> crate::Result<()> { unsafe { - LibCtruError(ctru_sys::CAMU_FlipImage(self.camera_as_raw(), flip.bits(), ctru_sys::CONTEXT_A))?; + LibCtruError(ctru_sys::CAMU_FlipImage( + self.camera_as_raw(), + flip.bits(), + ctru_sys::CONTEXT_A, + ))?; Ok(()) } } @@ -516,7 +543,11 @@ pub trait Camera { /// Sets the view size of the camera based on the passed [CamSize] argument. fn set_view_size(&mut self, size: CamSize) -> crate::Result<()> { unsafe { - LibCtruError(ctru_sys::CAMU_SetSize(self.camera_as_raw(), size.bits(), ctru_sys::CONTEXT_A))?; + LibCtruError(ctru_sys::CAMU_SetSize( + self.camera_as_raw(), + size.bits(), + ctru_sys::CONTEXT_A, + ))?; Ok(()) } } @@ -524,7 +555,10 @@ pub trait Camera { /// Sets the frame rate of the camera based on the passed [CamFrameRate] argument. fn set_frame_rate(&mut self, frame_rate: CamFrameRate) -> crate::Result<()> { unsafe { - LibCtruError(ctru_sys::CAMU_SetFrameRate(self.camera_as_raw(), frame_rate.bits()))?; + LibCtruError(ctru_sys::CAMU_SetFrameRate( + self.camera_as_raw(), + frame_rate.bits(), + ))?; Ok(()) } } @@ -532,7 +566,10 @@ pub trait Camera { /// Sets the photo mode of the camera based on the passed [CamPhotoMode] argument. fn set_photo_mode(&mut self, photo_mode: CamPhotoMode) -> crate::Result<()> { unsafe { - LibCtruError(ctru_sys::CAMU_SetPhotoMode(self.camera_as_raw(), photo_mode.bits()))?; + LibCtruError(ctru_sys::CAMU_SetPhotoMode( + self.camera_as_raw(), + photo_mode.bits(), + ))?; Ok(()) } } @@ -542,7 +579,11 @@ pub trait Camera { /// Multiple effects can be set at once by combining the bitflags of [CamEffect] fn set_effect(&mut self, effect: CamEffect) -> crate::Result<()> { unsafe { - LibCtruError(ctru_sys::CAMU_SetEffect(self.camera_as_raw(), effect.bits(), ctru_sys::CONTEXT_A))?; + LibCtruError(ctru_sys::CAMU_SetEffect( + self.camera_as_raw(), + effect.bits(), + ctru_sys::CONTEXT_A, + ))?; Ok(()) } } @@ -550,7 +591,10 @@ pub trait Camera { /// Sets the contrast of the camera based on the passed [CamContrast] argument. fn set_contrast(&mut self, contrast: CamContrast) -> crate::Result<()> { unsafe { - LibCtruError(ctru_sys::CAMU_SetContrast(self.camera_as_raw(), contrast.bits()))?; + LibCtruError(ctru_sys::CAMU_SetContrast( + self.camera_as_raw(), + contrast.bits(), + ))?; Ok(()) } } @@ -558,7 +602,10 @@ pub trait Camera { /// Sets the lens correction of the camera based on the passed [CamLensCorrection] argument. fn set_lens_correction(&mut self, lens_correction: CamLensCorrection) -> crate::Result<()> { unsafe { - LibCtruError(ctru_sys::CAMU_SetLensCorrection(self.camera_as_raw(), lens_correction.bits()))?; + LibCtruError(ctru_sys::CAMU_SetLensCorrection( + self.camera_as_raw(), + lens_correction.bits(), + ))?; Ok(()) } } @@ -591,7 +638,13 @@ pub trait Camera { height: i16, ) -> crate::Result<()> { unsafe { - LibCtruError(ctru_sys::CAMU_SetAutoExposureWindow(self.camera_as_raw(), x, y, width, height))?; + LibCtruError(ctru_sys::CAMU_SetAutoExposureWindow( + self.camera_as_raw(), + x, + y, + width, + height, + ))?; Ok(()) } } @@ -612,7 +665,13 @@ pub trait Camera { height: i16, ) -> crate::Result<()> { unsafe { - LibCtruError(ctru_sys::CAMU_SetAutoWhiteBalanceWindow(self.camera_as_raw(), x, y, width, height))?; + LibCtruError(ctru_sys::CAMU_SetAutoWhiteBalanceWindow( + self.camera_as_raw(), + x, + y, + width, + height, + ))?; Ok(()) } } @@ -674,7 +733,11 @@ pub trait Camera { ) -> crate::Result> { let transfer_unit = unsafe { let mut buf_size = 0; - LibCtruError(ctru_sys::CAMU_GetMaxBytes(&mut buf_size, width as i16, height as i16))?; + LibCtruError(ctru_sys::CAMU_GetMaxBytes( + &mut buf_size, + width as i16, + height as i16, + ))?; Ok::(buf_size) }?; diff --git a/ctru-rs/src/services/ps.rs b/ctru-rs/src/services/ps.rs index b1585df..fc91d96 100644 --- a/ctru-rs/src/services/ps.rs +++ b/ctru-rs/src/services/ps.rs @@ -45,7 +45,9 @@ pub fn device_id() -> crate::Result { } pub fn generate_random_bytes(out: &mut [u8]) -> crate::Result<()> { - LibCtruError(unsafe { ctru_sys::PS_GenerateRandomBytes(out as *mut _ as *mut _, out.len() as u32) })?; + LibCtruError(unsafe { + ctru_sys::PS_GenerateRandomBytes(out as *mut _ as *mut _, out.len() as u32) + })?; Ok(()) } diff --git a/ctru-rs/src/services/soc.rs b/ctru-rs/src/services/soc.rs index 1579d51..8fe231a 100644 --- a/ctru-rs/src/services/soc.rs +++ b/ctru-rs/src/services/soc.rs @@ -3,9 +3,9 @@ use once_cell::sync::Lazy; use std::net::Ipv4Addr; use std::sync::Mutex; +use crate::error::LibCtruError; use crate::services::ServiceReference; use crate::Error; -use crate::error::LibCtruError; /// Soc service. Initializing this service will enable the use of network sockets and utilities /// such as those found in `std::net`. The service will be closed when this struct is is dropped. diff --git a/ctru-rs/src/services/sslc.rs b/ctru-rs/src/services/sslc.rs index ef1e015..fc933b4 100644 --- a/ctru-rs/src/services/sslc.rs +++ b/ctru-rs/src/services/sslc.rs @@ -16,7 +16,10 @@ impl SslC { /// Fill `buf` with `buf.len()` random bytes pub fn generate_random_data(&self, buf: &mut [u8]) -> crate::Result<()> { unsafe { - LibCtruError(ctru_sys::sslcGenerateRandomData(buf.as_ptr() as _, buf.len() as u32))?; + LibCtruError(ctru_sys::sslcGenerateRandomData( + buf.as_ptr() as _, + buf.len() as u32, + ))?; Ok(()) } }