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