1use std::fmt::{Display, Formatter};
16use std::str::FromStr;
17
18use snafu::OptionExt;
19
20pub mod error;
21pub mod selector;
22
23#[derive(Debug, Clone, Eq, PartialEq)]
24pub struct DisplayProcessId {
25 pub server_addr: String,
26 pub id: u32,
27}
28
29impl Display for DisplayProcessId {
30 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
31 write!(f, "{}/{}", self.server_addr, self.id)
32 }
33}
34
35impl TryFrom<&str> for DisplayProcessId {
36 type Error = error::Error;
37
38 fn try_from(value: &str) -> Result<Self, Self::Error> {
39 let mut split = value.split('/');
40 let server_addr = split
41 .next()
42 .context(error::ParseProcessIdSnafu { s: value })?
43 .to_string();
44 let id = split
45 .next()
46 .context(error::ParseProcessIdSnafu { s: value })?;
47 let id = u32::from_str(id)
48 .ok()
49 .context(error::ParseProcessIdSnafu { s: value })?;
50 Ok(DisplayProcessId { server_addr, id })
51 }
52}