use custom errors in VmcExtSettingColor

This commit is contained in:
Cassandra de la Cruz-Munoz 2023-12-31 12:15:46 -05:00
parent 5aebb1cc63
commit 5dc7aefa1c
Signed by: cassdlcm
GPG Key ID: BFEBACEA812DDA70

View File

@ -1080,26 +1080,26 @@ impl MessageBehavior for VmcExtSettingColor {
],
};
}
fn from_osc_message(msg: OscMessage) -> Result<Self, String> {
fn from_osc_message(msg: OscMessage) -> Result<Self, FromMessageErr> {
if msg.args.len() != 4 {
return Err(String::from("argj count invalid"));
return Err(FromMessageErr::ArgCount(ArgCountErr { expected_in: vec![4], actual: msg.args.len(), addr: msg.addr}));
}
let mut color = Color::from_rgba(0.0, 0.0, 0.0, 0.0);
match msg.args[0] {
OscType::Float(f) => color.r = f,
_ => return Err(String::from("arg type invalid")),
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Float(0.0), actual: msg.args[0], addr: msg.addr, arg_count: 0})),
}
match msg.args[1] {
OscType::Float(f) => color.g = 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})),
}
match msg.args[2] {
OscType::Float(f) => color.b = f,
_ => return Err(String::from("arg type invalid")),
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Float(0.0), actual: msg.args[2], addr: msg.addr, arg_count: 2})),
}
match msg.args[3] {
OscType::Float(f) => color.a = f,
_ => return Err(String::from("arg type invalid")),
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Float(0.0), actual: msg.args[3], addr: msg.addr, arg_count: 3})),
}
return Ok(VmcExtSettingColor { color });
}