@@ -138,6 +138,22 @@ impl FromStr for DockerImage {
138
138
}
139
139
}
140
140
141
+ impl TryFrom < String > for DockerImage {
142
+ type Error = DockerImageError ;
143
+
144
+ fn try_from ( value : String ) -> Result < Self , Self :: Error > {
145
+ value. parse ( )
146
+ }
147
+ }
148
+
149
+ impl TryFrom < & str > for DockerImage {
150
+ type Error = DockerImageError ;
151
+
152
+ fn try_from ( value : & str ) -> Result < Self , Self :: Error > {
153
+ value. parse ( )
154
+ }
155
+ }
156
+
141
157
impl DockerImage {
142
158
/// Parses a Docker image string into its structured components.
143
159
///
@@ -160,7 +176,7 @@ impl DockerImage {
160
176
impl serde:: Serialize for DockerImage {
161
177
fn serialize < S > ( & self , serializer : S ) -> Result < S :: Ok , S :: Error >
162
178
where
163
- S : serde:: ser:: Serializer
179
+ S : serde:: ser:: Serializer ,
164
180
{
165
181
serializer. serialize_str ( & self . to_string ( ) )
166
182
}
@@ -170,12 +186,10 @@ impl serde::Serialize for DockerImage {
170
186
impl < ' de > serde:: Deserialize < ' de > for DockerImage {
171
187
fn deserialize < D > ( deserializer : D ) -> Result < Self , D :: Error >
172
188
where
173
- D : serde:: de:: Deserializer < ' de >
189
+ D : serde:: de:: Deserializer < ' de > ,
174
190
{
175
191
let docker_image_str = <String as serde:: Deserialize >:: deserialize ( deserializer) ?;
176
- docker_image_str
177
- . parse ( )
178
- . map_err ( serde:: de:: Error :: custom)
192
+ docker_image_str. parse ( ) . map_err ( serde:: de:: Error :: custom)
179
193
}
180
194
}
181
195
@@ -500,7 +514,6 @@ mod tests {
500
514
) ;
501
515
}
502
516
503
-
504
517
#[ test]
505
518
#[ cfg( feature = "serde-serialize" ) ]
506
519
fn test_serialize_dockerimage_to_json ( ) {
@@ -511,7 +524,8 @@ mod tests {
511
524
name : "library/image-name" . to_string ( ) ,
512
525
tag : Some ( "v1.0.0" . to_string ( ) ) ,
513
526
digest : Some (
514
- "sha256:deadbeefcafe1234567890abcdef1234567890abcdef1234567890abcdef1234" . to_string ( ) ,
527
+ "sha256:deadbeefcafe1234567890abcdef1234567890abcdef1234567890abcdef1234"
528
+ . to_string ( ) ,
515
529
) ,
516
530
} ;
517
531
@@ -538,7 +552,8 @@ mod tests {
538
552
name: "library/image-name" . to_string( ) ,
539
553
tag: Some ( "v1.0.0" . to_string( ) ) ,
540
554
digest: Some (
541
- "sha256:deadbeefcafe1234567890abcdef1234567890abcdef1234567890abcdef1234" . to_string( )
555
+ "sha256:deadbeefcafe1234567890abcdef1234567890abcdef1234567890abcdef1234"
556
+ . to_string( )
542
557
) ,
543
558
}
544
559
) ;
0 commit comments