use crate::std::string::String;
use crate::std::vec::Vec;
use rama_core::extensions::Extension;
#[derive(Debug, Clone, PartialEq, Eq, Hash, Extension)]
#[extension(tags(net))]
pub enum UserId {
Username(String),
Token(Vec<u8>),
Anonymous,
}
impl PartialEq<str> for UserId {
fn eq(&self, other: &str) -> bool {
match self {
Self::Username(username) => username == other,
Self::Token(token) => {
let other = other.as_bytes();
token == other
}
Self::Anonymous => false,
}
}
}
impl PartialEq<UserId> for str {
fn eq(&self, other: &UserId) -> bool {
other == self
}
}
impl PartialEq<[u8]> for UserId {
fn eq(&self, other: &[u8]) -> bool {
match self {
Self::Username(username) => {
let username_bytes = username.as_bytes();
username_bytes == other
}
Self::Token(token) => token == other,
Self::Anonymous => false,
}
}
}
impl PartialEq<UserId> for [u8] {
fn eq(&self, other: &UserId) -> bool {
other == self
}
}
impl PartialEq<String> for UserId {
fn eq(&self, other: &String) -> bool {
match self {
Self::Username(username) => username == other,
Self::Token(token) => {
let other = other.as_bytes();
token == other
}
Self::Anonymous => false,
}
}
}
impl PartialEq<UserId> for String {
fn eq(&self, other: &UserId) -> bool {
other == self
}
}
impl PartialEq<Vec<u8>> for UserId {
fn eq(&self, other: &Vec<u8>) -> bool {
match self {
Self::Username(username) => {
let username_bytes = username.as_bytes();
username_bytes == other
}
Self::Token(token) => token == other,
Self::Anonymous => false,
}
}
}
impl PartialEq<UserId> for Vec<u8> {
fn eq(&self, other: &UserId) -> bool {
other == self
}
}