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 {
} }
} }
from_type_to_u32!(Kind); from_impl!(Kind, ctru_sys::SwkbdType);
from_type_to_u32!(Button); from_impl!(Button, ctru_sys::SwkbdButton);
from_type_to_u32!(Error); from_impl!(Error, ctru_sys::SwkbdResult);
from_type_to_i32!(ValidInput); from_impl!(ValidInput, i32);

38
ctru-rs/src/lib.rs

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

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

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

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

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

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

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

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

@ -104,14 +104,15 @@ pub struct RawFrameBuffer<'screen> {
} }
#[derive(Copy, Clone, Debug)] #[derive(Copy, Clone, Debug)]
#[repr(u32)]
/// Side of top screen framebuffer /// Side of top screen framebuffer
/// ///
/// The top screen of the 3DS can have two separate sets of framebuffers to support its 3D functionality /// The top screen of the 3DS can have two separate sets of framebuffers to support its 3D functionality
pub enum Side { pub enum Side {
/// The left framebuffer. This framebuffer is also the one used when 3D is disabled /// The left framebuffer. This framebuffer is also the one used when 3D is disabled
Left, Left = ctru_sys::GFX_LEFT,
/// The right framebuffer /// 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 /// 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 {
} }
} }
from_type_to_u32!(Side); from_impl!(Side, ctru_sys::gfx3dSide_t);
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {

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

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

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

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

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

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

Loading…
Cancel
Save