pub(crate) mod host;
#[cfg(test)]
mod tests;
pub(crate) mod userinfo;
use super::Res;
use host::{hostspecs, HostSpec};
use nom::{
bytes::complete::tag,
combinator::{fail, map, opt},
sequence::{terminated, tuple},
};
use userinfo::{userinfo, UserSpec};
#[derive(Debug, Default, PartialEq, Eq)]
pub(crate) struct Authority {
pub userspec: Option<UserSpec>,
pub hostspec: Vec<HostSpec>,
}
pub(crate) fn authority(i: &str) -> Res<&str, Authority> {
match map(
tuple((opt(terminated(userinfo, tag("@"))), hostspecs)),
|(userspec, hostspec)| Authority {
userspec,
hostspec,
},
)(i)
{
Ok((rem, auth))
if auth.userspec.is_none() && auth.hostspec.is_empty() =>
{
fail(rem)
},
u => u,
}
}