dbus_server_address_parser/decode/
family.rs

1use crate::decode::unescape::{unescape, UnescapeError};
2use crate::Family;
3use std::convert::TryFrom;
4use thiserror::Error;
5
6#[derive(Error, Debug, Clone)]
7pub enum FamilyError {
8    #[error("Could not unescape: {0}")]
9    UnescapeError(#[from] UnescapeError),
10    #[error("Unknown value")]
11    UnknownValue,
12}
13
14impl TryFrom<&str> for Family {
15    type Error = FamilyError;
16
17    fn try_from(value: &str) -> Result<Self, Self::Error> {
18        let value = unescape(value)?;
19        match value.as_ref() {
20            "ipv4" => Ok(Family::Ipv4),
21            "ipv6" => Ok(Family::Ipv6),
22            _ => Err(FamilyError::UnknownValue),
23        }
24    }
25}