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