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