postgres_conn_str/parser/authority/
mod.rs1pub(crate) mod host;
2#[cfg(test)]
3mod tests;
4pub(crate) mod userinfo;
5
6use super::Res;
7use host::{hostspecs, HostSpec};
8use nom::{
9 bytes::complete::tag,
10 combinator::{fail, map, opt},
11 sequence::{terminated, tuple},
12};
13use userinfo::{userinfo, UserSpec};
14
15#[derive(Debug, Default, PartialEq, Eq)]
16pub(crate) struct Authority {
17 pub userspec: Option<UserSpec>,
18 pub hostspec: Vec<HostSpec>,
19}
20
21pub(crate) fn authority(i: &str) -> Res<&str, Authority> {
24 match map(
29 tuple((opt(terminated(userinfo, tag("@"))), hostspecs)),
30 |(userspec, hostspec)| Authority { userspec, hostspec },
31 )(i)
32 {
33 Ok((rem, auth)) if auth.userspec.is_none() && auth.hostspec.is_empty() => fail(rem),
34 u => u,
35 }
36}