stubr 0.6.2

Wiremock implemented in Rust
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
use std::net::{SocketAddr, TcpListener};

pub struct PortAllocator;

impl PortAllocator {
    pub(crate) fn new_binding(port: Option<u16>) -> SocketAddr {
        if let Some(p) = port {
            TcpListener::bind(format!("127.0.0.1:{p}"))
        } else {
            TcpListener::bind("127.0.0.1:0")
        }
        .and_then(|it| it.local_addr())
        .expect("Failed binding stubr recorder to a local port")
    }
}