use custom errors in VmcExtBlendVal

This commit is contained in:
Cassandra de la Cruz-Munoz 2023-12-31 10:55:09 -05:00
parent 9bcfdeec81
commit c88dc87e50
Signed by: cassdlcm
GPG Key ID: BFEBACEA812DDA70

View File

@ -362,19 +362,19 @@ impl MessageBehavior for VmcExtBlendVal {
],
};
}
fn from_osc_message(msg: OscMessage) -> Result<Self, String> {
fn from_osc_message(msg: OscMessage) -> Result<Self, FromMessageErr> {
let name: String;
let value: f32;
if msg.args.len() != 2 {
return Err(String::from("arg count invalid"));
return Err(FromMessageErr::ArgCount(ArgCountErr { expected_in: vec![2], actual: msg.args.len(), addr: msg.addr}));
}
match &msg.args[0] {
OscType::String(s) => name = s.to_owned(),
_ => return Err(String::from("arg type invalid")),
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::String(String::new()), actual: msg.args[0], addr: msg.addr, arg_count: 0})),
}
match msg.args[1] {
OscType::Float(f) => value = f,
_ => return Err(String::from("arg type invalid")),
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Float(0.0), actual: msg.args[1], addr: msg.addr, arg_count: 1})),
}
return Ok(VmcExtBlendVal { name, value });
}