use alloc::string::String;
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct SessionId(pub String);
impl SessionId {
#[must_use]
pub fn new(token: impl Into<String>) -> Self {
Self(token.into())
}
#[must_use]
pub fn as_str(&self) -> &str {
&self.0
}
#[must_use]
pub fn is_valid(&self) -> bool {
!self.0.is_empty()
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn session_id_carries_token_string() {
let s = SessionId::new("abc123");
assert_eq!(s.as_str(), "abc123");
assert!(s.is_valid());
}
#[test]
fn empty_session_id_is_invalid() {
let s = SessionId::new("");
assert!(!s.is_valid());
}
}