|
|
|
@@ -1,4 +1,9 @@ |
|
|
|
use std::convert::TryFrom; |
|
|
|
|
|
|
|
use anyhow::Result; |
|
|
|
|
|
|
|
use super::RclParameterType; |
|
|
|
use crate::error::RclRustError; |
|
|
|
|
|
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)] |
|
|
|
pub enum ParameterType { |
|
|
|
@@ -14,9 +19,11 @@ pub enum ParameterType { |
|
|
|
StringArray, |
|
|
|
} |
|
|
|
|
|
|
|
impl From<u8> for ParameterType { |
|
|
|
fn from(v: u8) -> Self { |
|
|
|
match v { |
|
|
|
impl TryFrom<u8> for ParameterType { |
|
|
|
type Error = anyhow::Error; |
|
|
|
|
|
|
|
fn try_from(v: u8) -> Result<Self> { |
|
|
|
Ok(match v { |
|
|
|
RclParameterType::PARAMETER_NOT_SET => Self::NotSet, |
|
|
|
RclParameterType::PARAMETER_BOOL => Self::Bool, |
|
|
|
RclParameterType::PARAMETER_INTEGER => Self::Integer, |
|
|
|
@@ -27,7 +34,13 @@ impl From<u8> for ParameterType { |
|
|
|
RclParameterType::PARAMETER_INTEGER_ARRAY => Self::IntegerArray, |
|
|
|
RclParameterType::PARAMETER_DOUBLE_ARRAY => Self::DoubleArray, |
|
|
|
RclParameterType::PARAMETER_STRING_ARRAY => Self::StringArray, |
|
|
|
_ => unreachable!(), |
|
|
|
} |
|
|
|
_ => { |
|
|
|
return Err(RclRustError::OutOfRange(format!( |
|
|
|
"{} cannot be converted into RclParameterType", |
|
|
|
v |
|
|
|
)) |
|
|
|
.into()) |
|
|
|
} |
|
|
|
}) |
|
|
|
} |
|
|
|
} |