type aliasing and create a few more constructors

This commit is contained in:
Cassandra de la Cruz-Munoz 2024-01-01 13:30:27 -05:00
parent c3193e2fbc
commit 682591278f
Signed by: cassdlcm
GPG Key ID: BFEBACEA812DDA70

View File

@ -112,6 +112,10 @@ pub enum MessageCreationErr {
OptionalArgs(CreateOptionalArgsErr),
}
type MsgNewResult<T> = Result<T, MessageCreationErr>;
type TraitMsgNewResult = Result<Box<dyn VmcMessage>, MessageCreationErr>;
#[derive(Debug)]
pub struct VmcExtOk {
loaded: i32,
@ -202,7 +206,7 @@ impl VmcMessage for VmcExtOk {
}
impl VmcExtOk {
pub fn new(loaded: i32, calibration_state: Option<i32>, calibration_mode: Option<i32>, tracking_status: Option<i32>) -> Result<Self, MessageCreationErr> {
pub fn new(loaded: i32, calibration_state: Option<i32>, calibration_mode: Option<i32>, tracking_status: Option<i32>) -> MsgNewResult<Self> {
if loaded < 0 || loaded > 1 {
return Err(MessageCreationErr::IntRange(CreateIntRangeErr { expected_lower: 0, expected_upper: 1, actual: loaded, calling_func: String::from("VmcExtOk::new"), arg_name: String::from("loaded")}));
}
@ -235,12 +239,12 @@ impl VmcExtOk {
}
return Ok(Self { loaded, calibration_state: None, calibration_mode: None, tracking_status: None})
}
pub fn new_vmc_message(loaded: i32, calibration_state: Option<i32>, calibration_mode: Option<i32>, tracking_status: Option<i32>) -> Result<Box<dyn VmcMessage>, MessageCreationErr> {
pub fn new_vmc_message(loaded: i32, calibration_state: Option<i32>, calibration_mode: Option<i32>, tracking_status: Option<i32>) -> TraitMsgNewResult {
let msg = Self::new(loaded, calibration_state, calibration_mode, tracking_status);
if msg.is_ok() {
return Ok(Box::new(msg.ok().unwrap()));
match msg {
Ok(val) => return Ok(Box::new(val)),
Err(val) => return Err(val)
}
return Err(msg.err().unwrap());
}
}
@ -273,15 +277,15 @@ impl VmcMessage for VmcExtT {
}
impl VmcExtT {
pub fn new(time: f32) -> Result<Self, MessageCreationErr> {
pub fn new(time: f32) -> MsgNewResult<Self> {
return Ok(Self { time });
}
pub fn new_vmc_message(time: f32) -> Result<Box<dyn VmcMessage>, MessageCreationErr> {
pub fn new_vmc_message(time: f32) -> TraitMsgNewResult {
let msg = Self::new(time);
if msg.is_ok() {
return Ok(Box::new(msg.ok().unwrap()));
match msg {
Ok(val) => return Ok(Box::new(val)),
Err(val) => return Err(val)
}
return Err(msg.err().unwrap());
}
}
@ -415,7 +419,7 @@ impl VmcMessage for VmcExtRootPos {
}
impl VmcExtRootPos {
pub fn new(name: String, transform: Transform3D, mr_scale: Option<Vector3>, mr_offset: Option<Vector3>) -> Result<Self, MessageCreationErr> {
pub fn new(name: String, transform: Transform3D, mr_scale: Option<Vector3>, mr_offset: Option<Vector3>) -> MsgNewResult<Self> {
if mr_scale.is_some() && mr_offset.is_none() {
return Err(MessageCreationErr::OptionalArgs(CreateOptionalArgsErr { expected_sets: vec![String::from("None"), String::from("mr_scale, mr_offset")], actual: String::from("mr_scale"), calling_func: String::from("VmcExtRootPos::new")}));
}
@ -424,12 +428,12 @@ impl VmcExtRootPos {
}
return Ok(Self { name, transform, mr_scale, mr_offset});
}
pub fn new_vmc_message(name: String, transform: Transform3D, mr_scale: Option<Vector3>, mr_offset: Option<Vector3>) -> Result<Box<dyn VmcMessage>, MessageCreationErr> {
pub fn new_vmc_message(name: String, transform: Transform3D, mr_scale: Option<Vector3>, mr_offset: Option<Vector3>) -> TraitMsgNewResult {
let message = Self::new(name, transform, mr_scale, mr_offset);
if message.is_ok() {
return Ok(Box::new(message.ok().unwrap()));
match message {
Ok(val) => return Ok(Box::new(val)),
Err(val) => return Err(val)
}
return Err(message.err().unwrap());
}
}
@ -511,15 +515,15 @@ impl VmcMessage for VmcExtBonePos {
}
impl VmcExtBonePos {
pub fn new(name: String, transform: Transform3D) -> Result<Self, MessageCreationErr> {
pub fn new(name: String, transform: Transform3D) -> MsgNewResult<Self> {
return Ok(Self{name, transform});
}
pub fn new_vmc_message(name: String, transform: Transform3D) -> Result<Box<dyn VmcMessage>, MessageCreationErr> {
pub fn new_vmc_message(name: String, transform: Transform3D) -> TraitMsgNewResult {
let message = Self::new(name, transform);
if message.is_ok() {
return Ok(Box::new(message.ok().unwrap()));
match message {
Ok(val) => return Ok(Box::new(val)),
Err(val) => return Err(val)
}
return Err(message.err().unwrap());
}
}
@ -561,15 +565,15 @@ impl VmcMessage for VmcExtBlendVal {
}
impl VmcExtBlendVal {
pub fn new(name: String, value: f32) -> Result<Self, MessageCreationErr> {
pub fn new(name: String, value: f32) -> MsgNewResult<Self> {
return Ok(Self{name, value});
}
pub fn new_vmc_message(name: String, value: f32) -> Result<Box<dyn VmcMessage>, MessageCreationErr> {
pub fn new_vmc_message(name: String, value: f32) -> TraitMsgNewResult {
let message = Self::new(name, value);
if message.is_ok() {
return Ok(Box::new(message.ok().unwrap()));
match message {
Ok(val) => return Ok(Box::new(val)),
Err(val) => return Err(val)
}
return Err(message.err().unwrap());
}
}
@ -657,12 +661,12 @@ impl VmcExtCam {
pub fn new(name: String, transform: Transform3D, fov: f32) ->Result<VmcExtCam, MessageCreationErr> {
return Ok(Self{name, transform, fov})
}
pub fn new_vmc_message(name: String, transform: Transform3D, fov: f32) -> Result<Box<dyn VmcMessage>, MessageCreationErr> {
pub fn new_vmc_message(name: String, transform: Transform3D, fov: f32) -> TraitMsgNewResult {
let message = Self::new(name, transform, fov);
if message.is_ok() {
return Ok(Box::new(message.ok().unwrap()));
match message {
Ok(val) => return Ok(Box::new(val)),
Err(val) => return Err(val)
}
return Err(message.err().unwrap());
}
}
@ -767,23 +771,23 @@ impl VmcMessage for VmcExtCon {
}
impl VmcExtCon {
pub fn new(active: i32, name: String, is_left: bool, is_touch: bool, axis: Vector3) -> Result<Self, MessageCreationErr> {
pub fn new(active: i32, name: String, is_left: bool, is_touch: bool, axis: Vector3) -> MsgNewResult<Self> {
if active > 2 || active < 0 {
return Err(MessageCreationErr::IntRange(CreateIntRangeErr { expected_lower: 0, expected_upper: 2, actual: active, calling_func: String::from("VmcExtCon::new"), arg_name: String::from("active")}))
}
return Ok(Self{ active, name, is_left, is_touch, axis });
}
pub fn new_vmc_message(active: i32, name: String, is_left: bool, is_touch: bool, axis: Vector3) -> Result<Box<dyn VmcMessage>, MessageCreationErr> {
pub fn new_vmc_message(active: i32, name: String, is_left: bool, is_touch: bool, axis: Vector3) -> TraitMsgNewResult {
let message = Self::new(active, name, is_left, is_touch, axis);
if message.is_ok() {
return Ok(Box::new(message.ok().unwrap()));
match message {
Ok(val) => return Ok(Box::new(val)),
Err(val) => return Err(val)
}
return Err(message.err().unwrap());
}
}
#[derive(Debug)]
struct VmcExtKey {
pub struct VmcExtKey {
active: bool,
name: String,
keycode: i32,
@ -844,8 +848,21 @@ impl VmcMessage for VmcExtKey {
}
}
impl VmcExtKey {
pub fn new(active: bool, name: String, keycode: i32) -> MsgNewResult<Self> {
return Ok(Self { active, name, keycode})
}
pub fn new_vmc_message(active: bool, name: String, keycode: i32) -> TraitMsgNewResult {
let message = Self::new(active, name, keycode);
match message {
Ok(val) => return Ok(Box::new(val)),
Err(val) => return Err(val)
}
}
}
#[derive(Debug)]
struct VmcExtMidiNote {
pub struct VmcExtMidiNote {
active: bool,
channel: i32,
note: i32,
@ -914,8 +931,21 @@ impl VmcMessage for VmcExtMidiNote {
}
}
impl VmcExtMidiNote {
pub fn new(active: bool, channel: i32, note: i32, velocity: f32) -> MsgNewResult<Self> {
return Ok(Self { active, channel, note, velocity})
}
pub fn new_vmc_message(active: bool, channel: i32, note: i32, velocity: f32) -> TraitMsgNewResult {
let message = Self::new(active, channel, note, velocity);
match message {
Ok(val) => return Ok(Box::new(val)),
Err(val) => return Err(val)
}
}
}
#[derive(Debug)]
struct VmcExtMidiCcVal {
pub struct VmcExtMidiCcVal {
knob: i32,
value: f32,
}
@ -948,6 +978,19 @@ impl VmcMessage for VmcExtMidiCcVal {
}
}
impl VmcExtMidiCcVal {
pub fn new(knob: i32, value: f32) -> MsgNewResult<Self> {
return Ok(Self { knob, value});
}
pub fn new_vmc_message(knob: i32, value: f32) -> TraitMsgNewResult {
let message = Self::new(knob, value);
match message {
Ok(val) => return Ok(Box::new(val)),
Err(val) => return Err(val),
}
}
}
#[derive(Debug)]
struct VmcExtMidiCcBit {
knob: i32,