m/cup
1
0
mirror of https://github.com/sergi0g/cup.git synced 2025-11-17 01:23:39 -05:00

Remove used async keyword from 2 functions in Image

This commit is contained in:
Sergio
2024-12-05 20:23:07 +02:00
parent 215e88ae0f
commit 6a77b85141
3 changed files with 12 additions and 23 deletions

View File

@@ -24,13 +24,12 @@ pub async fn get_updates(references: &Option<Vec<String>>, config: &Config) -> V
.iter() .iter()
.filter(|&reference| !image_refs.contains(reference)) .filter(|&reference| !image_refs.contains(reference))
.collect::<Vec<&String>>(); .collect::<Vec<&String>>();
let mut handles = Vec::with_capacity(extra.len()); Some(
extra
for reference in extra { .iter()
let future = Image::from_reference(reference); .map(|reference| Image::from_reference(reference))
handles.push(future) .collect::<Vec<Image>>(),
} )
Some(join_all(handles).await)
} }
None => None, None => None,
}; };

View File

@@ -41,14 +41,9 @@ pub async fn get_images_from_docker_daemon(
.filter(|inspect| inspect.is_ok()) .filter(|inspect| inspect.is_ok())
.map(|inspect| inspect.as_ref().unwrap().clone()) .map(|inspect| inspect.as_ref().unwrap().clone())
.collect(); .collect();
let mut image_handles = Vec::with_capacity(inspects.len()); inspects
for inspect in inspects {
image_handles.push(Image::from_inspect_data(inspect));
}
join_all(image_handles)
.await
.iter() .iter()
.filter_map(|img| img.clone()) .filter_map(|inspect| Image::from_inspect_data(inspect.clone()))
.collect() .collect()
} }
None => { None => {
@@ -58,14 +53,9 @@ pub async fn get_images_from_docker_daemon(
error!("Failed to retrieve list of images available!\n{}", e) error!("Failed to retrieve list of images available!\n{}", e)
} }
}; };
let mut handles = Vec::new(); images
for image in images {
handles.push(Image::from_inspect_data(image))
}
join_all(handles)
.await
.iter() .iter()
.filter_map(|img| img.clone()) .filter_map(|image| Image::from_inspect_data(image.clone()))
.collect() .collect()
} }
} }

View File

@@ -42,7 +42,7 @@ pub struct Image {
impl Image { impl Image {
/// Creates and populates the fields of an Image object based on the ImageSummary from the Docker daemon /// Creates and populates the fields of an Image object based on the ImageSummary from the Docker daemon
pub async fn from_inspect_data<T: InspectData>(image: T) -> Option<Self> { pub fn from_inspect_data<T: InspectData>(image: T) -> Option<Self> {
let tags = image.tags().unwrap(); let tags = image.tags().unwrap();
let digests = image.digests().unwrap(); let digests = image.digests().unwrap();
if !tags.is_empty() && !digests.is_empty() { if !tags.is_empty() && !digests.is_empty() {
@@ -74,7 +74,7 @@ impl Image {
} }
/// Creates and populates the fields of an Image object based on a reference. If the tag is not recognized as a version string, exits the program with an error. /// Creates and populates the fields of an Image object based on a reference. If the tag is not recognized as a version string, exits the program with an error.
pub async fn from_reference(reference: &str) -> Self { pub fn from_reference(reference: &str) -> Self {
let (registry, repository, tag) = split(reference); let (registry, repository, tag) = split(reference);
let version_tag = Version::from_tag(&tag); let version_tag = Version::from_tag(&tag);
match version_tag { match version_tag {