Struct PTMUser

Source
pub struct PTMUser { /* private fields */ }
Expand description

Handle to the PTM:User service.

Implementations§

Source§

impl PTMUser

Source

pub fn new() -> Result<Self>

Initialize a new service handle.

§Errors

This function will return an error if the service was unable to be initialized. Since this service requires no special or elevated permissions, errors are rare in practice.

§Example
use ctru::services::ptm::user::PTMUser;

let ptmu = PTMUser::new()?;
Source

pub fn shell_state(&self) -> Result<ShellState>

Returns whether the console’s clamshell is closed or open.

§Example
use ctru::services::ptm::user::{PTMUser, ShellState};

let ptmu = PTMUser::new()?;

let state = ptmu.shell_state()?;

match state {
    ShellState::Closed => println!("The shell is closed! How are you able to read this?"),
    ShellState::Open => println!("The shell is open! That might seem obvious to you."),
}
Source

pub fn battery_level(&self) -> Result<BatteryLevel>

Returns the console’s current battery charge level.

§Example
use ctru::services::ptm::user::{PTMUser, BatteryLevel};

let ptmu = PTMUser::new()?;

let charge = ptmu.battery_level()?;

if charge <= BatteryLevel::Low {
    println!("You should put the console to charge!");
}
Source

pub fn is_charging(&self) -> Result<bool>

Returns whether the console is currently charging its battery.

§Example
use ctru::services::ptm::user::PTMUser;

let ptmu = PTMUser::new()?;

let is_charging = ptmu.is_charging()?;

if is_charging {
    println!("That is one juicy power line.");
}
Source

pub fn step_count(&self) -> Result<u32>

Returns the console’s total step count.

§Example
use ctru::services::ptm::user::PTMUser;

let ptmu = PTMUser::new()?;

let steps = ptmu.step_count()?;

println!("You accumulated {steps} steps. Don't stop moving!");

Auto Trait Implementations§

§

impl Freeze for PTMUser

§

impl !RefUnwindSafe for PTMUser

§

impl !Send for PTMUser

§

impl Sync for PTMUser

§

impl Unpin for PTMUser

§

impl !UnwindSafe for PTMUser

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.