use super::Reader;
use crate::error::Result;
#[derive(Debug, Clone, Copy)]
pub struct NameList<'a>(pub &'a [u8]);
impl<'a> NameList<'a> {
pub fn read(r: &mut Reader<'a>) -> Result<Self> {
Ok(NameList(r.read_string()?))
}
pub fn iter(&self) -> impl Iterator<Item = &'a [u8]> + '_ {
self.0.split(|&b| b == b',').filter(|s| !s.is_empty())
}
pub fn negotiate<'b>(ours: &'b [&'b str], theirs: NameList<'_>) -> Option<&'b str> {
for name in ours {
for t in theirs.iter() {
if t == name.as_bytes() {
return Some(name);
}
}
}
None
}
}