Browse Source

Inequivocable From impls

pull/107/head
Andrea Ciliberti 2 years ago
parent
commit
1383e753ee
  1. 8
      ctru-rs/src/applets/swkbd.rs
  2. 38
      ctru-rs/src/lib.rs
  3. 20
      ctru-rs/src/services/cam.rs
  4. 6
      ctru-rs/src/services/cfgu.rs
  5. 6
      ctru-rs/src/services/fs.rs
  6. 7
      ctru-rs/src/services/gfx.rs
  7. 4
      ctru-rs/src/services/gspgpu.rs
  8. 6
      ctru-rs/src/services/ndsp/mod.rs
  9. 4
      ctru-rs/src/services/ps.rs

8
ctru-rs/src/applets/swkbd.rs

@ -213,7 +213,7 @@ impl Default for Swkbd { @@ -213,7 +213,7 @@ impl Default for Swkbd {
}
}
from_type_to_u32!(Kind);
from_type_to_u32!(Button);
from_type_to_u32!(Error);
from_type_to_i32!(ValidInput);
from_impl!(Kind, ctru_sys::SwkbdType);
from_impl!(Button, ctru_sys::SwkbdButton);
from_impl!(Error, ctru_sys::SwkbdResult);
from_impl!(ValidInput, i32);

38
ctru-rs/src/lib.rs

@ -15,41 +15,11 @@ extern crate pthread_3ds; @@ -15,41 +15,11 @@ extern crate pthread_3ds;
#[cfg(feature = "big-stack")]
static __stacksize__: usize = 2 * 1024 * 1024; // 2MB
macro_rules! from_type_to_u8 {
($from_type:ty) => {
impl From<$from_type> for u8 {
macro_rules! from_impl {
($from_type:ty, $into_type:ty) => {
impl From<$from_type> for $into_type {
fn from(v: $from_type) -> Self {
v as u8
}
}
};
}
macro_rules! from_type_to_u16 {
($from_type:ty) => {
impl From<$from_type> for u16 {
fn from(v: $from_type) -> Self {
v as u16
}
}
};
}
macro_rules! from_type_to_u32 {
($from_type:ty) => {
impl From<$from_type> for u32 {
fn from(v: $from_type) -> Self {
v as u32
}
}
};
}
macro_rules! from_type_to_i32 {
($from_type:ty) => {
impl From<$from_type> for i32 {
fn from(v: $from_type) -> Self {
v as i32
v as $into_type
}
}
};

20
ctru-rs/src/services/cam.rs

@ -794,13 +794,13 @@ impl Drop for Cam { @@ -794,13 +794,13 @@ impl Drop for Cam {
}
}
from_type_to_u32!(FlipMode);
from_type_to_u32!(ViewSize);
from_type_to_u32!(FrameRate);
from_type_to_u32!(WhiteBalance);
from_type_to_u32!(PhotoMode);
from_type_to_u32!(Effect);
from_type_to_u32!(Contrast);
from_type_to_u32!(LensCorrection);
from_type_to_u32!(OutputFormat);
from_type_to_u32!(ShutterSound);
from_impl!(FlipMode, ctru_sys::CAMU_Flip);
from_impl!(ViewSize, ctru_sys::CAMU_Size);
from_impl!(FrameRate, ctru_sys::CAMU_FrameRate);
from_impl!(WhiteBalance, ctru_sys::CAMU_WhiteBalance);
from_impl!(PhotoMode, ctru_sys::CAMU_PhotoMode);
from_impl!(Effect, ctru_sys::CAMU_Effect);
from_impl!(Contrast, ctru_sys::CAMU_Contrast);
from_impl!(LensCorrection, ctru_sys::CAMU_LensCorrection);
from_impl!(OutputFormat, ctru_sys::CAMU_OutputFormat);
from_impl!(ShutterSound, ctru_sys::CAMU_ShutterSoundType);

6
ctru-rs/src/services/cfgu.rs

@ -115,9 +115,9 @@ impl Drop for Cfgu { @@ -115,9 +115,9 @@ impl Drop for Cfgu {
}
}
from_type_to_u8!(Region);
from_type_to_u8!(Language);
from_type_to_u8!(SystemModel);
from_impl!(Region, u8);
from_impl!(Language, u8);
from_impl!(SystemModel, u8);
impl TryFrom<u8> for Region {
type Error = ();

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

@ -1018,6 +1018,6 @@ impl Drop for Dir { @@ -1018,6 +1018,6 @@ impl Drop for Dir {
}
}
from_type_to_u32!(FsMediaType);
from_type_to_u32!(PathType);
from_type_to_u32!(ArchiveID);
from_impl!(FsMediaType, ctru_sys::FS_MediaType);
from_impl!(PathType, ctru_sys::FS_PathType);
from_impl!(ArchiveID, ctru_sys::FS_ArchiveID);

7
ctru-rs/src/services/gfx.rs

@ -104,14 +104,15 @@ pub struct RawFrameBuffer<'screen> { @@ -104,14 +104,15 @@ pub struct RawFrameBuffer<'screen> {
}
#[derive(Copy, Clone, Debug)]
#[repr(u32)]
/// Side of top screen framebuffer
///
/// The top screen of the 3DS can have two separate sets of framebuffers to support its 3D functionality
pub enum Side {
/// The left framebuffer. This framebuffer is also the one used when 3D is disabled
Left,
Left = ctru_sys::GFX_LEFT,
/// The right framebuffer
Right,
Right = ctru_sys::GFX_RIGHT,
}
/// A handle to libctru's gfx module. This module is a wrapper around the GSPGPU service that
@ -283,7 +284,7 @@ impl Screen for BottomScreen { @@ -283,7 +284,7 @@ impl Screen for BottomScreen {
}
}
from_type_to_u32!(Side);
from_impl!(Side, ctru_sys::gfx3dSide_t);
#[cfg(test)]
mod tests {

4
ctru-rs/src/services/gspgpu.rs

@ -65,5 +65,5 @@ impl From<ctru_sys::GSPGPU_FramebufferFormat> for FramebufferFormat { @@ -65,5 +65,5 @@ impl From<ctru_sys::GSPGPU_FramebufferFormat> for FramebufferFormat {
}
}
from_type_to_u32!(FramebufferFormat);
from_type_to_u32!(Event);
from_impl!(FramebufferFormat, ctru_sys::GSPGPU_FramebufferFormat);
from_impl!(Event, ctru_sys::GSPGPU_Event);

6
ctru-rs/src/services/ndsp/mod.rs

@ -341,6 +341,6 @@ impl Drop for Ndsp { @@ -341,6 +341,6 @@ impl Drop for Ndsp {
}
}
from_type_to_u32!(InterpolationType);
from_type_to_u32!(OutputMode);
from_type_to_u16!(AudioFormat);
from_impl!(InterpolationType, ctru_sys::ndspInterpType);
from_impl!(OutputMode, ctru_sys::ndspOutputMode);
from_impl!(AudioFormat, u16);

4
ctru-rs/src/services/ps.rs

@ -70,8 +70,8 @@ impl Drop for Ps { @@ -70,8 +70,8 @@ impl Drop for Ps {
}
}
from_type_to_u32!(AESAlgorithm);
from_type_to_u32!(AESKeyType);
from_impl!(AESAlgorithm, ctru_sys::PS_AESAlgorithm);
from_impl!(AESKeyType, ctru_sys::PS_AESKeyType);
#[cfg(test)]
mod tests {

Loading…
Cancel
Save