summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/lib.rs24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 45a3838..a011396 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -635,6 +635,11 @@ impl<'docker> Containers<'docker> {
}
/// Returns a reference to a set of operations available to a specific container instance
+ ///
+ /// # Warning
+ ///
+ /// This function does not check whether the container with `name` actually exists and returns
+ /// a potentially invalid handle.
pub fn get<S>(
&self,
name: S,
@@ -645,6 +650,25 @@ impl<'docker> Containers<'docker> {
Container::new(self.docker, name)
}
+ /// Same as `Container::get()`, but checks whether the container exists and returns None if it
+ /// doesn't
+ pub async fn get_checked<S>(
+ &self,
+ name: S,
+ ) -> Result<Option<Container<'docker>>>
+ where
+ S: AsRef<str>,
+ {
+ let listopts = ContainerListOptions::builder().all().build();
+ self.list(&listopts)
+ .await?
+ .into_iter()
+ .find(|rep| rep.id == name.as_ref())
+ .map(|rep| Container::new(self.docker, rep.id))
+ .map(Ok)
+ .transpose()
+ }
+
/// Returns a builder interface for creating a new container instance
pub async fn create(
&self,