14
14
15
15
use std:: { collections:: HashMap , env, thread, time:: Duration } ;
16
16
17
- use appconfiguration_rust_sdk:: { client:: AppConfigurationClient , AttrValue , Entity , Feature , Property } ;
17
+ use appconfiguration_rust_sdk:: {
18
+ AppConfigurationClient , AttrValue , Entity , Feature , Property , Value ,
19
+ } ;
18
20
use dotenvy:: dotenv;
19
21
use std:: error:: Error ;
20
22
21
- type Result < T > = std:: result:: Result < T , Box < dyn Error + Send + Sync > > ;
22
-
23
23
#[ derive( Debug ) ]
24
24
struct CustomerEntity {
25
25
id : String ,
@@ -33,16 +33,14 @@ impl Entity for CustomerEntity {
33
33
}
34
34
35
35
fn get_attributes ( & self ) -> HashMap < String , AttrValue > {
36
- use AttrValue ;
37
-
38
36
HashMap :: from_iter ( vec ! [
39
37
( "city" . to_string( ) , AttrValue :: String ( self . city. clone( ) ) ) ,
40
38
( "radius" . to_string( ) , AttrValue :: Numeric ( self . radius as f64 ) ) ,
41
39
] )
42
40
}
43
41
}
44
42
45
- fn main ( ) -> Result < ( ) > {
43
+ fn main ( ) -> std :: result :: Result < ( ) , Box < dyn Error > > {
46
44
dotenv ( ) . ok ( ) ;
47
45
let region = env:: var ( "REGION" ) . expect ( "REGION should be set." ) ;
48
46
let guid = env:: var ( "GUID" ) . expect ( "GUID should be set." ) ;
@@ -70,13 +68,15 @@ fn main() -> Result<()> {
70
68
match client. get_feature_proxy ( & feature_id) {
71
69
Ok ( feature) => {
72
70
println ! ( "Feature name: {}" , feature. get_name( ) ?) ;
73
- println ! ( "Feature id: {}" , feature. get_id( ) ) ;
74
- println ! ( "Feature data type: {}" , feature. get_data_type( ) ?) ;
71
+ let value = feature. get_value ( & entity) ?;
72
+ let data_type = match & value {
73
+ Value :: Numeric ( _) => "Numeric" ,
74
+ Value :: String ( _) => "String" ,
75
+ Value :: Boolean ( _) => "Boolean" ,
76
+ } ;
77
+ println ! ( "Feature data type: {}" , data_type) ;
75
78
println ! ( "Is feature enabled: {}" , feature. is_enabled( ) ?) ;
76
- println ! (
77
- "Feature evaluated value is: {:?}" ,
78
- feature. get_value( & entity) ?
79
- ) ;
79
+ println ! ( "Feature evaluated value is: {value:?}" ) ;
80
80
}
81
81
Err ( error) => {
82
82
println ! ( "There was an error getting the Feature Flag. Error {error}" , ) ;
@@ -87,12 +87,14 @@ fn main() -> Result<()> {
87
87
match client. get_property_proxy ( & property_id) {
88
88
Ok ( property) => {
89
89
println ! ( "Property name: {}" , property. get_name( ) ?) ;
90
- println ! ( "Property id: {}" , property. get_id( ) ) ;
91
- println ! ( "Property data type: {}" , property. get_data_type( ) ?) ;
92
- println ! (
93
- "Property evaluated value is: {:?}" ,
94
- property. get_value( & entity) ?
95
- ) ;
90
+ let value = property. get_value ( & entity) ?;
91
+ let data_type = match & value {
92
+ Value :: Numeric ( _) => "Numeric" ,
93
+ Value :: String ( _) => "String" ,
94
+ Value :: Boolean ( _) => "Boolean" ,
95
+ } ;
96
+ println ! ( "Property data type: {data_type}" ) ;
97
+ println ! ( "Property evaluated value is: {value:?}" ) ;
96
98
}
97
99
Err ( error) => {
98
100
println ! ( "There was an error getting the Property. Error {error}" , ) ;
0 commit comments