From be858ff6aeb30ddec03924257994d99a0e911d47 Mon Sep 17 00:00:00 2001 From: Andrea Ciliberti Date: Tue, 22 Nov 2022 11:29:07 +0100 Subject: [PATCH] Cargo fmt --- ctru-rs/examples/linear-memory.rs | 9 ++++++--- ctru-rs/src/linear.rs | 12 ++++++++---- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/ctru-rs/examples/linear-memory.rs b/ctru-rs/examples/linear-memory.rs index 96ec554..11d13d3 100644 --- a/ctru-rs/examples/linear-memory.rs +++ b/ctru-rs/examples/linear-memory.rs @@ -1,7 +1,7 @@ #![feature(allocator_api)] -use ctru::prelude::*; use ctru::linear::LinearAllocator; +use ctru::prelude::*; fn main() { ctru::init(); @@ -15,13 +15,16 @@ fn main() { // Normal `Box` on the heap let heap_box = Box::new(1492); // `Box` living on the linear memory sector - let linear_box: Box:: = Box::new_in(2022, LinearAllocator); + let linear_box: Box = Box::new_in(2022, LinearAllocator); println!("This value is from the heap: {heap_box}"); println!("This value is from the LINEAR memory: {linear_box}"); println!("\nLINEAR space free before allocation: {linear_space_before}"); - println!("LINEAR space free after allocation: {}", LinearAllocator::free_space()); + println!( + "LINEAR space free after allocation: {}", + LinearAllocator::free_space() + ); println!("\x1b[29;16HPress Start to exit"); diff --git a/ctru-rs/src/linear.rs b/ctru-rs/src/linear.rs index 88f65fe..507cacd 100644 --- a/ctru-rs/src/linear.rs +++ b/ctru-rs/src/linear.rs @@ -2,7 +2,7 @@ //! //! Linear memory is a sector of the 3DS' RAM that binds virtual addresses exactly to the physical address. //! As such, it is used for fast and safe memory sharing between services (and is especially needed for GPU and DSP). -//! +//! //! Resources:
//!
//! @@ -25,10 +25,14 @@ impl LinearAllocator { } unsafe impl Allocator for LinearAllocator { - fn allocate(&self, layout: std::alloc::Layout) -> Result, std::alloc::AllocError> { + fn allocate( + &self, + layout: std::alloc::Layout, + ) -> Result, std::alloc::AllocError> { let pointer = unsafe { ctru_sys::linearAlloc(layout.size() as u32) }; - let slice: &mut [u8] = unsafe { std::slice::from_raw_parts_mut(pointer as *mut u8, layout.size()) }; - + let slice: &mut [u8] = + unsafe { std::slice::from_raw_parts_mut(pointer as *mut u8, layout.size()) }; + std::ptr::NonNull::new(slice).ok_or(std::alloc::AllocError) }