@@ -91,6 +91,8 @@ impl Foo {
9191 /// Set value of Voltage
9292 #[ inline( always) ]
9393 pub fn set_voltage ( & mut self , value : f32 ) -> Result < ( ) , CanError > {
94+ #[ cfg( feature = "range_checked" ) ]
95+ assert ! ( 0f32 <= value && value <= 63.9990234375f32 ) ;
9496 let factor = 0.000976562_f32 ;
9597 let offset = 0_f32 ;
9698 let value = ( ( value - offset) / factor) as u16 ;
@@ -132,6 +134,8 @@ impl Foo {
132134 /// Set value of Current
133135 #[ inline( always) ]
134136 pub fn set_current ( & mut self , value : f32 ) -> Result < ( ) , CanError > {
137+ #[ cfg( feature = "range_checked" ) ]
138+ assert ! ( -2048f32 <= value && value <= 2047.9375f32 ) ;
135139 let factor = 0.0625_f32 ;
136140 let offset = 0_f32 ;
137141 let value = ( ( value - offset) / factor) as i16 ;
@@ -215,6 +219,8 @@ impl Bar {
215219 /// Set value of One
216220 #[ inline( always) ]
217221 pub fn set_one ( & mut self , value : u8 ) -> Result < ( ) , CanError > {
222+ #[ cfg( feature = "range_checked" ) ]
223+ assert ! ( 0u8 <= value && value <= 3u8 ) ;
218224 let start_bit = 15 ;
219225 let bits = 2 ;
220226 value. pack_be_bits ( & mut self . raw , start_bit, bits) ;
@@ -252,6 +258,8 @@ impl Bar {
252258 /// Set value of Two
253259 #[ inline( always) ]
254260 pub fn set_two ( & mut self , value : f32 ) -> Result < ( ) , CanError > {
261+ #[ cfg( feature = "range_checked" ) ]
262+ assert ! ( 0f32 <= value && value <= 100f32 ) ;
255263 let factor = 0.39_f32 ;
256264 let offset = 0_f32 ;
257265 let value = ( ( value - offset) / factor) as u8 ;
@@ -297,6 +305,8 @@ impl Bar {
297305 /// Set value of Three
298306 #[ inline( always) ]
299307 pub fn set_three ( & mut self , value : u8 ) -> Result < ( ) , CanError > {
308+ #[ cfg( feature = "range_checked" ) ]
309+ assert ! ( 0u8 <= value && value <= 7u8 ) ;
300310 let start_bit = 13 ;
301311 let bits = 3 ;
302312 value. pack_be_bits ( & mut self . raw , start_bit, bits) ;
@@ -338,6 +348,8 @@ impl Bar {
338348 /// Set value of Four
339349 #[ inline( always) ]
340350 pub fn set_four ( & mut self , value : u8 ) -> Result < ( ) , CanError > {
351+ #[ cfg( feature = "range_checked" ) ]
352+ assert ! ( 0u8 <= value && value <= 3u8 ) ;
341353 let start_bit = 10 ;
342354 let bits = 2 ;
343355 value. pack_be_bits ( & mut self . raw , start_bit, bits) ;
@@ -360,7 +372,7 @@ impl core::convert::TryFrom<&[u8]> for Bar {
360372}
361373
362374/// Defined values for Three
363- #[ derive( Clone , Copy ) ]
375+ #[ derive( Clone , Copy , PartialEq ) ]
364376#[ cfg_attr( feature = "debug" , derive( Debug ) ) ]
365377pub enum BarThree {
366378 Off ,
0 commit comments