You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I think it would be great to make more use of the generated enums as I think it makes the api more compile-time safe and convenient to use. Right now it mostly saves you from putting .into() everywhere but furthermore I think a proper type makes it easier to use the api correctly. My proposal would be to rename the setters, analogue to the getters, to include a raw suffix and add a fn that uses the enum parameter. Same for new.
/// Construct new Bar from valuespubfnnew(one:u8,two:f32,three:BarThree,four:u8,xtype:BarType) -> Result<Self,CanError>{letmut res = Self{raw:[0u8;8]};
res.set_one(one)?;
res.set_two(two)?;
res.set_three(three)?;
res.set_four(four)?;
res.set_xtype(xtype)?;Ok(res)}/// Construct new Bar from valuespubfnnew_raw(one:u8,two:f32,three:u8,four:u8,xtype:bool) -> Result<Self,CanError>{letmut res = Self{raw:[0u8;8]};
res.set_one(one)?;
res.set_two(two)?;
res.set_three(three)?;
res.set_four(four)?;
res.set_xtype(xtype)?;Ok(res)}/// Three////// - Min: 0/// - Max: 7/// - Unit: ""/// - Receivers: Dolor#[inline(always)]pubfnthree(&self) -> BarThree{self.three_raw().into()}/// Get raw value of Three////// - Start bit: 13/// - Signal size: 3 bits/// - Factor: 1/// - Offset: 0/// - Byte order: BigEndian/// - Value type: Unsigned#[inline(always)]pubfnthree_raw(&self) -> u8{let signal = self.raw.view_bits::<Msb0>()[10..13].load_be::<u8>();
signal
}/// Set value of Three#[inline(always)]pubfnset_three_raw(&mutself,value:u8) -> Result<&mutSelf,CanError>{#[cfg(feature = "range_checked")]if value < 0_u8 || 7_u8 < value {returnErr(CanError::ParameterOutOfRange{message_id:512});}self.raw.view_bits_mut::<Msb0>()[10..13].store_be(value);Ok(self)}/// Set value of Three#[inline(always)]pubfnset_three(&mutself,value:BarThree) -> Result<&mutSelf,CanError>{self.set_three_raw(value.into())}
The text was updated successfully, but these errors were encountered:
I think it would be great to make more use of the generated enums as I think it makes the api more compile-time safe and convenient to use. Right now it mostly saves you from putting
.into()
everywhere but furthermore I think a proper type makes it easier to use the api correctly. My proposal would be to rename the setters, analogue to the getters, to include a raw suffix and add a fn that uses the enum parameter. Same fornew
.The text was updated successfully, but these errors were encountered: