File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -70,6 +70,30 @@ impl TryFrom<&str> for CrateScope {
70
70
}
71
71
}
72
72
73
+ impl TryFrom < String > for CrateScope {
74
+ type Error = String ;
75
+
76
+ fn try_from ( pattern : String ) -> Result < Self , Self :: Error > {
77
+ match CrateScope :: is_valid_pattern ( & pattern) {
78
+ true => Ok ( CrateScope { pattern } ) ,
79
+ false => Err ( "Invalid crate scope pattern" . to_string ( ) ) ,
80
+ }
81
+ }
82
+ }
83
+
84
+ impl FromSql < Text , Pg > for CrateScope {
85
+ fn from_sql ( bytes : Option < & [ u8 ] > ) -> deserialize:: Result < Self > {
86
+ let value = <String as FromSql < Text , Pg > >:: from_sql ( bytes) ?;
87
+ Ok ( CrateScope :: try_from ( value) ?)
88
+ }
89
+ }
90
+
91
+ impl ToSql < Text , Pg > for CrateScope {
92
+ fn to_sql < W : Write > ( & self , out : & mut Output < ' _ , W , Pg > ) -> serialize:: Result {
93
+ <String as ToSql < Text , Pg > >:: to_sql ( & self . pattern , out)
94
+ }
95
+ }
96
+
73
97
impl CrateScope {
74
98
fn is_valid_pattern ( pattern : & str ) -> bool {
75
99
if pattern. is_empty ( ) {
You can’t perform that action at this time.
0 commit comments