1use std::{collections::HashMap, io::Read};
2use Container;
3use Image;
4
5pub trait Docker
7where
8 Self: Sized,
9{
10 fn run<I: Image>(&self, image: I) -> Container<Self, I>;
11 fn logs(&self, id: &str) -> Logs;
12 fn ports(&self, id: &str) -> Ports;
13 fn rm(&self, id: &str);
14 fn stop(&self, id: &str);
15}
16
17#[derive(Debug, PartialEq, Default)]
19pub struct Ports {
20 mapping: HashMap<u32, u32>,
21}
22
23impl Ports {
24 pub fn add_mapping(&mut self, internal: u32, host: u32) -> &mut Self {
26 debug!("Registering port mapping: {} -> {}", internal, host);
27
28 self.mapping.insert(internal, host);
29
30 self
31 }
32
33 pub fn map_to_host_port(&self, internal_port: u32) -> Option<u32> {
35 self.mapping.get(&internal_port).map(|p| p.clone())
36 }
37}
38
39#[derive(DebugStub)]
41pub struct Logs {
42 #[debug_stub = "stream"]
43 pub stdout: Box<Read>,
44 #[debug_stub = "stream"]
45 pub stderr: Box<Read>,
46}