1#[cfg(feature = "serde")]
2use serde::Serialize;
3use std::collections::HashMap;
4use std::str::FromStr;
5#[cfg_attr(feature = "serde", derive(Serialize))]
6#[derive(Default)]
7pub struct UEvent {
8 attributes: HashMap<String, String>,
9}
10
11impl FromStr for UEvent {
12 type Err = std::io::Error;
13 fn from_str(lines: &str) -> Result<Self, std::io::Error> {
14 let mut uevent = UEvent::default();
15 for line in lines.lines() {
16 let mut kv = line.split('=');
17 if let Some(key) = kv.next() {
18 uevent
19 .attributes
20 .insert(key.into(), kv.next().unwrap_or("").into());
21 }
22 }
23 if uevent.attributes.is_empty() {
24 return Err(std::io::Error::from_raw_os_error(0));
25 }
26 Ok(uevent)
27 }
28}
29
30impl UEvent {
31 pub fn value(&self, key: &str) -> Option<&String> {
32 self.attributes.get(key)
33 }
34}