podman_client/networks/
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::networks::prune::{NetworkPrune, NetworkPruneOptions},
13 },
14};
15
16impl Client {
17 pub async fn network_prune(
18 &self,
19 options: Option<NetworkPruneOptions<'_>>,
20 ) -> Result<NetworkPrune, Error> {
21 let mut path = "/libpod/networks/prune".to_owned();
22
23 if let Some(options) = options {
24 if let Some(opt_filters) = options.filters {
25 let mut filters = HashMap::new();
26 if let Some(until) = opt_filters.until {
27 filters.insert("until", until);
28 }
29 if let Some(label) = opt_filters.label {
30 filters.insert("label", label);
31 }
32 if let Some(labelnot) = opt_filters.labelnot {
33 filters.insert("label!", labelnot);
34 }
35 if !filters.is_empty() {
36 let filters_json = serde_json::to_string(&filters)?;
37 let filters_encoded: String = byte_serialize(filters_json.as_bytes()).collect();
38 path += &["?filters=", &filters_encoded].concat();
39 }
40 }
41 }
42
43 let (_, data) = self
44 .send_request::<_, (), _>(SendRequestOptions {
45 method: "POST",
46 path: &path,
47 header: None,
48 body: Empty::<Bytes>::new(),
49 })
50 .await?;
51
52 Ok(data)
53 }
54}