From 2ba4cce043850f99ff052c93ea317e6c603e056c Mon Sep 17 00:00:00 2001 From: Cassandra de la Cruz-Munoz Date: Sun, 31 Dec 2023 10:51:07 -0500 Subject: [PATCH 01/22] create custom errors --- src/lib.rs | 114 +++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 88 insertions(+), 26 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index d48d15b..fcb87fb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -6,11 +6,54 @@ use rosc::{OscMessage, OscType}; pub trait MessageBehavior { fn to_osc_message(&self) -> OscMessage; - fn from_osc_message(msg: OscMessage) -> Result + fn from_osc_message(msg: OscMessage) -> Result where Self: Sized; } +struct ArgCountErr { + expected_in: Vec, + actual: usize, + addr: String, +} + +struct ArgTypeErr { + expected: OscType, + actual: OscType, + addr: String, + arg_count: usize, +} + +struct IntRangeErr { + expected_lower: i32, + expected_upper: i32, + actual: i32, + addr: String, + arg_count: usize, +} + +struct IntValErr { + expected_in: Vec, + actual: i32, + addr: String, + arg_count: usize, +} + +struct StrValErr { + expected_in: Vec, + actual: String, + addr: String, + arg_count: usize, +} + +enum FromMessageErr { + ArgCount(ArgCountErr), + ArgType(ArgTypeErr), + IntRange(IntRangeErr), + IntVal(IntValErr), + StrVal(StrValErr), +} + struct VmcExtOk { loaded: i32, calibration_state: Option, @@ -33,7 +76,7 @@ impl MessageBehavior for VmcExtOk { } return OscMessage { addr, args }; } - fn from_osc_message(msg: OscMessage) -> Result { + fn from_osc_message(msg: OscMessage) -> Result { let mut result = VmcExtOk { loaded: -1, calibration_state: None, @@ -46,11 +89,11 @@ impl MessageBehavior for VmcExtOk { result.loaded = i; } _ => { - return Err(String::from("arg type invalid")); + return Err(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Int(0), actual: msg.args[0],addr: msg.addr.to_owned(), arg_count: 0})); } } } else { - return Err(String::from("arg count invalid")); + return Err(FromMessageErr::ArgCount(ArgCountErr { expected_in: vec![1, 3, 4], actual: msg.args.len(), addr: msg.addr.to_owned()})); } if msg.args.len() == 3 || msg.args.len() == 4 { match msg.args[1] { @@ -58,7 +101,7 @@ impl MessageBehavior for VmcExtOk { result.calibration_state = Some(i); } _ => { - return Err(String::from("arg type invalid")); + return Err(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Int(0), actual: msg.args[1], addr: msg.addr.to_owned(), arg_count: 1})); } } match msg.args[2] { @@ -66,7 +109,7 @@ impl MessageBehavior for VmcExtOk { result.calibration_mode = Some(i); } _ => { - return Err(String::from("arg type invalid")); + return Err(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Int(0), actual: msg.args[2], addr: msg.addr.to_owned(), arg_count: 2})); } } } @@ -76,7 +119,7 @@ impl MessageBehavior for VmcExtOk { result.tracking_status = Some(i); } _ => { - return Err(String::from("arg type invalid")); + return Err(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Int(0), actual: msg.args[3], addr: msg.addr.to_owned(), arg_count: 3})); } } } @@ -95,13 +138,13 @@ impl MessageBehavior for VmcExtT { args: vec![OscType::from(self.time)], }; } - fn from_osc_message(msg: OscMessage) -> Result { + fn from_osc_message(msg: OscMessage) -> Result { if msg.args.len() != 1 { - return Err(String::from("arg count invalid")); + return Err(FromMessageErr::ArgCount(ArgCountErr { expected_in: vec![1], actual: msg.args.len(), addr: msg.addr})); } match msg.args[0] { OscType::Float(f) => return Ok(VmcExtT { time: 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})), } } } @@ -139,26 +182,26 @@ impl MessageBehavior for VmcExtRootPos { } return OscMessage { addr, args }; } - fn from_osc_message(msg: OscMessage) -> Result { + fn from_osc_message(msg: OscMessage) -> Result { let mut result: VmcExtRootPos; if msg.args.len() == 8 || msg.args.len() == 14 { let mut origin = Vector3::new(0.0, 0.0, 0.0); let name: String; 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})), } let mut quat = Quaternion { x: 0.0, @@ -168,19 +211,19 @@ impl MessageBehavior for VmcExtRootPos { }; 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})), } result = VmcExtRootPos { name, @@ -189,7 +232,7 @@ impl MessageBehavior for VmcExtRootPos { mr_offset: None, }; } else { - return Err(String::from("arg count invalid")); + return Err(FromMessageErr::ArgCount(ArgCountErr { expected_in: vec![8, 14], actual: msg.args.len(), addr: msg.addr})); } if msg.args.len() == 14 { result.mr_scale = Some(Vector3 { @@ -204,27 +247,27 @@ impl MessageBehavior for VmcExtRootPos { }); match msg.args[8] { OscType::Float(f) => result.mr_scale.unwrap().x = 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) => result.mr_scale.unwrap().y = 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) => result.mr_scale.unwrap().z = 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) => result.mr_offset.unwrap().x = 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})), } match msg.args[12] { OscType::Float(f) => result.mr_offset.unwrap().y = f, - _ => return Err(String::from("arg type invalid")), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Float(0.0), actual: msg.args[12], addr: msg.addr, arg_count: 12})), } match msg.args[13] { OscType::Float(f) => result.mr_offset.unwrap().z = f, - _ => return Err(String::from("arg type invalid")), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Float(0.0), actual: msg.args[13], addr: msg.addr, arg_count: 13})), } } return Ok(result); @@ -1310,3 +1353,22 @@ impl MessageBehavior for VmcExtSetEye { return Ok(VmcExtSetEye { enable, position: Vector3::new(x, y, z)}) } } + +struct VmcExtSetRes { + response: String +} + +impl MessageBehavior for VmcExtSetRes { + fn to_osc_message(&self) -> OscMessage { + return OscMessage{addr: String::from("/VMC/Ext/Set/Res"), args: vec![OscType::from(self.response.to_owned())]}; + } + fn from_osc_message(msg: OscMessage) -> Result { + if msg.args.len() != 1 { + return Err(String::from("arg count invalid")); + } + match &msg.args[0] { + OscType::String(s) => return Ok(VmcExtSetRes{response: s.to_owned()}), + _ => return Err(String::from("arg type invalid")) + } + } +} -- 2.30.2 From 9bcfdeec812790bde6201d71b7cda2a20848fbca Mon Sep 17 00:00:00 2001 From: Cassandra de la Cruz-Munoz Date: Sun, 31 Dec 2023 10:53:07 -0500 Subject: [PATCH 02/22] use custom errors in VmcExtBonePos --- src/lib.rs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index fcb87fb..bd3c724 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -296,27 +296,27 @@ impl MessageBehavior for VmcExtBonePos { ], }; } - fn from_osc_message(msg: OscMessage) -> Result { + fn from_osc_message(msg: OscMessage) -> Result { let name: String; let mut origin = Vector3::new(0.0, 0.0, 0.0); if msg.args.len() != 8 { - return Err(String::from("arg count invalid")); + return Err(FromMessageErr::ArgCount(ArgCountErr { expected_in: vec![8], 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) => 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})), } let mut quat = Quaternion { x: 0.0, @@ -326,19 +326,19 @@ impl MessageBehavior for VmcExtBonePos { }; 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})), } return Ok(VmcExtBonePos { name, -- 2.30.2 From c88dc87e506f3d6b12a4f9eedeca1165e435c7d4 Mon Sep 17 00:00:00 2001 From: Cassandra de la Cruz-Munoz Date: Sun, 31 Dec 2023 10:55:09 -0500 Subject: [PATCH 03/22] use custom errors in VmcExtBlendVal --- src/lib.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index bd3c724..cafa7b7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -362,19 +362,19 @@ impl MessageBehavior for VmcExtBlendVal { ], }; } - fn from_osc_message(msg: OscMessage) -> Result { + fn from_osc_message(msg: OscMessage) -> Result { 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 }); } -- 2.30.2 From a4b674c3d8ea98161a5c194df5cf2acc2e8e8524 Mon Sep 17 00:00:00 2001 From: Cassandra de la Cruz-Munoz Date: Sun, 31 Dec 2023 11:52:55 -0500 Subject: [PATCH 04/22] use custom errors in VmcExtCam --- src/lib.rs | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index cafa7b7..07a94c0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -404,9 +404,9 @@ impl MessageBehavior for VmcExtCam { ], }; } - fn from_osc_message(msg: OscMessage) -> Result { + fn from_osc_message(msg: OscMessage) -> Result { if msg.args.len() != 9 { - return Err(String::from("arg count invalid")); + return Err(FromMessageErr::ArgCount(ArgCountErr { expected_in: vec![9], actual: msg.args.len(), addr: msg.addr})); } let name: String; let mut origin = Vector3::new(0.0, 0.0, 0.0); @@ -414,39 +414,39 @@ impl MessageBehavior for VmcExtCam { let fov: f32; 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) => fov = 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})), } return Ok(VmcExtCam { name, -- 2.30.2 From 0ce9ee167d0b9bd5ed5d1c3a196be9aac1347e59 Mon Sep 17 00:00:00 2001 From: Cassandra de la Cruz-Munoz Date: Sun, 31 Dec 2023 11:56:22 -0500 Subject: [PATCH 05/22] use custom errors in VmcExtCon --- src/lib.rs | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 07a94c0..c3a580d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -479,9 +479,9 @@ impl MessageBehavior for VmcExtCon { ], }; } - fn from_osc_message(msg: OscMessage) -> Result { + fn from_osc_message(msg: OscMessage) -> Result { if msg.args.len() != 7 { - return Err(String::from("arg count invalid")); + return Err(FromMessageErr::ArgCount(ArgCountErr { expected_in: vec![7], actual: msg.args.len(), addr: msg.addr})); } let active: i32; let name: String; @@ -490,40 +490,40 @@ impl MessageBehavior for VmcExtCon { let mut axis = Vector3::new(0.0, 0.0, 0.0); match msg.args[0] { OscType::Int(i) => active = i, - _ => return Err(String::from("arg type invalid")), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Int(0), actual: msg.args[0], addr: msg.addr, arg_count: 0})), } if active > 2 || active < 0 { - return Err(String::from("arg value invalid")); + return Err(FromMessageErr::IntRange(IntRangeErr { expected_lower: 0, expected_upper: 2, actual: active, addr: msg.addr, arg_count: 0})); } match &msg.args[1] { OscType::String(s) => name = s.to_owned(), - _ => return Err(String::from("arg value invalid")), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::String(String::new()), actual: msg.args[1], addr: msg.addr, arg_count: 1})), } match msg.args[2] { OscType::Int(i) => is_left = i, - _ => return Err(String::from("arg type invalid")), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Int(0), actual: msg.args[2], addr: msg.addr, arg_count: 2})), } if is_left < 0 || is_left > 1 { - return Err(String::from("arg value invalid")); + return Err(FromMessageErr::IntRange(IntRangeErr { expected_lower: 0, expected_upper: 1, actual: active, addr: msg.addr, arg_count: 2})); } match msg.args[3] { OscType::Int(i) => is_touch = i, - _ => return Err(String::from("arg type invalid")), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Int(0), actual: msg.args[3], addr: msg.addr, arg_count: 3})), } if is_touch < 0 || is_touch > 1 { - return Err(String::from("arg value invalid")); + return Err(FromMessageErr::IntRange(IntRangeErr { expected_lower: 0, expected_upper: 1, actual: active, addr: msg.addr, arg_count: 3})); } match msg.args[4] { OscType::Float(f) => axis.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) => axis.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) => axis.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})), } return Ok(VmcExtCon { active, -- 2.30.2 From cd4278b72a1b51c52e5fe8520ff789fd054eb352 Mon Sep 17 00:00:00 2001 From: Cassandra de la Cruz-Munoz Date: Sun, 31 Dec 2023 11:58:23 -0500 Subject: [PATCH 06/22] use custom errors in VmcExtKey --- src/lib.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index c3a580d..ea3a708 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -558,9 +558,9 @@ impl MessageBehavior for VmcExtKey { args, }; } - fn from_osc_message(msg: OscMessage) -> Result { + fn from_osc_message(msg: OscMessage) -> Result { if msg.args.len() != 3 { - return Err(String::from("arg count invalid")); + return Err(FromMessageErr::ArgCount(ArgCountErr { expected_in: vec![3], actual: msg.args.len(), addr: msg.addr})); } let active: bool; let name: String; @@ -572,18 +572,18 @@ impl MessageBehavior for VmcExtKey { } else if i == 0 { active = false; } else { - return Err(String::from("arg value invalid")); + return Err(FromMessageErr::IntRange(IntRangeErr { expected_lower: 0, expected_upper: 1, actual: i, addr: msg.addr, arg_count: 0})); } } - _ => return Err(String::from("arg type invalid")), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Int(0), actual: msg.args[0], addr: msg.addr, arg_count: 0})), } match &msg.args[1] { 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[1], addr: msg.addr, arg_count: 1})), } match msg.args[2] { OscType::Int(i) => keycode = i, - _ => return Err(String::from("arg type invalid")), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Int(0), actual: msg.args[2], addr: msg.addr, arg_count: 2})), } return Ok(VmcExtKey { active, -- 2.30.2 From c0645d928201fc5f8563374d62d90af7dadbb37c Mon Sep 17 00:00:00 2001 From: Cassandra de la Cruz-Munoz Date: Sun, 31 Dec 2023 12:00:00 -0500 Subject: [PATCH 07/22] use custom errors in VmcExtMidiNote --- src/lib.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index ea3a708..ad76f18 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -618,9 +618,9 @@ impl MessageBehavior for VmcExtMidiNote { args, }; } - fn from_osc_message(msg: OscMessage) -> Result { + fn from_osc_message(msg: OscMessage) -> Result { 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 active: bool; let channel: i32; @@ -633,22 +633,22 @@ impl MessageBehavior for VmcExtMidiNote { } else if i == 0 { active = false; } else { - return Err(String::from("arg value invalid")); + return Err(FromMessageErr::IntRange(IntRangeErr { expected_lower: 0, expected_upper: 1, actual: i, addr: msg.addr, arg_count: 0})); } } - _ => return Err(String::from("arg type invalid")), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Int(0), actual: msg.args[0], addr: msg.addr, arg_count: 0})), } match msg.args[1] { OscType::Int(i) => channel = i, - _ => return Err(String::from("arg type invalid")), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Int(0), actual: msg.args[1], addr: msg.addr, arg_count: 1})), } match msg.args[2] { OscType::Int(i) => note = i, - _ => return Err(String::from("arg type invalid")), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Int(0), actual: msg.args[2], addr: msg.addr, arg_count: 2})), } match msg.args[3] { OscType::Float(f) => velocity = 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(VmcExtMidiNote { active, -- 2.30.2 From 75a541cc2a536b45bd53b7eda111e662a35ac238 Mon Sep 17 00:00:00 2001 From: Cassandra de la Cruz-Munoz Date: Sun, 31 Dec 2023 12:00:52 -0500 Subject: [PATCH 08/22] use custom errors in VmcExtMidiCcVal --- src/lib.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index ad76f18..ce125a5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -671,19 +671,19 @@ impl MessageBehavior for VmcExtMidiCcVal { args: vec![OscType::from(self.knob), OscType::from(self.value)], }; } - fn from_osc_message(msg: OscMessage) -> Result { + fn from_osc_message(msg: OscMessage) -> Result { 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})); } let knob: i32; let value: f32; match msg.args[0] { OscType::Int(i) => knob = i, - _ => return Err(String::from("arg type invalid")), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Int(0), 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(VmcExtMidiCcVal { knob, value }); } -- 2.30.2 From 20142c69227093f758117e30297faa514c00b9e2 Mon Sep 17 00:00:00 2001 From: Cassandra de la Cruz-Munoz Date: Sun, 31 Dec 2023 12:02:44 -0500 Subject: [PATCH 09/22] use custom errors in VmcExtMidiCcBit --- src/lib.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index ce125a5..de52dfd 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -707,15 +707,15 @@ impl MessageBehavior for VmcExtMidiCcBit { args, }; } - fn from_osc_message(msg: OscMessage) -> Result { + fn from_osc_message(msg: OscMessage) -> Result { 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})); } let knob: i32; let active: bool; match msg.args[0] { OscType::Int(i) => knob = i, - _ => return Err(String::from("arg type invalid")), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Int(0), actual: msg.args[0], addr: msg.addr, arg_count: 0})), } match msg.args[1] { OscType::Int(i) => { @@ -724,10 +724,10 @@ impl MessageBehavior for VmcExtMidiCcBit { } else if i == 1 { active = true; } else { - return Err(String::from("arg value invalid")); + return Err(FromMessageErr::IntRange(IntRangeErr { expected_lower: 0, expected_upper: 1, actual: i, addr: msg.addr, arg_count: 1})); } } - _ => return Err(String::from("arg type invalid")), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Int(0), actual: msg.args[1], addr: msg.addr, arg_count: 1})), } return Ok(VmcExtMidiCcBit { knob, active }); } -- 2.30.2 From 86a1d0a6056d37a6303728b475231392a63ba070 Mon Sep 17 00:00:00 2001 From: Cassandra de la Cruz-Munoz Date: Sun, 31 Dec 2023 12:05:02 -0500 Subject: [PATCH 10/22] use custom errors in DeviceTransform --- src/lib.rs | 29 ++++++++++------------------- 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index de52dfd..5625027 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -756,53 +756,44 @@ impl MessageBehavior for DeviceTranform { ], }; } - fn from_osc_message(msg: OscMessage) -> Result { + fn from_osc_message(msg: OscMessage) -> Result { if msg.args.len() != 8 { - return Err(String::from("arg count invalid")); - } - match msg.addr.as_str() { - "/VMC/Ext/Hmd/Pos" - | "/VMC/Ext/Con/Pos" - | "/VMC/Ext/Tra/Pos" - | "/VMC/Ext/Hmd/Pos/Local" - | "/VMC/Ext/Con/Pos/Local" - | "/VMC/Ext/Tra/Pos/Local" => {} - _ => return Err(String::from("addr invalid")), + return Err(FromMessageErr::ArgCount(ArgCountErr { expected_in: vec![8], actual: msg.args.len(), addr: msg.addr})); } let serial: String; let mut origin = Vector3::new(0.0, 0.0, 0.0); let mut quat = Quaternion::new(0.0, 0.0, 0.0, 0.0); match &msg.args[0] { OscType::String(s) => serial = 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})), } return Ok(DeviceTranform { addr: msg.addr.to_owned(), -- 2.30.2 From 577c1aa87296c86b84af1882aeedd2951539e963 Mon Sep 17 00:00:00 2001 From: Cassandra de la Cruz-Munoz Date: Sun, 31 Dec 2023 12:07:15 -0500 Subject: [PATCH 11/22] use custom errors in VmcExtRvc --- src/lib.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 5625027..9c98080 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -826,9 +826,9 @@ impl MessageBehavior for VmcExtRvc { args, }; } - fn from_osc_message(msg: OscMessage) -> Result { + fn from_osc_message(msg: OscMessage) -> Result { if msg.args.len() < 2 || msg.args.len() > 3 { - return Err(String::from("arg count invalid")); + return Err(FromMessageErr::ArgCount(ArgCountErr { expected_in: vec![2, 3], actual: msg.args.len(), addr: msg.addr})); } let enable: bool; let port: u16; @@ -840,25 +840,25 @@ impl MessageBehavior for VmcExtRvc { } else if i == 1 { enable = true; } else { - return Err(String::from("arg value invalid")); + return Err(FromMessageErr::IntRange(IntRangeErr { expected_lower: 0, expected_upper: 1, actual: i, addr: msg.addr, arg_count: 0})); } } - _ => return Err(String::from("arg type invalid")), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Int(0), actual: msg.args[0], addr: msg.addr, arg_count: 0})), } match msg.args[1] { OscType::Int(i) => { if i >= 0 && i <= 65535 { port = i as u16; } else { - return Err(String::from("arg value invalid")); + return Err(FromMessageErr::IntRange(IntRangeErr { expected_lower: 0, expected_upper: 65535, actual: i, addr: msg.addr, arg_count: 1})); } } - _ => return Err(String::from("arg type invalid")), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Int(0), actual: msg.args[1], addr: msg.addr, arg_count: 1})), } if msg.args.len() == 3 { match &msg.args[2] { OscType::String(s) => ip_addr = Some(s.to_owned()), - _ => return Err(String::from("arg type invalid")), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::String(String::new()), actual: msg.args[2], addr: msg.addr, arg_count: 2})), } } return Ok(VmcExtRvc { -- 2.30.2 From 3766cd210415e28c2ab5b13e0370f979154abd67 Mon Sep 17 00:00:00 2001 From: Cassandra de la Cruz-Munoz Date: Sun, 31 Dec 2023 12:12:02 -0500 Subject: [PATCH 12/22] use custom errors in VmcExtLight --- src/lib.rs | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 9c98080..903718c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -896,9 +896,9 @@ impl MessageBehavior for VmcExtLight { ], }; } - fn from_osc_message(msg: OscMessage) -> Result { + fn from_osc_message(msg: OscMessage) -> Result { 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, -- 2.30.2 From 6acdcaab6a0a0c783161f0fb7b86a0bcb62afc45 Mon Sep 17 00:00:00 2001 From: Cassandra de la Cruz-Munoz Date: Sun, 31 Dec 2023 12:13:09 -0500 Subject: [PATCH 13/22] use custom errors in VmcExtVrm --- src/lib.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 903718c..310ba9a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -980,25 +980,25 @@ impl MessageBehavior for VmcExtVrm { args, }; } - fn from_osc_message(msg: OscMessage) -> Result { + fn from_osc_message(msg: OscMessage) -> Result { if msg.args.len() < 2 || msg.args.len() > 3 { - return Err(String::from("arg count invalid")); + return Err(FromMessageErr::ArgCount(ArgCountErr { expected_in: vec![2, 3], actual: msg.args.len(), addr: msg.addr})); } let path: String; let title: String; let mut hash: Option = None; match &msg.args[0] { OscType::String(s) => path = 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::String(s) => title = s.to_owned(), - _ => return Err(String::from("arg type invalid")), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::String(String::new()), actual: msg.args[1], addr: msg.addr, arg_count: 1})), } if msg.args.len() == 3 { match &msg.args[2] { OscType::String(s) => hash = Some(s.to_owned()), - _ => return Err(String::from("arg type invalid")), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::String(String::new()), actual: msg.args[2], addr: msg.addr, arg_count: 2})), } } return Ok(VmcExtVrm { path, title, hash }); -- 2.30.2 From a91a39ecbe6b2d00b09b6d857ae991c8e2de3927 Mon Sep 17 00:00:00 2001 From: Cassandra de la Cruz-Munoz Date: Sun, 31 Dec 2023 12:13:48 -0500 Subject: [PATCH 14/22] use custom errors in VmcExtRemote --- src/lib.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 310ba9a..a542588 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1020,19 +1020,19 @@ impl MessageBehavior for VmcExtRemote { ], }; } - fn from_osc_message(msg: OscMessage) -> Result { + fn from_osc_message(msg: OscMessage) -> Result { 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})); } let service: String; let json: String; match &msg.args[0] { OscType::String(s) => service = 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::String(s) => json = s.to_owned(), - _ => return Err(String::from("arg type invalid")), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::String(String::new()), actual: msg.args[1], addr: msg.addr, arg_count: 1})), } return Ok(VmcExtRemote { service, json }); } -- 2.30.2 From 5aebb1cc632e6761dee5522125f04f940718eade Mon Sep 17 00:00:00 2001 From: Cassandra de la Cruz-Munoz Date: Sun, 31 Dec 2023 12:14:38 -0500 Subject: [PATCH 15/22] use custom errors in VmcExtOpt --- src/lib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index a542588..030c872 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1049,9 +1049,9 @@ impl MessageBehavior for VmcExtOpt { args: vec![OscType::from(self.option.to_owned())], }; } - fn from_osc_message(msg: OscMessage) -> Result { + fn from_osc_message(msg: OscMessage) -> Result { if msg.args.len() != 1 { - return Err(String::from("arg count invalid")); + return Err(FromMessageErr::ArgCount(ArgCountErr { expected_in: vec![1], actual: msg.args.len(), addr: msg.addr})); } match &msg.args[0] { OscType::String(s) => { @@ -1059,7 +1059,7 @@ impl MessageBehavior for VmcExtOpt { option: 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})), } } } -- 2.30.2 From 5dc7aefa1c5fb73a2a62c8432bb72d081508e0ba Mon Sep 17 00:00:00 2001 From: Cassandra de la Cruz-Munoz Date: Sun, 31 Dec 2023 12:15:46 -0500 Subject: [PATCH 16/22] use custom errors in VmcExtSettingColor --- src/lib.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 030c872..0f8e332 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1080,26 +1080,26 @@ impl MessageBehavior for VmcExtSettingColor { ], }; } - fn from_osc_message(msg: OscMessage) -> Result { + fn from_osc_message(msg: OscMessage) -> Result { 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 }); } -- 2.30.2 From 15503575e5ddf60fca4c8e1105b89cafb946edbf Mon Sep 17 00:00:00 2001 From: Cassandra de la Cruz-Munoz Date: Sun, 31 Dec 2023 12:17:51 -0500 Subject: [PATCH 17/22] use custom errors and fix bug in VmcExtSettingWin --- src/lib.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 0f8e332..588f70e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1134,9 +1134,9 @@ impl MessageBehavior for VmcExtSettingWin { args, }; } - fn from_osc_message(msg: OscMessage) -> Result { + fn from_osc_message(msg: OscMessage) -> Result { 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 mut result = Self { is_top_most: false, @@ -1149,28 +1149,28 @@ impl MessageBehavior for VmcExtSettingWin { if i == 1 { result.is_top_most = true; } else if i != 0 { - return Err(String::from("arg value invalid")); + return Err(FromMessageErr::IntRange(IntRangeErr { expected_lower: 0, expected_upper: 1, actual: i, addr: msg.addr, arg_count: 0})); } } - _ => return Err(String::from("arg type invalid")), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Int(0), actual: msg.args[0], addr: msg.addr, arg_count: 0})), } match msg.args[1] { OscType::Int(i) => { if i == 1 { result.is_transparent = true; } else if i != 0 { - return Err(String::from("arg value invalid")); + return Err(FromMessageErr::IntRange(IntRangeErr { expected_lower: 0, expected_upper: 1, actual: i, addr: msg.addr, arg_count: 1})); } } - _ => return Err(String::from("arg type invalid")), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Int(0), actual: msg.args[1], addr: msg.addr, arg_count: 1})), } match msg.args[2] { OscType::Int(i) => result.window_click_through = i, - _ => return Err(String::from("arg type invalid")), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Int(0), actual: msg.args[2], addr: msg.addr, arg_count: 2})), } - match msg.args[2] { + match msg.args[3] { OscType::Int(i) => result.hide_border = i, - _ => return Err(String::from("arg type invalid")), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Int(0), actual: msg.args[3], addr: msg.addr, arg_count: 3})), } return Ok(result); } -- 2.30.2 From 3fab3f9a2e4c228aa612efd4ebe05055893e3626 Mon Sep 17 00:00:00 2001 From: Cassandra de la Cruz-Munoz Date: Sun, 31 Dec 2023 12:19:00 -0500 Subject: [PATCH 18/22] use custom errors and fix bug in VmcExtConfig --- src/lib.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 588f70e..c8805a8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1187,13 +1187,13 @@ impl MessageBehavior for VmcExtConfig { args: vec![OscType::from(self.path.to_owned())], }; } - fn from_osc_message(msg: OscMessage) -> Result { - if msg.addr.len() != 1 { - return Err(String::from("arg count invalid")); + fn from_osc_message(msg: OscMessage) -> Result { + if msg.args.len() != 1 { + return Err(FromMessageErr::ArgCount(ArgCountErr { expected_in: vec![1], actual: msg.args.len(), addr: msg.addr })); } match &msg.args[0] { OscType::String(s) => return Ok(VmcExtConfig { path: 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})), } } } -- 2.30.2 From 78a03b862d06f1faefcfa7d86b656f17fce4d390 Mon Sep 17 00:00:00 2001 From: Cassandra de la Cruz-Munoz Date: Sun, 31 Dec 2023 12:22:48 -0500 Subject: [PATCH 19/22] change argtype to have expected vec, use custom errors in VmcThru --- src/lib.rs | 198 ++++++++++++++++++++++++++--------------------------- 1 file changed, 99 insertions(+), 99 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index c8805a8..49ac8cc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -18,7 +18,7 @@ struct ArgCountErr { } struct ArgTypeErr { - expected: OscType, + expected: Vec, actual: OscType, addr: String, arg_count: usize, @@ -89,7 +89,7 @@ impl MessageBehavior for VmcExtOk { result.loaded = i; } _ => { - return Err(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Int(0), actual: msg.args[0],addr: msg.addr.to_owned(), arg_count: 0})); + return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[0],addr: msg.addr.to_owned(), arg_count: 0})); } } } else { @@ -101,7 +101,7 @@ impl MessageBehavior for VmcExtOk { result.calibration_state = Some(i); } _ => { - return Err(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Int(0), actual: msg.args[1], addr: msg.addr.to_owned(), arg_count: 1})); + return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[1], addr: msg.addr.to_owned(), arg_count: 1})); } } match msg.args[2] { @@ -109,7 +109,7 @@ impl MessageBehavior for VmcExtOk { result.calibration_mode = Some(i); } _ => { - return Err(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Int(0), actual: msg.args[2], addr: msg.addr.to_owned(), arg_count: 2})); + return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[2], addr: msg.addr.to_owned(), arg_count: 2})); } } } @@ -119,7 +119,7 @@ impl MessageBehavior for VmcExtOk { result.tracking_status = Some(i); } _ => { - return Err(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Int(0), actual: msg.args[3], addr: msg.addr.to_owned(), arg_count: 3})); + return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[3], addr: msg.addr.to_owned(), arg_count: 3})); } } } @@ -144,7 +144,7 @@ impl MessageBehavior for VmcExtT { } match msg.args[0] { OscType::Float(f) => return Ok(VmcExtT { time: f }), - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Float(0.0), actual: msg.args[0], addr: msg.addr, arg_count: 0})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[0], addr: msg.addr, arg_count: 0})), } } } @@ -189,19 +189,19 @@ impl MessageBehavior for VmcExtRootPos { let name: String; match &msg.args[0] { OscType::String(s) => name = s.to_owned(), - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::String(String::new()), actual: msg.args[0], addr: msg.addr, arg_count: 0})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![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(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Float(0.0), actual: msg.args[1], addr: msg.addr, arg_count: 1})), + _ => 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] { OscType::Float(f) => origin.y = f, - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Float(0.0), actual: msg.args[2], addr: msg.addr, arg_count: 2})), + _ => 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] { OscType::Float(f) => origin.z = f, - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Float(0.0), actual: msg.args[3], addr: msg.addr, arg_count: 3})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[3], addr: msg.addr, arg_count: 3})), } let mut quat = Quaternion { x: 0.0, @@ -211,19 +211,19 @@ impl MessageBehavior for VmcExtRootPos { }; match msg.args[4] { OscType::Float(f) => quat.x = f, - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Float(0.0), actual: msg.args[4], addr: msg.addr, arg_count: 4})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![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(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Float(0.0), actual: msg.args[5], addr: msg.addr, arg_count: 5})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![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(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Float(0.0), actual: msg.args[6], addr: msg.addr, arg_count: 6})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![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(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Float(0.0), actual: msg.args[7], addr: msg.addr, arg_count: 7})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[7], addr: msg.addr, arg_count: 7})), } result = VmcExtRootPos { name, @@ -247,27 +247,27 @@ impl MessageBehavior for VmcExtRootPos { }); match msg.args[8] { OscType::Float(f) => result.mr_scale.unwrap().x = f, - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Float(0.0), actual: msg.args[8], addr: msg.addr, arg_count: 8})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[8], addr: msg.addr, arg_count: 8})), } match msg.args[9] { OscType::Float(f) => result.mr_scale.unwrap().y = f, - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Float(0.0), actual: msg.args[9], addr: msg.addr, arg_count: 9})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[9], addr: msg.addr, arg_count: 9})), } match msg.args[10] { OscType::Float(f) => result.mr_scale.unwrap().z = f, - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Float(0.0), actual: msg.args[10], addr: msg.addr, arg_count: 10})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[10], addr: msg.addr, arg_count: 10})), } match msg.args[11] { OscType::Float(f) => result.mr_offset.unwrap().x = f, - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Float(0.0), actual: msg.args[11], addr: msg.addr, arg_count: 11})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[11], addr: msg.addr, arg_count: 11})), } match msg.args[12] { OscType::Float(f) => result.mr_offset.unwrap().y = f, - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Float(0.0), actual: msg.args[12], addr: msg.addr, arg_count: 12})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[12], addr: msg.addr, arg_count: 12})), } match msg.args[13] { OscType::Float(f) => result.mr_offset.unwrap().z = f, - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Float(0.0), actual: msg.args[13], addr: msg.addr, arg_count: 13})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[13], addr: msg.addr, arg_count: 13})), } } return Ok(result); @@ -304,19 +304,19 @@ impl MessageBehavior for VmcExtBonePos { } match &msg.args[0] { OscType::String(s) => name = s.to_owned(), - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::String(String::new()), actual: msg.args[0], addr: msg.addr, arg_count: 0})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![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(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Float(0.0), actual: msg.args[1], addr: msg.addr, arg_count: 1})), + _ => 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] { OscType::Float(f) => origin.y = f, - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Float(0.0), actual: msg.args[2], addr: msg.addr, arg_count: 2})), + _ => 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] { OscType::Float(f) => origin.z = f, - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Float(0.0), actual: msg.args[3], addr: msg.addr, arg_count: 3})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[3], addr: msg.addr, arg_count: 3})), } let mut quat = Quaternion { x: 0.0, @@ -326,19 +326,19 @@ impl MessageBehavior for VmcExtBonePos { }; match msg.args[4] { OscType::Float(f) => quat.x = f, - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Float(0.0), actual: msg.args[4], addr: msg.addr, arg_count: 4})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![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(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Float(0.0), actual: msg.args[5], addr: msg.addr, arg_count: 5})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![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(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Float(0.0), actual: msg.args[6], addr: msg.addr, arg_count: 6})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![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(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Float(0.0), actual: msg.args[7], addr: msg.addr, arg_count: 7})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[7], addr: msg.addr, arg_count: 7})), } return Ok(VmcExtBonePos { name, @@ -370,11 +370,11 @@ impl MessageBehavior for VmcExtBlendVal { } match &msg.args[0] { OscType::String(s) => name = s.to_owned(), - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::String(String::new()), actual: msg.args[0], addr: msg.addr, arg_count: 0})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![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(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Float(0.0), actual: msg.args[1], addr: msg.addr, arg_count: 1})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[1], addr: msg.addr, arg_count: 1})), } return Ok(VmcExtBlendVal { name, value }); } @@ -414,39 +414,39 @@ impl MessageBehavior for VmcExtCam { let fov: f32; match &msg.args[0] { OscType::String(s) => name = s.to_owned(), - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::String(String::new()), actual: msg.args[0], addr: msg.addr, arg_count: 0})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![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(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Float(0.0), actual: msg.args[1], addr: msg.addr, arg_count: 1})), + _ => 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] { OscType::Float(f) => origin.y = f, - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Float(0.0), actual: msg.args[2], addr: msg.addr, arg_count: 2})), + _ => 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] { OscType::Float(f) => origin.z = f, - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Float(0.0), actual: msg.args[3], addr: msg.addr, arg_count: 3})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![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(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Float(0.0), actual: msg.args[4], addr: msg.addr, arg_count: 4})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![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(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Float(0.0), actual: msg.args[5], addr: msg.addr, arg_count: 5})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![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(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Float(0.0), actual: msg.args[6], addr: msg.addr, arg_count: 6})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![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(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Float(0.0), actual: msg.args[7], addr: msg.addr, arg_count: 7})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[7], addr: msg.addr, arg_count: 7})), } match msg.args[8] { OscType::Float(f) => fov = f, - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Float(0.0), actual: msg.args[8], addr: msg.addr, arg_count: 8})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[8], addr: msg.addr, arg_count: 8})), } return Ok(VmcExtCam { name, @@ -490,40 +490,40 @@ impl MessageBehavior for VmcExtCon { let mut axis = Vector3::new(0.0, 0.0, 0.0); match msg.args[0] { OscType::Int(i) => active = i, - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Int(0), actual: msg.args[0], addr: msg.addr, arg_count: 0})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[0], addr: msg.addr, arg_count: 0})), } if active > 2 || active < 0 { return Err(FromMessageErr::IntRange(IntRangeErr { expected_lower: 0, expected_upper: 2, actual: active, addr: msg.addr, arg_count: 0})); } match &msg.args[1] { OscType::String(s) => name = s.to_owned(), - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::String(String::new()), actual: msg.args[1], addr: msg.addr, arg_count: 1})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::String(String::new())], actual: msg.args[1], addr: msg.addr, arg_count: 1})), } match msg.args[2] { OscType::Int(i) => is_left = i, - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Int(0), actual: msg.args[2], addr: msg.addr, arg_count: 2})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[2], addr: msg.addr, arg_count: 2})), } if is_left < 0 || is_left > 1 { return Err(FromMessageErr::IntRange(IntRangeErr { expected_lower: 0, expected_upper: 1, actual: active, addr: msg.addr, arg_count: 2})); } match msg.args[3] { OscType::Int(i) => is_touch = i, - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Int(0), actual: msg.args[3], addr: msg.addr, arg_count: 3})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[3], addr: msg.addr, arg_count: 3})), } if is_touch < 0 || is_touch > 1 { return Err(FromMessageErr::IntRange(IntRangeErr { expected_lower: 0, expected_upper: 1, actual: active, addr: msg.addr, arg_count: 3})); } match msg.args[4] { OscType::Float(f) => axis.x = f, - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Float(0.0), actual: msg.args[4], addr: msg.addr, arg_count: 4})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[4], addr: msg.addr, arg_count: 4})), } match msg.args[5] { OscType::Float(f) => axis.y = f, - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Float(0.0), actual: msg.args[5], addr: msg.addr, arg_count: 5})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[5], addr: msg.addr, arg_count: 5})), } match msg.args[6] { OscType::Float(f) => axis.z = f, - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Float(0.0), actual: msg.args[6], addr: msg.addr, arg_count: 6})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[6], addr: msg.addr, arg_count: 6})), } return Ok(VmcExtCon { active, @@ -575,15 +575,15 @@ impl MessageBehavior for VmcExtKey { return Err(FromMessageErr::IntRange(IntRangeErr { expected_lower: 0, expected_upper: 1, actual: i, addr: msg.addr, arg_count: 0})); } } - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Int(0), actual: msg.args[0], addr: msg.addr, arg_count: 0})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[0], addr: msg.addr, arg_count: 0})), } match &msg.args[1] { OscType::String(s) => name = s.to_owned(), - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::String(String::new()), actual: msg.args[1], addr: msg.addr, arg_count: 1})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::String(String::new())], actual: msg.args[1], addr: msg.addr, arg_count: 1})), } match msg.args[2] { OscType::Int(i) => keycode = i, - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Int(0), actual: msg.args[2], addr: msg.addr, arg_count: 2})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[2], addr: msg.addr, arg_count: 2})), } return Ok(VmcExtKey { active, @@ -636,19 +636,19 @@ impl MessageBehavior for VmcExtMidiNote { return Err(FromMessageErr::IntRange(IntRangeErr { expected_lower: 0, expected_upper: 1, actual: i, addr: msg.addr, arg_count: 0})); } } - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Int(0), actual: msg.args[0], addr: msg.addr, arg_count: 0})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[0], addr: msg.addr, arg_count: 0})), } match msg.args[1] { OscType::Int(i) => channel = i, - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Int(0), actual: msg.args[1], addr: msg.addr, arg_count: 1})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[1], addr: msg.addr, arg_count: 1})), } match msg.args[2] { OscType::Int(i) => note = i, - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Int(0), actual: msg.args[2], addr: msg.addr, arg_count: 2})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[2], addr: msg.addr, arg_count: 2})), } match msg.args[3] { OscType::Float(f) => velocity = f, - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Float(0.0), actual: msg.args[3], addr: msg.addr, arg_count: 3})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[3], addr: msg.addr, arg_count: 3})), } return Ok(VmcExtMidiNote { active, @@ -679,11 +679,11 @@ impl MessageBehavior for VmcExtMidiCcVal { let value: f32; match msg.args[0] { OscType::Int(i) => knob = i, - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Int(0), actual: msg.args[0], addr: msg.addr, arg_count: 0})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[0], addr: msg.addr, arg_count: 0})), } match msg.args[1] { OscType::Float(f) => value = f, - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Float(0.0), actual: msg.args[1], addr: msg.addr, arg_count: 1})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[1], addr: msg.addr, arg_count: 1})), } return Ok(VmcExtMidiCcVal { knob, value }); } @@ -715,7 +715,7 @@ impl MessageBehavior for VmcExtMidiCcBit { let active: bool; match msg.args[0] { OscType::Int(i) => knob = i, - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Int(0), actual: msg.args[0], addr: msg.addr, arg_count: 0})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[0], addr: msg.addr, arg_count: 0})), } match msg.args[1] { OscType::Int(i) => { @@ -727,7 +727,7 @@ impl MessageBehavior for VmcExtMidiCcBit { return Err(FromMessageErr::IntRange(IntRangeErr { expected_lower: 0, expected_upper: 1, actual: i, addr: msg.addr, arg_count: 1})); } } - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Int(0), actual: msg.args[1], addr: msg.addr, arg_count: 1})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[1], addr: msg.addr, arg_count: 1})), } return Ok(VmcExtMidiCcBit { knob, active }); } @@ -765,35 +765,35 @@ impl MessageBehavior for DeviceTranform { let mut quat = Quaternion::new(0.0, 0.0, 0.0, 0.0); match &msg.args[0] { OscType::String(s) => serial = s.to_owned(), - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::String(String::new()), actual: msg.args[0], addr: msg.addr, arg_count: 0})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![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(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Float(0.0), actual: msg.args[1], addr: msg.addr, arg_count: 1})), + _ => 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] { OscType::Float(f) => origin.y = f, - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Float(0.0), actual: msg.args[2], addr: msg.addr, arg_count: 2})), + _ => 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] { OscType::Float(f) => origin.z = f, - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Float(0.0), actual: msg.args[3], addr: msg.addr, arg_count: 3})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![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(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Float(0.0), actual: msg.args[4], addr: msg.addr, arg_count: 4})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![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(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Float(0.0), actual: msg.args[5], addr: msg.addr, arg_count: 5})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![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(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Float(0.0), actual: msg.args[6], addr: msg.addr, arg_count: 6})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![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(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Float(0.0), actual: msg.args[7], addr: msg.addr, arg_count: 7})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[7], addr: msg.addr, arg_count: 7})), } return Ok(DeviceTranform { addr: msg.addr.to_owned(), @@ -843,7 +843,7 @@ impl MessageBehavior for VmcExtRvc { return Err(FromMessageErr::IntRange(IntRangeErr { expected_lower: 0, expected_upper: 1, actual: i, addr: msg.addr, arg_count: 0})); } } - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Int(0), actual: msg.args[0], addr: msg.addr, arg_count: 0})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[0], addr: msg.addr, arg_count: 0})), } match msg.args[1] { OscType::Int(i) => { @@ -853,12 +853,12 @@ impl MessageBehavior for VmcExtRvc { return Err(FromMessageErr::IntRange(IntRangeErr { expected_lower: 0, expected_upper: 65535, actual: i, addr: msg.addr, arg_count: 1})); } } - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Int(0), actual: msg.args[1], addr: msg.addr, arg_count: 1})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[1], addr: msg.addr, arg_count: 1})), } if msg.args.len() == 3 { match &msg.args[2] { OscType::String(s) => ip_addr = Some(s.to_owned()), - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::String(String::new()), actual: msg.args[2], addr: msg.addr, arg_count: 2})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::String(String::new())], actual: msg.args[2], addr: msg.addr, arg_count: 2})), } } return Ok(VmcExtRvc { @@ -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(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::String(String::new()), actual: msg.args[0], addr: msg.addr, arg_count: 0})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![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(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Float(0.0), actual: msg.args[1], addr: msg.addr, arg_count: 1})), + _ => 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] { OscType::Float(f) => origin.y = f, - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Float(0.0), actual: msg.args[2], addr: msg.addr, arg_count: 2})), + _ => 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] { OscType::Float(f) => origin.z = f, - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Float(0.0), actual: msg.args[3], addr: msg.addr, arg_count: 3})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![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(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Float(0.0), actual: msg.args[4], addr: msg.addr, arg_count: 4})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![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(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Float(0.0), actual: msg.args[5], addr: msg.addr, arg_count: 5})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![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(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Float(0.0), actual: msg.args[6], addr: msg.addr, arg_count: 6})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![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(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Float(0.0), actual: msg.args[7], addr: msg.addr, arg_count: 7})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![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(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Float(0.0), actual: msg.args[8], addr: msg.addr, arg_count: 8})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![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(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Float(0.0), actual: msg.args[9], addr: msg.addr, arg_count: 9})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![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(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Float(0.0), actual: msg.args[10], addr: msg.addr, arg_count: 10})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![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(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Float(0.0), actual: msg.args[11], addr: msg.addr, arg_count: 11})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[11], addr: msg.addr, arg_count: 11})), } return Ok(VmcExtLight { name, @@ -989,16 +989,16 @@ impl MessageBehavior for VmcExtVrm { let mut hash: Option = None; match &msg.args[0] { OscType::String(s) => path = s.to_owned(), - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::String(String::new()), actual: msg.args[0], addr: msg.addr, arg_count: 0})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::String(String::new())], actual: msg.args[0], addr: msg.addr, arg_count: 0})), } match &msg.args[1] { OscType::String(s) => title = s.to_owned(), - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::String(String::new()), actual: msg.args[1], addr: msg.addr, arg_count: 1})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::String(String::new())], actual: msg.args[1], addr: msg.addr, arg_count: 1})), } if msg.args.len() == 3 { match &msg.args[2] { OscType::String(s) => hash = Some(s.to_owned()), - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::String(String::new()), actual: msg.args[2], addr: msg.addr, arg_count: 2})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::String(String::new())], actual: msg.args[2], addr: msg.addr, arg_count: 2})), } } return Ok(VmcExtVrm { path, title, hash }); @@ -1028,11 +1028,11 @@ impl MessageBehavior for VmcExtRemote { let json: String; match &msg.args[0] { OscType::String(s) => service = s.to_owned(), - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::String(String::new()), actual: msg.args[0], addr: msg.addr, arg_count: 0})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::String(String::new())], actual: msg.args[0], addr: msg.addr, arg_count: 0})), } match &msg.args[1] { OscType::String(s) => json = s.to_owned(), - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::String(String::new()), actual: msg.args[1], addr: msg.addr, arg_count: 1})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::String(String::new())], actual: msg.args[1], addr: msg.addr, arg_count: 1})), } return Ok(VmcExtRemote { service, json }); } @@ -1059,7 +1059,7 @@ impl MessageBehavior for VmcExtOpt { option: s.to_owned(), }) } - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::String(String::new()), actual: msg.args[0], addr: msg.addr, arg_count: 0})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::String(String::new())], actual: msg.args[0], addr: msg.addr, arg_count: 0})), } } } @@ -1087,19 +1087,19 @@ impl MessageBehavior for VmcExtSettingColor { 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(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Float(0.0), actual: msg.args[0], addr: msg.addr, arg_count: 0})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![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(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Float(0.0), actual: msg.args[1], addr: msg.addr, arg_count: 1})), + _ => 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] { OscType::Float(f) => color.b = f, - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Float(0.0), actual: msg.args[2], addr: msg.addr, arg_count: 2})), + _ => 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] { OscType::Float(f) => color.a = f, - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Float(0.0), actual: msg.args[3], addr: msg.addr, arg_count: 3})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[3], addr: msg.addr, arg_count: 3})), } return Ok(VmcExtSettingColor { color }); } @@ -1152,7 +1152,7 @@ impl MessageBehavior for VmcExtSettingWin { return Err(FromMessageErr::IntRange(IntRangeErr { expected_lower: 0, expected_upper: 1, actual: i, addr: msg.addr, arg_count: 0})); } } - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Int(0), actual: msg.args[0], addr: msg.addr, arg_count: 0})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[0], addr: msg.addr, arg_count: 0})), } match msg.args[1] { OscType::Int(i) => { @@ -1162,15 +1162,15 @@ impl MessageBehavior for VmcExtSettingWin { return Err(FromMessageErr::IntRange(IntRangeErr { expected_lower: 0, expected_upper: 1, actual: i, addr: msg.addr, arg_count: 1})); } } - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Int(0), actual: msg.args[1], addr: msg.addr, arg_count: 1})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[1], addr: msg.addr, arg_count: 1})), } match msg.args[2] { OscType::Int(i) => result.window_click_through = i, - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Int(0), actual: msg.args[2], addr: msg.addr, arg_count: 2})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[2], addr: msg.addr, arg_count: 2})), } match msg.args[3] { OscType::Int(i) => result.hide_border = i, - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::Int(0), actual: msg.args[3], addr: msg.addr, arg_count: 3})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[3], addr: msg.addr, arg_count: 3})), } return Ok(result); } @@ -1193,7 +1193,7 @@ impl MessageBehavior for VmcExtConfig { } match &msg.args[0] { OscType::String(s) => return Ok(VmcExtConfig { path: s.to_owned() }), - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: OscType::String(String::new()), actual: msg.args[0], addr: msg.addr, arg_count: 0})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::String(String::new())], actual: msg.args[0], addr: msg.addr, arg_count: 0})), } } } @@ -1222,21 +1222,21 @@ impl MessageBehavior for VmcThru { } return OscMessage { addr: self.addr.to_owned(), args} } - fn from_osc_message(msg: OscMessage) -> Result { + fn from_osc_message(msg: OscMessage) -> Result { if msg.args.len() > 2 || msg.args.len() < 1 { - return Err(String::from("arg count invalid")); + return Err(FromMessageErr::ArgCount(ArgCountErr { expected_in: vec![1, 2], actual: msg.args.len(), addr: msg.addr})); } let arg1: String; match &msg.args[0] { OscType::String(s) => arg1 = s.to_owned(), - _ => return Err(String::from("arg type invalid")) + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::String(String::new())], actual: msg.args[0], addr: msg.addr, arg_count: 0})), } let mut arg2: Option = None; if msg.args.len() == 2 { match msg.args[1] { OscType::Int(i) => arg2 = Some(ThruType::Int(i)), OscType::Float(f) => arg2 = Some(ThruType::Float(f)), - _ => return Err(String::from("arg type invalid")) + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0), OscType::Float(0.0)], actual: msg.args[1], addr: msg.addr, arg_count: 1})) } } return Ok(VmcThru { addr: msg.addr, arg1 , arg2 }) -- 2.30.2 From 9aa00b5b366320eed6e9f0d16a63fa3fafcc866d Mon Sep 17 00:00:00 2001 From: Cassandra de la Cruz-Munoz Date: Sun, 31 Dec 2023 12:24:28 -0500 Subject: [PATCH 20/22] use custom errors in VmcExtSetPeriod --- src/lib.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 49ac8cc..c04b798 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1263,9 +1263,9 @@ impl MessageBehavior for VmcExtSetPeriod { OscType::from(self.devices), ] }; } - fn from_osc_message(msg: OscMessage) -> Result { + fn from_osc_message(msg: OscMessage) -> Result { if msg.args.len() != 6 { - return Err(String::from("arg count invalid")); + return Err(FromMessageErr::ArgCount(ArgCountErr { expected_in: vec![6], actual: msg.args.len(), addr: msg.addr})); } let status: i32; let root: i32; @@ -1275,27 +1275,27 @@ impl MessageBehavior for VmcExtSetPeriod { let devices: i32; match msg.args[0] { OscType::Int(i) => status = 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] { OscType::Int(i) => root = i, - _ => return Err(String::from("arg type invalid")) + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[1], addr: msg.addr, arg_count: 1})) } match msg.args[2] { OscType::Int(i) => bone = i, - _ => return Err(String::from("arg type invalid")) + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[2], addr: msg.addr, arg_count: 2})) } match msg.args[3] { OscType::Int(i) => blendshape = i, - _ => return Err(String::from("arg type invalid")) + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[3], addr: msg.addr, arg_count: 3})) } match msg.args[4] { OscType::Int(i) => camera = i, - _ => return Err(String::from("arg type invalid")) + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[4], addr: msg.addr, arg_count: 4})) } match msg.args[5] { OscType::Int(i) => devices = i, - _ => return Err(String::from("arg type invalid")) + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[5], addr: msg.addr, arg_count: 5})) } return Ok(VmcExtSetPeriod { status, root, bone, blendshape, camera, devices}) } -- 2.30.2 From 3f01f2f3fdde35c3135a4b249c9e1e9f81e0928c Mon Sep 17 00:00:00 2001 From: Cassandra de la Cruz-Munoz Date: Sun, 31 Dec 2023 13:18:47 -0500 Subject: [PATCH 21/22] use custom errors in VmcExtSetEye --- src/lib.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index c04b798..1306a0f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1316,9 +1316,9 @@ impl MessageBehavior for VmcExtSetEye { ] }; } - fn from_osc_message(msg: OscMessage) -> Result { + fn from_osc_message(msg: OscMessage) -> Result { 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 x: f32; @@ -1326,20 +1326,20 @@ impl MessageBehavior for VmcExtSetEye { let z: f32; match msg.args[0] { 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] { 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] { 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] { 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)}) } -- 2.30.2 From dff7e0916122cf2d638a7af895f2496826b3cabb Mon Sep 17 00:00:00 2001 From: Cassandra de la Cruz-Munoz Date: Sun, 31 Dec 2023 13:35:38 -0500 Subject: [PATCH 22/22] add error messages to custom errors --- src/lib.rs | 287 +++++++++++++++++++++++++++++++---------------------- 1 file changed, 171 insertions(+), 116 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 1306a0f..7e68958 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3,6 +3,7 @@ use godot::{ prelude::{Color, Transform3D, Vector3}, }; use rosc::{OscMessage, OscType}; +use std::fmt; pub trait MessageBehavior { fn to_osc_message(&self) -> OscMessage; @@ -11,20 +12,32 @@ pub trait MessageBehavior { Self: Sized; } -struct ArgCountErr { +pub struct ArgCountErr { expected_in: Vec, actual: usize, addr: String, } -struct ArgTypeErr { +impl fmt::Display for ArgCountErr { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "Invalid number of arguments for message with address {}. Expected {:?}, received {}.", self.addr, self.expected_in, self.actual) + } +} + +pub struct ArgTypeErr { expected: Vec, actual: OscType, addr: String, arg_count: usize, } -struct IntRangeErr { +impl fmt::Display for ArgTypeErr { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "Invalid type of argument {} for message with address {}. Expected {:?}, received {:?}.", self.arg_count, self.addr, self.expected, self.actual) + } +} + +pub struct IntRangeErr { expected_lower: i32, expected_upper: i32, actual: i32, @@ -32,21 +45,39 @@ struct IntRangeErr { arg_count: usize, } -struct IntValErr { +impl fmt::Display for IntRangeErr { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "Invalid value of integer argument {} for message with address {}. Expected in range [{}, {}], received {}.", self.arg_count, self.addr, self.expected_lower, self.expected_upper, self.actual) + } +} + +pub struct IntValErr { expected_in: Vec, actual: i32, addr: String, arg_count: usize, } -struct StrValErr { +impl fmt::Display for IntValErr { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "Invalid value of integer argument {} for message with address {}. Expected {:?}, received {:?}.", self.arg_count, self.addr, self.expected_in, self.actual) + } +} + +pub struct StrValErr { expected_in: Vec, actual: String, addr: String, arg_count: usize, } -enum FromMessageErr { +impl fmt::Display for StrValErr { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "Invalid value of string argument {} for message with address {}. Expected {:?}, received {:?}.", self.arg_count, self.addr, self.expected_in, self.actual) + } +} + +pub enum FromMessageErr { ArgCount(ArgCountErr), ArgType(ArgTypeErr), IntRange(IntRangeErr), @@ -54,6 +85,7 @@ enum FromMessageErr { StrVal(StrValErr), } +#[derive(Debug)] struct VmcExtOk { loaded: i32, calibration_state: Option, @@ -89,7 +121,7 @@ impl MessageBehavior for VmcExtOk { result.loaded = i; } _ => { - return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[0],addr: msg.addr.to_owned(), arg_count: 0})); + return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[0].to_owned(),addr: msg.addr.to_owned(), arg_count: 0})); } } } else { @@ -101,7 +133,7 @@ impl MessageBehavior for VmcExtOk { result.calibration_state = Some(i); } _ => { - return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[1], addr: msg.addr.to_owned(), arg_count: 1})); + return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[1].to_owned(), addr: msg.addr.to_owned(), arg_count: 1})); } } match msg.args[2] { @@ -109,7 +141,7 @@ impl MessageBehavior for VmcExtOk { result.calibration_mode = Some(i); } _ => { - return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[2], addr: msg.addr.to_owned(), arg_count: 2})); + return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[2].to_owned(), addr: msg.addr.to_owned(), arg_count: 2})); } } } @@ -119,7 +151,7 @@ impl MessageBehavior for VmcExtOk { result.tracking_status = Some(i); } _ => { - return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[3], addr: msg.addr.to_owned(), arg_count: 3})); + return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[3].to_owned(), addr: msg.addr.to_owned(), arg_count: 3})); } } } @@ -127,6 +159,7 @@ impl MessageBehavior for VmcExtOk { } } +#[derive(Debug)] struct VmcExtT { time: f32, } @@ -144,11 +177,12 @@ impl MessageBehavior for VmcExtT { } match msg.args[0] { OscType::Float(f) => return Ok(VmcExtT { time: f }), - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[0], addr: msg.addr, arg_count: 0})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[0].to_owned(), addr: msg.addr, arg_count: 0})), } } } +#[derive(Debug)] struct VmcExtRootPos { name: String, transform: Transform3D, @@ -189,19 +223,19 @@ impl MessageBehavior for VmcExtRootPos { let name: String; match &msg.args[0] { OscType::String(s) => name = s.to_owned(), - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::String(String::new())], actual: msg.args[0], addr: msg.addr, arg_count: 0})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::String(String::new())], actual: msg.args[0].to_owned(), addr: msg.addr, arg_count: 0})), } match msg.args[1] { OscType::Float(f) => origin.x = f, - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[1], addr: msg.addr, arg_count: 1})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[1].to_owned(), addr: msg.addr, arg_count: 1})), } match msg.args[2] { OscType::Float(f) => origin.y = f, - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[2], addr: msg.addr, arg_count: 2})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[2].to_owned(), addr: msg.addr, arg_count: 2})), } match msg.args[3] { OscType::Float(f) => origin.z = f, - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[3], addr: msg.addr, arg_count: 3})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[3].to_owned(), addr: msg.addr, arg_count: 3})), } let mut quat = Quaternion { x: 0.0, @@ -211,19 +245,19 @@ impl MessageBehavior for VmcExtRootPos { }; match msg.args[4] { OscType::Float(f) => quat.x = f, - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[4], addr: msg.addr, arg_count: 4})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[4].to_owned(), addr: msg.addr, arg_count: 4})), } match msg.args[5] { OscType::Float(f) => quat.y = f, - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[5], addr: msg.addr, arg_count: 5})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[5].to_owned(), addr: msg.addr, arg_count: 5})), } match msg.args[6] { OscType::Float(f) => quat.z = f, - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[6], addr: msg.addr, arg_count: 6})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[6].to_owned(), addr: msg.addr, arg_count: 6})), } match msg.args[7] { OscType::Float(f) => quat.w = f, - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[7], addr: msg.addr, arg_count: 7})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[7].to_owned(), addr: msg.addr, arg_count: 7})), } result = VmcExtRootPos { name, @@ -247,33 +281,34 @@ impl MessageBehavior for VmcExtRootPos { }); match msg.args[8] { OscType::Float(f) => result.mr_scale.unwrap().x = f, - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[8], addr: msg.addr, arg_count: 8})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[8].to_owned(), addr: msg.addr, arg_count: 8})), } match msg.args[9] { OscType::Float(f) => result.mr_scale.unwrap().y = f, - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[9], addr: msg.addr, arg_count: 9})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[9].to_owned(), addr: msg.addr, arg_count: 9})), } match msg.args[10] { OscType::Float(f) => result.mr_scale.unwrap().z = f, - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[10], addr: msg.addr, arg_count: 10})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[10].to_owned(), addr: msg.addr, arg_count: 10})), } match msg.args[11] { OscType::Float(f) => result.mr_offset.unwrap().x = f, - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[11], addr: msg.addr, arg_count: 11})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[11].to_owned(), addr: msg.addr, arg_count: 11})), } match msg.args[12] { OscType::Float(f) => result.mr_offset.unwrap().y = f, - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[12], addr: msg.addr, arg_count: 12})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[12].to_owned(), addr: msg.addr, arg_count: 12})), } match msg.args[13] { OscType::Float(f) => result.mr_offset.unwrap().z = f, - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[13], addr: msg.addr, arg_count: 13})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[13].to_owned(), addr: msg.addr, arg_count: 13})), } } return Ok(result); } } +#[derive(Debug)] struct VmcExtBonePos { name: String, transform: Transform3D, @@ -304,19 +339,19 @@ impl MessageBehavior for VmcExtBonePos { } match &msg.args[0] { OscType::String(s) => name = s.to_owned(), - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::String(String::new())], actual: msg.args[0], addr: msg.addr, arg_count: 0})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::String(String::new())], actual: msg.args[0].to_owned(), addr: msg.addr, arg_count: 0})), } match msg.args[1] { OscType::Float(f) => origin.x = f, - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[1], addr: msg.addr, arg_count: 1})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[1].to_owned(), addr: msg.addr, arg_count: 1})), } match msg.args[2] { OscType::Float(f) => origin.y = f, - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[2], addr: msg.addr, arg_count: 2})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[2].to_owned(), addr: msg.addr, arg_count: 2})), } match msg.args[3] { OscType::Float(f) => origin.z = f, - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[3], addr: msg.addr, arg_count: 3})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[3].to_owned(), addr: msg.addr, arg_count: 3})), } let mut quat = Quaternion { x: 0.0, @@ -326,19 +361,19 @@ impl MessageBehavior for VmcExtBonePos { }; match msg.args[4] { OscType::Float(f) => quat.x = f, - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[4], addr: msg.addr, arg_count: 4})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[4].to_owned(), addr: msg.addr, arg_count: 4})), } match msg.args[5] { OscType::Float(f) => quat.y = f, - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[5], addr: msg.addr, arg_count: 5})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[5].to_owned(), addr: msg.addr, arg_count: 5})), } match msg.args[6] { OscType::Float(f) => quat.z = f, - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[6], addr: msg.addr, arg_count: 6})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[6].to_owned(), addr: msg.addr, arg_count: 6})), } match msg.args[7] { OscType::Float(f) => quat.w = f, - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[7], addr: msg.addr, arg_count: 7})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[7].to_owned(), addr: msg.addr, arg_count: 7})), } return Ok(VmcExtBonePos { name, @@ -347,6 +382,7 @@ impl MessageBehavior for VmcExtBonePos { } } +#[derive(Debug)] struct VmcExtBlendVal { name: String, value: f32, @@ -370,16 +406,17 @@ impl MessageBehavior for VmcExtBlendVal { } match &msg.args[0] { OscType::String(s) => name = s.to_owned(), - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::String(String::new())], actual: msg.args[0], addr: msg.addr, arg_count: 0})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::String(String::new())], actual: msg.args[0].to_owned(), addr: msg.addr, arg_count: 0})), } match msg.args[1] { OscType::Float(f) => value = f, - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[1], addr: msg.addr, arg_count: 1})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[1].to_owned(), addr: msg.addr, arg_count: 1})), } return Ok(VmcExtBlendVal { name, value }); } } +#[derive(Debug)] struct VmcExtCam { name: String, transform: Transform3D, @@ -414,39 +451,39 @@ impl MessageBehavior for VmcExtCam { let fov: f32; match &msg.args[0] { OscType::String(s) => name = s.to_owned(), - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::String(String::new())], actual: msg.args[0], addr: msg.addr, arg_count: 0})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::String(String::new())], actual: msg.args[0].to_owned(), addr: msg.addr, arg_count: 0})), } match msg.args[1] { OscType::Float(f) => origin.x = f, - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[1], addr: msg.addr, arg_count: 1})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[1].to_owned(), addr: msg.addr, arg_count: 1})), } match msg.args[2] { OscType::Float(f) => origin.y = f, - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[2], addr: msg.addr, arg_count: 2})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[2].to_owned(), addr: msg.addr, arg_count: 2})), } match msg.args[3] { OscType::Float(f) => origin.z = f, - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[3], addr: msg.addr, arg_count: 3})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[3].to_owned(), addr: msg.addr, arg_count: 3})), } match msg.args[4] { OscType::Float(f) => quat.x = f, - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[4], addr: msg.addr, arg_count: 4})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[4].to_owned(), addr: msg.addr, arg_count: 4})), } match msg.args[5] { OscType::Float(f) => quat.y = f, - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[5], addr: msg.addr, arg_count: 5})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[5].to_owned(), addr: msg.addr, arg_count: 5})), } match msg.args[6] { OscType::Float(f) => quat.z = f, - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[6], addr: msg.addr, arg_count: 6})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[6].to_owned(), addr: msg.addr, arg_count: 6})), } match msg.args[7] { OscType::Float(f) => quat.w = f, - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[7], addr: msg.addr, arg_count: 7})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[7].to_owned(), addr: msg.addr, arg_count: 7})), } match msg.args[8] { OscType::Float(f) => fov = f, - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[8], addr: msg.addr, arg_count: 8})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[8].to_owned(), addr: msg.addr, arg_count: 8})), } return Ok(VmcExtCam { name, @@ -456,6 +493,7 @@ impl MessageBehavior for VmcExtCam { } } +#[derive(Debug)] struct VmcExtCon { active: i32, name: String, @@ -490,40 +528,40 @@ impl MessageBehavior for VmcExtCon { let mut axis = Vector3::new(0.0, 0.0, 0.0); match msg.args[0] { OscType::Int(i) => active = i, - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[0], addr: msg.addr, arg_count: 0})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[0].to_owned(), addr: msg.addr, arg_count: 0})), } if active > 2 || active < 0 { return Err(FromMessageErr::IntRange(IntRangeErr { expected_lower: 0, expected_upper: 2, actual: active, addr: msg.addr, arg_count: 0})); } match &msg.args[1] { OscType::String(s) => name = s.to_owned(), - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::String(String::new())], actual: msg.args[1], addr: msg.addr, arg_count: 1})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::String(String::new())], actual: msg.args[1].to_owned(), addr: msg.addr, arg_count: 1})), } match msg.args[2] { OscType::Int(i) => is_left = i, - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[2], addr: msg.addr, arg_count: 2})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[2].to_owned(), addr: msg.addr, arg_count: 2})), } if is_left < 0 || is_left > 1 { return Err(FromMessageErr::IntRange(IntRangeErr { expected_lower: 0, expected_upper: 1, actual: active, addr: msg.addr, arg_count: 2})); } match msg.args[3] { OscType::Int(i) => is_touch = i, - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[3], addr: msg.addr, arg_count: 3})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[3].to_owned(), addr: msg.addr, arg_count: 3})), } if is_touch < 0 || is_touch > 1 { return Err(FromMessageErr::IntRange(IntRangeErr { expected_lower: 0, expected_upper: 1, actual: active, addr: msg.addr, arg_count: 3})); } match msg.args[4] { OscType::Float(f) => axis.x = f, - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[4], addr: msg.addr, arg_count: 4})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[4].to_owned(), addr: msg.addr, arg_count: 4})), } match msg.args[5] { OscType::Float(f) => axis.y = f, - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[5], addr: msg.addr, arg_count: 5})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[5].to_owned(), addr: msg.addr, arg_count: 5})), } match msg.args[6] { OscType::Float(f) => axis.z = f, - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[6], addr: msg.addr, arg_count: 6})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[6].to_owned(), addr: msg.addr, arg_count: 6})), } return Ok(VmcExtCon { active, @@ -535,6 +573,7 @@ impl MessageBehavior for VmcExtCon { } } +#[derive(Debug)] struct VmcExtKey { active: bool, name: String, @@ -575,15 +614,15 @@ impl MessageBehavior for VmcExtKey { return Err(FromMessageErr::IntRange(IntRangeErr { expected_lower: 0, expected_upper: 1, actual: i, addr: msg.addr, arg_count: 0})); } } - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[0], addr: msg.addr, arg_count: 0})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[0].to_owned(), addr: msg.addr, arg_count: 0})), } match &msg.args[1] { OscType::String(s) => name = s.to_owned(), - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::String(String::new())], actual: msg.args[1], addr: msg.addr, arg_count: 1})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::String(String::new())], actual: msg.args[1].to_owned(), addr: msg.addr, arg_count: 1})), } match msg.args[2] { OscType::Int(i) => keycode = i, - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[2], addr: msg.addr, arg_count: 2})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[2].to_owned(), addr: msg.addr, arg_count: 2})), } return Ok(VmcExtKey { active, @@ -593,6 +632,7 @@ impl MessageBehavior for VmcExtKey { } } +#[derive(Debug)] struct VmcExtMidiNote { active: bool, channel: i32, @@ -636,19 +676,19 @@ impl MessageBehavior for VmcExtMidiNote { return Err(FromMessageErr::IntRange(IntRangeErr { expected_lower: 0, expected_upper: 1, actual: i, addr: msg.addr, arg_count: 0})); } } - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[0], addr: msg.addr, arg_count: 0})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[0].to_owned(), addr: msg.addr, arg_count: 0})), } match msg.args[1] { OscType::Int(i) => channel = i, - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[1], addr: msg.addr, arg_count: 1})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[1].to_owned(), addr: msg.addr, arg_count: 1})), } match msg.args[2] { OscType::Int(i) => note = i, - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[2], addr: msg.addr, arg_count: 2})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[2].to_owned(), addr: msg.addr, arg_count: 2})), } match msg.args[3] { OscType::Float(f) => velocity = f, - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[3], addr: msg.addr, arg_count: 3})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[3].to_owned(), addr: msg.addr, arg_count: 3})), } return Ok(VmcExtMidiNote { active, @@ -659,6 +699,7 @@ impl MessageBehavior for VmcExtMidiNote { } } +#[derive(Debug)] struct VmcExtMidiCcVal { knob: i32, value: f32, @@ -679,16 +720,17 @@ impl MessageBehavior for VmcExtMidiCcVal { let value: f32; match msg.args[0] { OscType::Int(i) => knob = i, - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[0], addr: msg.addr, arg_count: 0})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[0].to_owned(), addr: msg.addr, arg_count: 0})), } match msg.args[1] { OscType::Float(f) => value = f, - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[1], addr: msg.addr, arg_count: 1})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[1].to_owned(), addr: msg.addr, arg_count: 1})), } return Ok(VmcExtMidiCcVal { knob, value }); } } +#[derive(Debug)] struct VmcExtMidiCcBit { knob: i32, active: bool, @@ -715,7 +757,7 @@ impl MessageBehavior for VmcExtMidiCcBit { let active: bool; match msg.args[0] { OscType::Int(i) => knob = i, - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[0], addr: msg.addr, arg_count: 0})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[0].to_owned(), addr: msg.addr, arg_count: 0})), } match msg.args[1] { OscType::Int(i) => { @@ -727,12 +769,13 @@ impl MessageBehavior for VmcExtMidiCcBit { return Err(FromMessageErr::IntRange(IntRangeErr { expected_lower: 0, expected_upper: 1, actual: i, addr: msg.addr, arg_count: 1})); } } - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[1], addr: msg.addr, arg_count: 1})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[1].to_owned(), addr: msg.addr, arg_count: 1})), } return Ok(VmcExtMidiCcBit { knob, active }); } } +#[derive(Debug)] struct DeviceTranform { addr: String, serial: String, @@ -765,35 +808,35 @@ impl MessageBehavior for DeviceTranform { let mut quat = Quaternion::new(0.0, 0.0, 0.0, 0.0); match &msg.args[0] { OscType::String(s) => serial = s.to_owned(), - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::String(String::new())], actual: msg.args[0], addr: msg.addr, arg_count: 0})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::String(String::new())], actual: msg.args[0].to_owned(), addr: msg.addr, arg_count: 0})), } match msg.args[1] { OscType::Float(f) => origin.x = f, - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[1], addr: msg.addr, arg_count: 1})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[1].to_owned(), addr: msg.addr, arg_count: 1})), } match msg.args[2] { OscType::Float(f) => origin.y = f, - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[2], addr: msg.addr, arg_count: 2})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[2].to_owned(), addr: msg.addr, arg_count: 2})), } match msg.args[3] { OscType::Float(f) => origin.z = f, - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[3], addr: msg.addr, arg_count: 3})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[3].to_owned(), addr: msg.addr, arg_count: 3})), } match msg.args[4] { OscType::Float(f) => quat.x = f, - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[4], addr: msg.addr, arg_count: 4})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[4].to_owned(), addr: msg.addr, arg_count: 4})), } match msg.args[5] { OscType::Float(f) => quat.y = f, - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[5], addr: msg.addr, arg_count: 5})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[5].to_owned(), addr: msg.addr, arg_count: 5})), } match msg.args[6] { OscType::Float(f) => quat.z = f, - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[6], addr: msg.addr, arg_count: 6})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[6].to_owned(), addr: msg.addr, arg_count: 6})), } match msg.args[7] { OscType::Float(f) => quat.w = f, - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[7], addr: msg.addr, arg_count: 7})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[7].to_owned(), addr: msg.addr, arg_count: 7})), } return Ok(DeviceTranform { addr: msg.addr.to_owned(), @@ -803,6 +846,7 @@ impl MessageBehavior for DeviceTranform { } } +#[derive(Debug)] struct VmcExtRvc { enable: bool, port: u16, @@ -843,7 +887,7 @@ impl MessageBehavior for VmcExtRvc { return Err(FromMessageErr::IntRange(IntRangeErr { expected_lower: 0, expected_upper: 1, actual: i, addr: msg.addr, arg_count: 0})); } } - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[0], addr: msg.addr, arg_count: 0})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[0].to_owned(), addr: msg.addr, arg_count: 0})), } match msg.args[1] { OscType::Int(i) => { @@ -853,12 +897,12 @@ impl MessageBehavior for VmcExtRvc { return Err(FromMessageErr::IntRange(IntRangeErr { expected_lower: 0, expected_upper: 65535, actual: i, addr: msg.addr, arg_count: 1})); } } - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[1], addr: msg.addr, arg_count: 1})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[1].to_owned(), addr: msg.addr, arg_count: 1})), } if msg.args.len() == 3 { match &msg.args[2] { OscType::String(s) => ip_addr = Some(s.to_owned()), - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::String(String::new())], actual: msg.args[2], addr: msg.addr, arg_count: 2})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::String(String::new())], actual: msg.args[2].to_owned(), addr: msg.addr, arg_count: 2})), } } return Ok(VmcExtRvc { @@ -869,6 +913,7 @@ impl MessageBehavior for VmcExtRvc { } } +#[derive(Debug)] struct VmcExtLight { name: String, transform: Transform3D, @@ -906,51 +951,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(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::String(String::new())], actual: msg.args[0], addr: msg.addr, arg_count: 0})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::String(String::new())], actual: msg.args[0].to_owned(), addr: msg.addr, arg_count: 0})), } match msg.args[1] { OscType::Float(f) => origin.x = f, - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[1], addr: msg.addr, arg_count: 1})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[1].to_owned(), addr: msg.addr, arg_count: 1})), } match msg.args[2] { OscType::Float(f) => origin.y = f, - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[2], addr: msg.addr, arg_count: 2})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[2].to_owned(), addr: msg.addr, arg_count: 2})), } match msg.args[3] { OscType::Float(f) => origin.z = f, - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[3], addr: msg.addr, arg_count: 3})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[3].to_owned(), addr: msg.addr, arg_count: 3})), } match msg.args[4] { OscType::Float(f) => quat.x = f, - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[4], addr: msg.addr, arg_count: 4})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[4].to_owned(), addr: msg.addr, arg_count: 4})), } match msg.args[5] { OscType::Float(f) => quat.y = f, - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[5], addr: msg.addr, arg_count: 5})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[5].to_owned(), addr: msg.addr, arg_count: 5})), } match msg.args[6] { OscType::Float(f) => quat.z = f, - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[6], addr: msg.addr, arg_count: 6})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[6].to_owned(), addr: msg.addr, arg_count: 6})), } match msg.args[7] { OscType::Float(f) => quat.w = f, - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[7], addr: msg.addr, arg_count: 7})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[7].to_owned(), addr: msg.addr, arg_count: 7})), } match msg.args[8] { OscType::Float(f) => color.r = f, - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[8], addr: msg.addr, arg_count: 8})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[8].to_owned(), addr: msg.addr, arg_count: 8})), } match msg.args[9] { OscType::Float(f) => color.g = f, - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[9], addr: msg.addr, arg_count: 9})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[9].to_owned(), addr: msg.addr, arg_count: 9})), } match msg.args[10] { OscType::Float(f) => color.b = f, - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[10], addr: msg.addr, arg_count: 10})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[10].to_owned(), addr: msg.addr, arg_count: 10})), } match msg.args[11] { OscType::Float(f) => color.a = f, - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[11], addr: msg.addr, arg_count: 11})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[11].to_owned(), addr: msg.addr, arg_count: 11})), } return Ok(VmcExtLight { name, @@ -960,6 +1005,7 @@ impl MessageBehavior for VmcExtLight { } } +#[derive(Debug)] struct VmcExtVrm { path: String, title: String, @@ -989,22 +1035,23 @@ impl MessageBehavior for VmcExtVrm { let mut hash: Option = None; match &msg.args[0] { OscType::String(s) => path = s.to_owned(), - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::String(String::new())], actual: msg.args[0], addr: msg.addr, arg_count: 0})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::String(String::new())], actual: msg.args[0].to_owned(), addr: msg.addr, arg_count: 0})), } match &msg.args[1] { OscType::String(s) => title = s.to_owned(), - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::String(String::new())], actual: msg.args[1], addr: msg.addr, arg_count: 1})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::String(String::new())], actual: msg.args[1].to_owned(), addr: msg.addr, arg_count: 1})), } if msg.args.len() == 3 { match &msg.args[2] { OscType::String(s) => hash = Some(s.to_owned()), - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::String(String::new())], actual: msg.args[2], addr: msg.addr, arg_count: 2})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::String(String::new())], actual: msg.args[2].to_owned(), addr: msg.addr, arg_count: 2})), } } return Ok(VmcExtVrm { path, title, hash }); } } +#[derive(Debug)] struct VmcExtRemote { service: String, json: String, @@ -1028,16 +1075,17 @@ impl MessageBehavior for VmcExtRemote { let json: String; match &msg.args[0] { OscType::String(s) => service = s.to_owned(), - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::String(String::new())], actual: msg.args[0], addr: msg.addr, arg_count: 0})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::String(String::new())], actual: msg.args[0].to_owned(), addr: msg.addr, arg_count: 0})), } match &msg.args[1] { OscType::String(s) => json = s.to_owned(), - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::String(String::new())], actual: msg.args[1], addr: msg.addr, arg_count: 1})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::String(String::new())], actual: msg.args[1].to_owned(), addr: msg.addr, arg_count: 1})), } return Ok(VmcExtRemote { service, json }); } } +#[derive(Debug)] struct VmcExtOpt { option: String, } @@ -1059,11 +1107,12 @@ impl MessageBehavior for VmcExtOpt { option: s.to_owned(), }) } - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::String(String::new())], actual: msg.args[0], addr: msg.addr, arg_count: 0})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::String(String::new())], actual: msg.args[0].to_owned(), addr: msg.addr, arg_count: 0})), } } } +#[derive(Debug)] struct VmcExtSettingColor { color: Color, } @@ -1087,24 +1136,25 @@ impl MessageBehavior for VmcExtSettingColor { 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(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[0], addr: msg.addr, arg_count: 0})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[0].to_owned(), addr: msg.addr, arg_count: 0})), } match msg.args[1] { OscType::Float(f) => color.g = f, - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[1], addr: msg.addr, arg_count: 1})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[1].to_owned(), addr: msg.addr, arg_count: 1})), } match msg.args[2] { OscType::Float(f) => color.b = f, - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[2], addr: msg.addr, arg_count: 2})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[2].to_owned(), addr: msg.addr, arg_count: 2})), } match msg.args[3] { OscType::Float(f) => color.a = f, - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[3], addr: msg.addr, arg_count: 3})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[3].to_owned(), addr: msg.addr, arg_count: 3})), } return Ok(VmcExtSettingColor { color }); } } +#[derive(Debug)] struct VmcExtSettingWin { is_top_most: bool, is_transparent: bool, @@ -1152,7 +1202,7 @@ impl MessageBehavior for VmcExtSettingWin { return Err(FromMessageErr::IntRange(IntRangeErr { expected_lower: 0, expected_upper: 1, actual: i, addr: msg.addr, arg_count: 0})); } } - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[0], addr: msg.addr, arg_count: 0})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[0].to_owned(), addr: msg.addr, arg_count: 0})), } match msg.args[1] { OscType::Int(i) => { @@ -1162,20 +1212,21 @@ impl MessageBehavior for VmcExtSettingWin { return Err(FromMessageErr::IntRange(IntRangeErr { expected_lower: 0, expected_upper: 1, actual: i, addr: msg.addr, arg_count: 1})); } } - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[1], addr: msg.addr, arg_count: 1})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[1].to_owned(), addr: msg.addr, arg_count: 1})), } match msg.args[2] { OscType::Int(i) => result.window_click_through = i, - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[2], addr: msg.addr, arg_count: 2})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[2].to_owned(), addr: msg.addr, arg_count: 2})), } match msg.args[3] { OscType::Int(i) => result.hide_border = i, - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[3], addr: msg.addr, arg_count: 3})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[3].to_owned(), addr: msg.addr, arg_count: 3})), } return Ok(result); } } +#[derive(Debug)] struct VmcExtConfig { path: String, } @@ -1193,17 +1244,18 @@ impl MessageBehavior for VmcExtConfig { } match &msg.args[0] { OscType::String(s) => return Ok(VmcExtConfig { path: s.to_owned() }), - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::String(String::new())], actual: msg.args[0], addr: msg.addr, arg_count: 0})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::String(String::new())], actual: msg.args[0].to_owned(), addr: msg.addr, arg_count: 0})), } } } -#[derive(Clone, Copy)] +#[derive(Clone, Copy, Debug)] enum ThruType { Float(f32), Int(i32), } +#[derive(Debug)] struct VmcThru { addr: String, arg1: String, @@ -1229,20 +1281,21 @@ impl MessageBehavior for VmcThru { let arg1: String; match &msg.args[0] { OscType::String(s) => arg1 = s.to_owned(), - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::String(String::new())], actual: msg.args[0], addr: msg.addr, arg_count: 0})), + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::String(String::new())], actual: msg.args[0].to_owned(), addr: msg.addr, arg_count: 0})), } let mut arg2: Option = None; if msg.args.len() == 2 { match msg.args[1] { OscType::Int(i) => arg2 = Some(ThruType::Int(i)), OscType::Float(f) => arg2 = Some(ThruType::Float(f)), - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0), OscType::Float(0.0)], actual: msg.args[1], addr: msg.addr, arg_count: 1})) + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0), OscType::Float(0.0)], actual: msg.args[1].to_owned(), addr: msg.addr, arg_count: 1})) } } return Ok(VmcThru { addr: msg.addr, arg1 , arg2 }) } } +#[derive(Debug)] struct VmcExtSetPeriod { status: i32, root: i32, @@ -1275,32 +1328,33 @@ impl MessageBehavior for VmcExtSetPeriod { let devices: i32; match msg.args[0] { OscType::Int(i) => status = i, - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[0], addr: msg.addr, arg_count: 0})) + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[0].to_owned(), addr: msg.addr, arg_count: 0})) } match msg.args[1] { OscType::Int(i) => root = i, - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[1], addr: msg.addr, arg_count: 1})) + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[1].to_owned(), addr: msg.addr, arg_count: 1})) } match msg.args[2] { OscType::Int(i) => bone = i, - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[2], addr: msg.addr, arg_count: 2})) + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[2].to_owned(), addr: msg.addr, arg_count: 2})) } match msg.args[3] { OscType::Int(i) => blendshape = i, - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[3], addr: msg.addr, arg_count: 3})) + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[3].to_owned(), addr: msg.addr, arg_count: 3})) } match msg.args[4] { OscType::Int(i) => camera = i, - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[4], addr: msg.addr, arg_count: 4})) + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[4].to_owned(), addr: msg.addr, arg_count: 4})) } match msg.args[5] { OscType::Int(i) => devices = i, - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[5], addr: msg.addr, arg_count: 5})) + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[5].to_owned(), addr: msg.addr, arg_count: 5})) } return Ok(VmcExtSetPeriod { status, root, bone, blendshape, camera, devices}) } } +#[derive(Debug)] struct VmcExtSetEye { enable: i32, position: Vector3, @@ -1326,25 +1380,26 @@ impl MessageBehavior for VmcExtSetEye { let z: f32; match msg.args[0] { OscType::Int(i) => enable = i, - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[0], addr: msg.addr, arg_count: 0})) + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Int(0)], actual: msg.args[0].to_owned(), addr: msg.addr, arg_count: 0})) } match msg.args[1] { OscType::Float(f) => x = f, - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[1], addr: msg.addr, arg_count: 1})) + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[1].to_owned(), addr: msg.addr, arg_count: 1})) } match msg.args[2] { OscType::Float(f) => y = f, - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[2], addr: msg.addr, arg_count: 2})) + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[2].to_owned(), addr: msg.addr, arg_count: 2})) } match msg.args[3] { OscType::Float(f) => z = f, - _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[3], addr: msg.addr, arg_count: 3})) + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::Float(0.0)], actual: msg.args[3].to_owned(), addr: msg.addr, arg_count: 3})) } return Ok(VmcExtSetEye { enable, position: Vector3::new(x, y, z)}) } } +#[derive(Debug)] struct VmcExtSetRes { response: String } @@ -1353,13 +1408,13 @@ impl MessageBehavior for VmcExtSetRes { fn to_osc_message(&self) -> OscMessage { return OscMessage{addr: String::from("/VMC/Ext/Set/Res"), args: vec![OscType::from(self.response.to_owned())]}; } - fn from_osc_message(msg: OscMessage) -> Result { + fn from_osc_message(msg: OscMessage) -> Result { if msg.args.len() != 1 { - return Err(String::from("arg count invalid")); + return Err(FromMessageErr::ArgCount(ArgCountErr { expected_in: vec![1], actual: msg.args.len(), addr: msg.addr})); } match &msg.args[0] { OscType::String(s) => return Ok(VmcExtSetRes{response: s.to_owned()}), - _ => return Err(String::from("arg type invalid")) + _ => return Err(FromMessageErr::ArgType(ArgTypeErr { expected: vec![OscType::String(String::new())], actual: msg.args[0].to_owned(), addr: msg.addr, arg_count: 0})) } } } -- 2.30.2