use custom errors in VmcExtLight
This commit is contained in:
parent
577c1aa872
commit
3766cd2104
28
src/lib.rs
28
src/lib.rs
|
@ -896,9 +896,9 @@ impl MessageBehavior for VmcExtLight {
|
|||
],
|
||||
};
|
||||
}
|
||||
fn from_osc_message(msg: OscMessage) -> Result<Self, String> {
|
||||
fn from_osc_message(msg: OscMessage) -> Result<Self, FromMessageErr> {
|
||||
if msg.args.len() != 12 {
|
||||
return Err(String::from("arg count invalid"));
|
||||
return Err(FromMessageErr::ArgCount(ArgCountErr { expected_in: vec![12], actual: msg.args.len(), addr: msg.addr}));
|
||||
}
|
||||
let name: String;
|
||||
let mut origin = Vector3::new(0.0, 0.0, 0.0);
|
||||
|
@ -906,51 +906,51 @@ impl MessageBehavior for VmcExtLight {
|
|||
let mut color = Color::from_rgba(0.0, 0.0, 0.0, 0.0);
|
||||
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) => origin.x = 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) => origin.y = 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) => origin.z = 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})),
|
||||
}
|
||||
match msg.args[4] {
|
||||
OscType::Float(f) => quat.x = f,
|
||||
_ => return Err(String::from("arg type invalid")),
|
||||
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Float(0.0), actual: msg.args[4], addr: msg.addr, arg_count: 4})),
|
||||
}
|
||||
match msg.args[5] {
|
||||
OscType::Float(f) => quat.y = f,
|
||||
_ => return Err(String::from("arg type invalid")),
|
||||
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Float(0.0), actual: msg.args[5], addr: msg.addr, arg_count: 5})),
|
||||
}
|
||||
match msg.args[6] {
|
||||
OscType::Float(f) => quat.z = f,
|
||||
_ => return Err(String::from("arg type invalid")),
|
||||
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Float(0.0), actual: msg.args[6], addr: msg.addr, arg_count: 6})),
|
||||
}
|
||||
match msg.args[7] {
|
||||
OscType::Float(f) => quat.w = f,
|
||||
_ => return Err(String::from("arg type invalid")),
|
||||
_ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Float(0.0), actual: msg.args[7], addr: msg.addr, arg_count: 7})),
|
||||
}
|
||||
match msg.args[8] {
|
||||
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[8], addr: msg.addr, arg_count: 8})),
|
||||
}
|
||||
match msg.args[9] {
|
||||
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[9], addr: msg.addr, arg_count: 9})),
|
||||
}
|
||||
match msg.args[10] {
|
||||
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[10], addr: msg.addr, arg_count: 10})),
|
||||
}
|
||||
match msg.args[11] {
|
||||
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[11], addr: msg.addr, arg_count: 11})),
|
||||
}
|
||||
return Ok(VmcExtLight {
|
||||
name,
|
||||
|
|
Loading…
Reference in New Issue
Block a user