Browse Source

More generic doc changes

pull/134/head
Andrea Ciliberti 1 year ago
parent
commit
ccb0676f3c
  1. 1
      ctru-rs/README.md
  2. 11
      ctru-rs/src/error.rs
  3. 4
      ctru-rs/src/lib.rs
  4. 18
      ctru-rs/src/linear.rs
  5. 2
      ctru-rs/src/services/am.rs
  6. 4
      ctru-rs/src/services/mod.rs

1
ctru-rs/README.md

@ -1,7 +1,6 @@ @@ -1,7 +1,6 @@
# ctru-rs
Safe and idiomatic Rust wrapper around [`libctru`](https://github.com/devkitPro/libctru).
This crate uses the bindings provided by [`ctru-sys`](../ctru-sys/).
## Getting Started

11
ctru-rs/src/error.rs

@ -1,6 +1,7 @@ @@ -1,6 +1,7 @@
//! Error handling interface.
//!
//! This module holds the generic error and result types to interface with [`ctru_sys`] and the safe wrapper.
//! This module holds the generic error and result types to interface with `ctru_sys` and the [`ctru-rs`](crate) safe wrapper.
use std::borrow::Cow;
use std::error;
use std::ffi::CStr;
@ -9,12 +10,12 @@ use std::ops::{ControlFlow, FromResidual, Try}; @@ -9,12 +10,12 @@ use std::ops::{ControlFlow, FromResidual, Try};
use ctru_sys::result::{R_DESCRIPTION, R_LEVEL, R_MODULE, R_SUMMARY};
/// Custom type alias for generic `ctru` operations.
/// Custom type alias for generic [`ctru-rs`](crate) operations.
///
/// This type is compatible with `ctru-sys` result codes.
/// This type is compatible with `ctru-sys::Result` codes.
pub type Result<T> = ::std::result::Result<T, Error>;
/// Validity checker of raw [`ctru_sys::Result`] codes.
/// Validity checker of raw `ctru_sys::Result` codes.
///
/// This struct supports the "try" syntax (`?`) to convert to an [`Error::Os`].
///
@ -72,7 +73,7 @@ impl<T> FromResidual<Error> for Result<T> { @@ -72,7 +73,7 @@ impl<T> FromResidual<Error> for Result<T> {
}
}
/// The generic error enum returned by `ctru` functions.
/// The generic error enum returned by [`ctru-rs`](crate) functions.
///
/// This error enum supports parsing and displaying [`ctru_sys::Result`] codes.
#[non_exhaustive]

4
ctru-rs/src/lib.rs

@ -6,7 +6,7 @@ @@ -6,7 +6,7 @@
//! Thanks to it, developers can access the underlying system services and the console's hardware to develop userland applications
//! (such as [HID devices](crate::services::hid), [network capabilities](crate::services::soc), [graphics](crate::services::gfx), [built-in cameras](crate::services::cam), etc.).
//!
//! Among these features, `ctru-rs` also automatically includes functionality to properly integrate the Rust `std` with the console's operating system,
//! Among these features, [`ctru-rs`](crate) also automatically includes functionality to properly integrate the Rust `std` with the console's operating system,
//! which the developer would otherwise need to implement manually.
//!
//! # Usage
@ -53,7 +53,7 @@ macro_rules! from_impl { @@ -53,7 +53,7 @@ macro_rules! from_impl {
};
}
/// Activate the custom `ctru-rs` panic handler.
/// Activate the custom [`ctru-rs`](crate) panic handler.
///
/// With this implementation, the main thread will stop and try to print debug info to an available [`Console`](console::Console).
/// In case it fails to find an active [`Console`](console::Console) the program will just exit.

18
ctru-rs/src/linear.rs

@ -1,11 +1,12 @@ @@ -1,11 +1,12 @@
//! Linear memory allocator
//! LINEAR memory allocator.
//!
//! 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).
//! 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 hardware processors (such as the GPU and the DSP).
//!
//! Resources:<br>
//! <https://github.com/devkitPro/libctru/blob/master/libctru/source/allocator/linear.cpp><br>
//! <https://www.3dbrew.org/wiki/Memory_layout>
//! # Additional Resources
//!
//! - <https://github.com/devkitPro/libctru/blob/master/libctru/source/allocator/linear.cpp><br>
//! - <https://www.3dbrew.org/wiki/Memory_layout>
use std::alloc::{AllocError, Allocator, Layout};
use std::ptr::NonNull;
@ -15,13 +16,14 @@ use std::ptr::NonNull; @@ -15,13 +16,14 @@ use std::ptr::NonNull;
// Sadly the linear memory allocator included in `libctru` doesn't implement `linearRealloc` at the time of these additions,
// but the default fallback of the `std` will take care of that for us.
/// [`Allocator`](std::alloc::Allocator) struct for LINEAR memory
/// [`Allocator`](std::alloc::Allocator) struct for LINEAR memory.
///
/// To use this struct the main crate must activate the `allocator_api` unstable feature.
#[derive(Copy, Clone, Default, Debug)]
pub struct LinearAllocator;
impl LinearAllocator {
/// Returns the amount of free space left in the LINEAR sector
/// Returns the amount of free space left in the LINEAR memory sector.
#[doc(alias = "linearSpaceFree")]
pub fn free_space() -> u32 {
unsafe { ctru_sys::linearSpaceFree() }

2
ctru-rs/src/services/am.rs

@ -4,7 +4,7 @@ @@ -4,7 +4,7 @@
//! - Read the installed applications on the console and their information (depending on the install location).
//! - Install compatible applications to the console.
//!
//! TODO: `ctru-rs` doesn't support installing or uninstalling titles yet.
//! TODO: [`ctru-rs`](crate) doesn't support installing or uninstalling titles yet.
use crate::error::ResultCode;
use crate::services::fs::FsMediaType;

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

@ -3,13 +3,13 @@ @@ -3,13 +3,13 @@
//! Most of the 3DS console's functionalities (when writing user-land homebrew) are accessible via services,
//! which need to be initialized before accessing any particular feature.
//!
//! To ensure safety while using the underlying services, `ctru-rs` leverages Rust's lifetime model.
//! To ensure safety while using the underlying services, [`ctru-rs`](crate) leverages Rust's lifetime model.
//! After initializing the handle for a specific service (e.g. [`Apt`](apt::Apt)) the service will be accessible as long as there is at least one handle "alive".
//! As such, handles should be dropped *after* the use of a specific service. This is particularly important for services which are necessary for functionality
//! "outside" their associated methods, such as [`RomFS`](romfs::RomFS), which creates an accessible virtual filesystem, or [`Soc`](soc::Soc),
//! which enables all network communications via sockets.
//!
//! In `ctru-rs` some services only allow a single handle to be created at a time, to ensure a safe and controlled environment.
//! In [`ctru-rs`](crate) some services only allow a single handle to be created at a time, to ensure a safe and controlled environment.
pub mod am;
pub mod apt;

Loading…
Cancel
Save