How to get a u8 from tuple struct with u8?

Hi,

A hal library has a tuple struct as below for gpio pin.

pub struct Pin(u8);

I am trying to use this value as shift count. How to convert to u8? casting as below, threw an compilation error, coz tuple can't be casted to u8.
let p = pin as u8;

an as expression can only be used to convert between primitive types or to coerce to a specific trait object

The u8 field is private; you can only access it if the crate provides a function or method to access it.

2 Likes

OTOH, if it is a public field, you can use numbered field access or pattern matching to extract it:

let p = pin.0;
// or:
let Pin(p) = pin;