@@ -85,17 +85,21 @@ pub(crate) fn map_property_to_astarte_type(
8585 Ok ( Some ( individual. try_into ( ) ?) )
8686}
8787
88- /// Map a list of properties that need to be set , unset value will result in an error of the conversion
88+ /// Map a list of properties, unset properties will be ignored
8989pub ( crate ) fn map_set_stored_properties (
9090 mut message_hub_properties : astarte_message_hub_proto:: StoredProperties ,
9191) -> Result < Vec < StoredProp > , MessageHubProtoError > {
9292 message_hub_properties
9393 . interface_properties
9494 . iter_mut ( )
9595 . flat_map ( |( name, prop_data) | {
96- prop_data. properties . iter ( ) . map ( |p| {
96+ prop_data. properties . iter ( ) . filter_map ( |p| {
9797 let path = p. path . clone ( ) ;
98- let value: AstarteType = p. clone ( ) . try_into ( ) ?;
98+ let value: AstarteType =
99+ match map_property_to_astarte_type ( p. clone ( ) ) . transpose ( ) ? {
100+ Ok ( s) => s,
101+ Err ( e) => return Some ( Err ( e) ) ,
102+ } ;
99103
100104 let res = StoredProp {
101105 interface : name. clone ( ) ,
@@ -105,7 +109,7 @@ pub(crate) fn map_set_stored_properties(
105109 ownership : prop_data. ownership ( ) . into ( ) ,
106110 } ;
107111
108- Ok ( res)
112+ Some ( Ok ( res) )
109113 } )
110114 } )
111115 . try_collect ( )
@@ -120,16 +124,6 @@ impl From<astarte_message_hub_proto::Ownership> for Ownership {
120124 }
121125}
122126
123- /// Construct an sdk astarte type from a property that is required to be set
124- impl TryFrom < astarte_message_hub_proto:: Property > for AstarteType {
125- type Error = MessageHubProtoError ;
126-
127- fn try_from ( property : astarte_message_hub_proto:: Property ) -> Result < Self , Self :: Error > {
128- map_property_to_astarte_type ( property)
129- . and_then ( |value| value. ok_or ( MessageHubProtoError :: ExpectedSetProperty ) )
130- }
131- }
132-
133127impl TryFrom < ProtoIndividualData > for AstarteType {
134128 type Error = MessageHubProtoError ;
135129
@@ -472,6 +466,8 @@ mod test {
472466 } ;
473467 use chrono:: { DateTime , Utc } ;
474468
469+ use crate :: transport:: grpc:: convert:: map_property_to_astarte_type;
470+
475471 use super :: * ;
476472
477473 #[ test]
@@ -1356,26 +1352,23 @@ mod test {
13561352 }
13571353
13581354 #[ test]
1359- fn map_property_to_astarte_type ( ) {
1355+ fn map_property_to_astarte_type_ok ( ) {
13601356 let value: AstarteType = AstarteType :: String ( "test" . to_owned ( ) ) ;
13611357
13621358 let prop = make_messagehub_property ( "/path11" , Some ( value. clone ( ) ) ) ;
13631359
1364- let astarte_type = AstarteType :: try_from ( prop) . unwrap ( ) ;
1360+ let astarte_type = map_property_to_astarte_type ( prop) . unwrap ( ) . unwrap ( ) ;
13651361
13661362 assert_eq ! ( value, astarte_type) ;
13671363 }
13681364
13691365 #[ test]
1370- fn map_property_to_astarte_type_error ( ) {
1366+ fn map_property_to_astarte_type_none ( ) {
13711367 let prop = make_messagehub_property ( "/path11" , None ) ;
13721368
1373- let astarte_type_err = AstarteType :: try_from ( prop) ;
1369+ let astarte_type_err = map_property_to_astarte_type ( prop) ;
13741370
1375- assert ! ( matches!(
1376- astarte_type_err,
1377- Err ( MessageHubProtoError :: ExpectedSetProperty )
1378- ) ) ;
1371+ assert ! ( matches!( astarte_type_err, Ok ( None ) ) ) ;
13791372 }
13801373
13811374 #[ test]
0 commit comments