You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: mod.rs
    path of file: ./repos/plane/plane/src/drone/docker
    
    the code of the file until where you have to start completion: use self::{
    commands::{get_port, run_container},
    types::ContainerId,
};
use crate::{
    database::backend::BackendMetricsMessage,
    names::BackendName,
    protocol::AcquiredKey,
    types::{BearerToken, ExecutorConfig},
};
use anyhow::Result;
use bollard::{
    auth::DockerCredentials,
    container::{PruneContainersOptions, StatsOptions},
    errors::Error,
    image::PruneImagesOptions,
    service::{EventMessage, HostConfigLogConfig},
    system::EventsOptions,
    Docker,
};
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use std::sync::atomic::{AtomicU64, Ordering};
use std::{collections::HashMap, path::PathBuf};
use thiserror::Error;
use tokio_stream::{Stream, StreamExt};

pub mod commands;
pub mod types;

/// The label used to identify containers managed by Plane.
/// The existence of this label is used to determine whether a container is managed by Plane.
const PLANE_DOCKER_LABEL: &str = "dev.plane.backend";

#[derive(Clone, Debug, Default, Serialize, Deserialize)]
pub struct PlaneDockerConfig {
    pub runtime: Option<String>,
    pub log_config: Option<HostConfigLogConfig>,
    pub mount_base: Option<PathBuf>,
}

#[derive(Clone, Debug)]
pub struct PlaneDocker {
    docker: Docker,
    config: PlaneDockerConfig,
}

#[derive(Clone, Debug)]
pub struct TerminateEvent {
    pub backend_id: BackendName,
    pub exit_code: Option<i32>,
}

pub struct SpawnResult {
    pub container_id: ContainerId,
    pub port: u16,
}

impl PlaneDocker {
    pub async fn new(docker: Docker, config: PlaneDockerConfig) -> Result<Self> {
        Ok(Self { docker, config })
    }

    pub async fn pull(
        &self,
        image: &str,
        credentials: Option<&DockerCredentials>,
        force: bool,
    ) -> Result<()> {
        commands::pull_image(&self.docker, image, credentials, force).await
    
    pub async fn backend_events(&self) -> impl Stream<Item = TerminateEvent> {
        let options = EventsOptions {
            since: None,
            until: None,
            filters: vec![
                ("type", vec!["container"]),
                ("event", vec!["die", "stop"]),
                ("label", vec![PLANE_DOCKER_LABEL]),
            ]
            .into_iter()
            .collect(),
        };
        self.docker.events(Some(options)).filter_map(|e| {
            let e: EventMessage = match e {
                Err(e) => {
                    tracing::error!(?e, "Error receiving Docker event.");
                    return None;
                }
                Ok(e) => e,
            };

            tracing::info!(event=?e, "Received event");

            let Some(actor) = e.actor else {
                tracing::warn!("Received event without actor.");
                return None;
            };
            let Some(attributes) = actor.attributes else {
                tracing::warn!("Received event without attributes.");
                return None;
            };

            let exit_code = attributes.get("exitCode");
            let exit_code = exit_code.and_then(|s| s.parse::<i32>().ok());
            let Some(backend_id) = attributes.get(PLANE_DOCKER_LABEL) else {
                tracing::warn!(
                    "Ignoring event without Plane backend \
                    ID (this is expected if non-Plane \
                    backends are running on the same Docker instance.)"
                );
                return None;
            };
            let backend_id = match BackendName::try_from(backend_id.to_string()) {
                Ok(backend_id) => backend_id,
                Err(err) => {
                    tracing::warn!(?err, backend_id, "Ignoring event with invalid backend ID.");
                    return None;
                }
            };

            tracing::info!(exit_code, "Received exit code");

            Some(TerminateEvent {
                backend_id,
                exit_code,
            })
        })
    }