12
12
// See the License for the specific language governing permissions and
13
13
// limitations under the License.
14
14
15
- use crate :: Result ;
16
-
17
15
use crate :: client:: feature_proxy:: FeatureProxy ;
18
16
use crate :: client:: feature_snapshot:: FeatureSnapshot ;
19
17
use crate :: client:: property_proxy:: PropertyProxy ;
20
18
use crate :: client:: property_snapshot:: PropertySnapshot ;
21
-
19
+ use crate :: Result ;
22
20
/// Identifies a configuration
23
21
#[ derive( Debug , Clone ) ]
24
22
pub struct ConfigurationId {
@@ -40,12 +38,11 @@ impl ConfigurationId {
40
38
}
41
39
}
42
40
43
- /// AppConfiguration client for browsing, and evaluating features and properties.
44
- pub trait AppConfigurationClient {
41
+ pub trait ConfigurationProvider {
45
42
/// Returns the list of features.
46
43
///
47
- /// The list contains the `id`s that can be used in [`get_feature`](AppConfigurationClient::get_feature)
48
- /// or [`get_feature_proxy `](AppConfigurationClient::get_feature_proxy) to retrieve the actual features .
44
+ /// The list contains the `id`s that can be used in other methods to return
45
+ /// concrete features, like [`get_feature `](ConfigurationProvider::get_feature) .
49
46
fn get_feature_ids ( & self ) -> Result < Vec < String > > ;
50
47
51
48
/// Returns a snapshot for a [`Feature`](crate::Feature).
@@ -55,16 +52,10 @@ pub trait AppConfigurationClient {
55
52
/// will be received from the server.
56
53
fn get_feature ( & self , feature_id : & str ) -> Result < FeatureSnapshot > ;
57
54
58
- /// Returns a proxied [`Feature`](crate::Feature).
59
- ///
60
- /// This proxied feature will envaluate entities using the latest information
61
- /// available if the client implementation support some kind of live-updates.
62
- fn get_feature_proxy < ' a > ( & ' a self , feature_id : & str ) -> Result < FeatureProxy < ' a > > ;
63
-
64
55
/// Returns the list of properties.
65
56
///
66
- /// The list contains the `id`s that can be used in [`get_property`](AppConfigurationClient::get_property)
67
- /// or [`get_property_proxy `](AppConfigurationClient::get_property_proxy) to retrieve the actual features .
57
+ /// The list contains the `id`s that can be used in other methods to return
58
+ /// concrete properties, like [`get_property `](ConfigurationProvider::get_property) .
68
59
fn get_property_ids ( & self ) -> Result < Vec < String > > ;
69
60
70
61
/// Returns a snapshot for a [`Property`](crate::Property).
@@ -73,10 +64,32 @@ pub trait AppConfigurationClient {
73
64
/// will always evaluate the same entities to the same values, no updates
74
65
/// will be received from the server
75
66
fn get_property ( & self , property_id : & str ) -> Result < PropertySnapshot > ;
67
+ }
68
+
69
+ /// AppConfiguration client for browsing, and evaluating features and properties.
70
+ pub trait AppConfigurationClient : ConfigurationProvider {
71
+ /// Returns a proxied [`Feature`](crate::Feature).
72
+ ///
73
+ /// This proxied feature will envaluate entities using the latest information
74
+ /// available if the client implementation support some kind of live-updates.
75
+ fn get_feature_proxy < ' a > ( & ' a self , feature_id : & str ) -> Result < FeatureProxy < ' a > > ;
76
76
77
77
/// Returns a proxied [`Property`](crate::Property).
78
78
///
79
79
/// This proxied property will envaluate entities using the latest information
80
80
/// available if the client implementation support some kind of live-updates.
81
81
fn get_property_proxy ( & self , property_id : & str ) -> Result < PropertyProxy > ;
82
82
}
83
+
84
+ impl < T : ConfigurationProvider > AppConfigurationClient for T {
85
+ fn get_feature_proxy < ' a > ( & ' a self , feature_id : & str ) -> Result < FeatureProxy < ' a > > {
86
+ // FIXME: there is and was no validation happening if the feature exists.
87
+ // Comments and error messages in FeatureProxy suggest that this should happen here.
88
+ // same applies for properties.
89
+ Ok ( FeatureProxy :: new ( self , feature_id. to_string ( ) ) )
90
+ }
91
+
92
+ fn get_property_proxy ( & self , property_id : & str ) -> Result < PropertyProxy > {
93
+ Ok ( PropertyProxy :: new ( self , property_id. to_string ( ) ) )
94
+ }
95
+ }
0 commit comments