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: current_mapping.rs
    path of file: ./repos/iroh/iroh-net/src/portmapper
    
    the code of the file until where you have to start completion: //! Holds the current mapping value and ensures that any change is reported accordingly.

use std::{
    net::{Ipv4Addr, SocketAddrV4},
    num::NonZeroU16,
    pin::Pin,
    task::Poll,
};

use futures::Future;
use iroh_metrics::inc;
use std::time::Duration;
use tokio::{sync::watch, time};
use tracing::{debug, trace};

/// This is an implementation detail to facilitate testing.
pub(super) trait Mapping: std::fmt::Debug + Unpin {
    fn external(&self) -> (Ipv4Addr, NonZeroU16);
    /// Half the lifetime of a mapping. This is used to calculate when a mapping should be renewed.
    fn half_lifetime(&self) -> Duration;
}

impl Mapping for super::mapping::Mapping {
    fn external(&self) -> (Ipv4Addr, NonZeroU16) {
        super::mapping::PortMapped::external(self)
    }
    fn half_lifetime(&self) -> Duration {
        super::mapping::PortMapped::half_lifetime(self)
    }
}

/// Models the lifetime of an active mapping.
#[derive(Debug)]
struct ActiveMapping<M> {
    mapping: M,
    deadline: Pin<Box<time::Sleep>>,
    expire_after: bool,
}

impl<M: Mapping> ActiveMapping<
    
    fn poll(&mut self, cx: &mut std::task::Context<'_>) -> Poll<Event> {
        // grab the waker if needed
        if let Some(waker) = &self.waker {
            if waker.will_wake(cx.waker()) {
                self.waker = Some(cx.waker().clone());
            }
        } else {
            self.waker = Some(cx.waker().clone());
        }

        // poll the mapping deadlines to keep the state up to date
        if let Some(ActiveMapping {
            mapping,
            deadline,
            expire_after,
        }) = &mut self.mapping
        {
            if deadline.as_mut().poll(cx).is_ready() {
                let (external_ip, external_port) = mapping.external();
                // check if the deadline means the mapping is expired or due for renewal
                return if *expire_after {
                    trace!("mapping expired {mapping:?}");
                    self.update(None);
                    Poll::Ready(Event::Expired {
                        external_ip,
                        external_port,
                    })
                } else {
                    // mapping is due for renewal
                    *deadline = Box::pin(time::sleep(mapping.half_lifetime()));
                    *expire_after = true;
                    trace!("due for renewal {mapping:?}");
                    Poll::Ready(Event::Renew {
                        external_ip,
                        external_port,
                    })
                };
            }
        }
        Poll::Pending
    }