use crate::ffi::user_v1 as ffi;
#[doc(hidden)]
pub use ffi::API as FFI_API;
type PlayerId = u64;
#[derive(Clone, Debug, Hash, PartialEq, Eq)]
#[cfg_attr(feature = "with_serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "with_speedy", derive(speedy::Writable, speedy::Readable))]
pub struct UserId(pub String);
impl From<UserId> for Vec<u8> {
fn from(user_id: UserId) -> Self {
user_id.0.into_bytes()
}
}
impl AsRef<[u8]> for UserId {
fn as_ref(&self) -> &[u8] {
self.0.as_bytes()
}
}
const LOCAL_PLAYER_ID: PlayerId = 0;
#[derive(Copy, Clone)]
pub struct User {}
impl User {
pub fn display_name() -> Option<String> {
Self::display_name_of(LOCAL_PLAYER_ID)
}
pub fn id() -> Option<UserId> {
Self::id_of(LOCAL_PLAYER_ID)
}
pub fn id_of(player_id: PlayerId) -> Option<UserId> {
ffi::id_of(player_id)
.ok()
.and_then(|bytes| String::from_utf8(bytes).ok().map(UserId))
}
pub fn display_name_of(player_id: PlayerId) -> Option<String> {
ffi::display_name_of(player_id).ok()
}
}