use custom errors in VmcExtSetEye

This commit is contained in:
Cassandra de la Cruz-Munoz 2023-12-31 13:18:47 -05:00
parent 9aa00b5b36
commit 3f01f2f3fd
Signed by: cassdlcm
GPG Key ID: BFEBACEA812DDA70

View File

@ -1316,9 +1316,9 @@ impl MessageBehavior for VmcExtSetEye {
] ]
}; };
} }
fn from_osc_message(msg: OscMessage) -> Result<Self, String> { fn from_osc_message(msg: OscMessage) -> Result<Self, FromMessageErr> {
if msg.args.len() != 4 { if msg.args.len() != 4 {
return Err(String::from("arg count invalid")); return Err(FromMessageErr::ArgCount(ArgCountErr { expected_in: vec![4], actual: msg.args.len(), addr: msg.addr}));
} }
let enable: i32; let enable: i32;
let x: f32; let x: f32;
@ -1326,20 +1326,20 @@ impl MessageBehavior for VmcExtSetEye {
let z: f32; let z: f32;
match msg.args[0] { match msg.args[0] {
OscType::Int(i) => enable = i, OscType::Int(i) => enable = i,
_ => return Err(String::from("arg type invalid")), _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[0], addr: msg.addr, arg_count: 0}))
} }
match msg.args[1] { match msg.args[1] {
OscType::Float(f) => x = f, OscType::Float(f) => x = f,
_ => return Err(String::from("arg type invalid")), _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[1], addr: msg.addr, arg_count: 1}))
} }
match msg.args[2] { match msg.args[2] {
OscType::Float(f) => y = f, OscType::Float(f) => y = f,
_ => return Err(String::from("arg type invalid")), _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[2], addr: msg.addr, arg_count: 2}))
} }
match msg.args[3] { match msg.args[3] {
OscType::Float(f) => z = f, OscType::Float(f) => z = f,
_ => return Err(String::from("arg type invalid")), _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[3], addr: msg.addr, arg_count: 3}))
} }
return Ok(VmcExtSetEye { enable, position: Vector3::new(x, y, z)}) return Ok(VmcExtSetEye { enable, position: Vector3::new(x, y, z)})
} }