@@ -18,7 +18,6 @@ pub struct Id<T> {
1818}
1919
2020impl < T > Id < T > {
21-
2221 /// private method to build an Id that exists in the [Collection]
2322 fn must_exists ( s : String ) -> Id < T > {
2423 Id {
@@ -27,12 +26,18 @@ impl<T> Id<T> {
2726 }
2827 }
2928
30- /// get as str
29+ /// Extracts a string slice containing the entire [Id]
3130 pub fn as_str ( & self ) -> & str {
3231 self
3332 }
3433}
3534
35+ impl < T > std:: convert:: AsRef < str > for Id < T > {
36+ fn as_ref ( & self ) -> & str {
37+ self
38+ }
39+ }
40+
3641impl < T > std:: ops:: Deref for Id < T > {
3742 type Target = str ;
3843 fn deref ( & self ) -> & str {
@@ -58,7 +63,6 @@ impl<T> Default for Collection<T> {
5863}
5964
6065impl < T > Collection < T > {
61-
6266 /// Get a typed [Id] from a raw &str
6367 /// An [Id] can be returned only if it exists in the [Collection]
6468 pub fn get_id ( & self , raw_id : & str ) -> Option < Id < T > > {
@@ -69,10 +73,12 @@ impl<T> Collection<T> {
6973 pub ( crate ) fn get_by_str ( & self , raw_id : & str ) -> Option < ( & Id < T > , & T ) > {
7074 self . 0 . get_key_value ( raw_id)
7175 }
72-
76+
7377 /// Get an &[Id] and a mutable reference to the object associated with it if it exists in the [Collection]
7478 pub ( crate ) fn get_mut_by_str ( & mut self , raw_id : & str ) -> Option < ( Id < T > , & mut T ) > {
75- self . 0 . get_mut ( raw_id) . map ( |v| ( Id :: must_exists ( raw_id. to_owned ( ) ) , v) )
79+ self . 0
80+ . get_mut ( raw_id)
81+ . map ( |v| ( Id :: must_exists ( raw_id. to_owned ( ) ) , v) )
7682 }
7783
7884 /// Get the object associated to the typed [Id]
0 commit comments