podman_client/volumes/
prune.rs1use std::collections::HashMap;
2
3use http_body_util::Empty;
4use hyper::body::Bytes;
5use url::form_urlencoded::byte_serialize;
6
7use crate::{
8 client::Client,
9 models::{
10 connection::SendRequestOptions,
11 lib::Error,
12 podman::volumes::prune::{VolumePrune, VolumePruneOptions},
13 },
14};
15
16impl Client {
17 pub async fn volume_prune(
18 &self,
19 options: Option<VolumePruneOptions<'_>>,
20 ) -> Result<VolumePrune, Error> {
21 let mut path = "/libpod/volumes/prune".to_owned();
22
23 if let Some(options) = options
24 && let Some(opt_filters) = options.filters
25 {
26 let mut filters = HashMap::new();
27 if let Some(until) = opt_filters.until
28 && !until.is_empty()
29 {
30 filters.insert("until", until);
31 }
32 if let Some(label) = opt_filters.label
33 && !label.is_empty()
34 {
35 filters.insert("label", label);
36 }
37 if let Some(labelnot) = opt_filters.labelnot
38 && !labelnot.is_empty()
39 {
40 filters.insert("label!", labelnot);
41 }
42
43 if !filters.is_empty() {
44 let filters_json = serde_json::to_string(&filters)?;
45 let filters_encoded: String = byte_serialize(filters_json.as_bytes()).collect();
46 path += &["?filters=", &filters_encoded].concat();
47 }
48 }
49
50 let (_, data) = self
51 .send_request::<_, (), _>(SendRequestOptions {
52 method: "POST",
53 path: &path,
54 header: None,
55 body: Empty::<Bytes>::new(),
56 })
57 .await?;
58
59 Ok(data)
60 }
61}