@@ -36,62 +36,39 @@ struct RhsmFacts {
3636 available_digest : String ,
3737}
3838
39+ /// Return the image reference, version and digest as owned strings.
40+ /// A missing version is serialized as the empty string.
41+ fn status_to_strings ( imagestatus : & crate :: spec:: ImageStatus ) -> ( String , String , String ) {
42+ let image = imagestatus. image . image . clone ( ) ;
43+ let version = imagestatus. version . as_ref ( ) . cloned ( ) . unwrap_or_default ( ) ;
44+ let digest = imagestatus. image_digest . clone ( ) ;
45+ ( image, version, digest)
46+ }
47+
3948impl From < crate :: spec:: HostStatus > for RhsmFacts {
4049 fn from ( hoststatus : crate :: spec:: HostStatus ) -> Self {
4150 let ( booted_image, booted_version, booted_digest) = hoststatus
4251 . booted
4352 . as_ref ( )
44- . and_then ( |boot_entry| {
45- boot_entry. image . as_ref ( ) . map ( |imagestatus| {
46- let image = imagestatus. image . image . clone ( ) ;
47- let version = imagestatus. version . as_ref ( ) . cloned ( ) . unwrap_or_default ( ) ;
48- let digest = imagestatus. image_digest . clone ( ) ;
49-
50- ( image, version, digest)
51- } )
52- } )
53+ . and_then ( |boot_entry| boot_entry. image . as_ref ( ) . map ( status_to_strings) )
5354 . unwrap_or_default ( ) ;
5455
5556 let ( staged_image, staged_version, staged_digest) = hoststatus
5657 . staged
5758 . as_ref ( )
58- . and_then ( |boot_entry| {
59- boot_entry. image . as_ref ( ) . map ( |imagestatus| {
60- let image = imagestatus. image . image . clone ( ) ;
61- let version = imagestatus. version . as_ref ( ) . cloned ( ) . unwrap_or_default ( ) ;
62- let digest = imagestatus. image_digest . clone ( ) ;
63-
64- ( image, version, digest)
65- } )
66- } )
59+ . and_then ( |boot_entry| boot_entry. image . as_ref ( ) . map ( status_to_strings) )
6760 . unwrap_or_default ( ) ;
6861
6962 let ( rollback_image, rollback_version, rollback_digest) = hoststatus
7063 . rollback
7164 . as_ref ( )
72- . and_then ( |boot_entry| {
73- boot_entry. image . as_ref ( ) . map ( |imagestatus| {
74- let image = imagestatus. image . image . clone ( ) ;
75- let version = imagestatus. version . as_ref ( ) . cloned ( ) . unwrap_or_default ( ) ;
76- let digest = imagestatus. image_digest . clone ( ) ;
77-
78- ( image, version, digest)
79- } )
80- } )
65+ . and_then ( |boot_entry| boot_entry. image . as_ref ( ) . map ( status_to_strings) )
8166 . unwrap_or_default ( ) ;
8267
8368 let ( available_image, available_version, available_digest) = hoststatus
8469 . booted
8570 . as_ref ( )
86- . and_then ( |boot_entry| {
87- boot_entry. cached_update . as_ref ( ) . map ( |imagestatus| {
88- let image = imagestatus. image . image . clone ( ) ;
89- let version = imagestatus. version . as_ref ( ) . cloned ( ) . unwrap_or_default ( ) ;
90- let digest = imagestatus. image_digest . clone ( ) ;
91-
92- ( image, version, digest)
93- } )
94- } )
71+ . and_then ( |boot_entry| boot_entry. cached_update . as_ref ( ) . map ( status_to_strings) )
9572 . unwrap_or_default ( ) ;
9673
9774 Self {
0 commit comments