podman_client/containers/
stop.rs1use http_body_util::Empty;
2use hyper::body::Bytes;
3use url::form_urlencoded;
4
5use crate::{
6 client::Client,
7 models::{
8 connection::SendRequestOptions, lib::Error, podman::containers::stop::ContainerStopOptions,
9 },
10 utils::bool_to_str::bool_to_str,
11};
12
13impl Client {
14 pub async fn container_stop(&self, options: ContainerStopOptions<'_>) -> Result<(), Error> {
15 let mut path = ["/libpod/containers/", options.name, "/stop"].concat();
16
17 let mut query = form_urlencoded::Serializer::new(String::new());
18 if let Some(ignore) = options.ignore {
19 query.append_pair("Ignore", bool_to_str(ignore));
20 }
21 if let Some(timeout) = options.timeout {
22 query.append_pair("timeout", itoa::Buffer::new().format(timeout));
23 }
24 let query_string = query.finish();
25 if !query_string.is_empty() {
26 path += &["?", &query_string].concat();
27 }
28
29 let (_, data) = self
30 .send_request::<_, (), _>(SendRequestOptions {
31 method: "POST",
32 path: &path,
33 header: None,
34 body: Empty::<Bytes>::new(),
35 })
36 .await?;
37
38 Ok(data)
39 }
40}