use std::{borrow::Cow, fmt, str};
use serde::{Deserialize, Serialize};
use super::EmptyStreamName;
#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
pub struct ID<'a>(pub(crate) Cow<'a, str>);
impl<'a> ID<'a> {
pub const COMPOUND_ID_SEPARATOR: char = '+';
pub fn new(id: impl Into<Cow<'a, str>>) -> Result<Self, EmptyStreamName> {
let id = id.into();
Ok(ID(id))
}
pub fn cardinal_id(&self) -> &str {
self.split_once(Self::COMPOUND_ID_SEPARATOR)
.map(|(id, _)| id)
.unwrap_or(&self.0)
}
}
impl_eq! { ID<'a>, &'b str }
impl_eq! { ID<'a>, String }
impl_as_ref_str! { ID, ID<'a>, ID<'static> }