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: swarm.rs
    path of file: ./repos/rust-libp2p/misc/metrics/src
    
    the code of the file until where you have to start completion: // Copyright 2021 Protocol Labs.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
    
    pub(crate) fn new(registry: &mut Registry) -> Self {
        let sub_registry = registry.sub_registry_with_prefix("swarm");

        let connections_incoming = Family::default();
        sub_registry.register(
            "connections_incoming",
            "Number of incoming connections per address stack",
            connections_incoming.clone(),
        );

        let connections_incoming_error = Family::default();
        sub_registry.register(
            "connections_incoming_error",
            "Number of incoming connection errors",
            connections_incoming_error.clone(),
        );

        let new_listen_addr = Family::default();
        sub_registry.register(
            "new_listen_addr",
            "Number of new listen addresses",
            new_listen_addr.clone(),
        );

        let expired_listen_addr = Family::default();
        sub_registry.register(
            "expired_listen_addr",
            "Number of expired listen addresses",
            expired_listen_addr.clone(),
        );

        let external_addr_candidates = Family::default();
        sub_registry.register(
            "external_addr_candidates",
            "Number of new external address candidates",
            external_addr_candidates.clone(),
        );

        let external_addr_confirmed = Family::default();
        sub_registry.register(
            "external_addr_confirmed",
            "Number of confirmed external addresses",
            external_addr_confirmed.clone(),
        );

        let external_addr_expired = Family::default();
        sub_registry.register(
            "external_addr_expired",
            "Number of expired external addresses",
            external_addr_expired.clone(),
        );

        let listener_closed = Family::default();
        sub_registry.register(
            "listener_closed",
            "Number of listeners closed",
            listener_closed.clone(),
        );

        let listener_error = Counter::default();
        sub_registry.register(
            "listener_error",
            "Number of listener errors",
            listener_error.clone(),
        );

        let dial_attempt = Counter::default();
        sub_registry.register(
            "dial_attempt",
            "Number of dial attempts",
            dial_attempt.clone(),
        );

        let outgoing_connection_error = Family::default();
        sub_registry.register(
            "outgoing_connection_error",
            "Number outgoing connection errors",
            outgoing_connection_error.clone(),
        );

        let connections_established = Family::default();
        sub_registry.register(
            "connections_established",
            "Number of connections established",
            connections_established.clone(),
        );

        let connections_establishment_duration = {
            let constructor: fn() -> Histogram =
                || Histogram::new(exponential_buckets(0.01, 1.5, 20));
            Family::new_with_constructor(constructor)
        };
        sub_registry.register(
            "connections_establishment_duration",
            "Time it took (locally) to establish connections",
            connections_establishment_duration.clone(),
        );

        let connections_duration = {
            let constructor: fn() -> Histogram =
                || Histogram::new(exponential_buckets(0.01, 3.0, 20));
            Family::new_with_constructor(constructor)
        };
        sub_registry.register_with_unit(
            "connections_duration",
            "Time a connection was alive",
            Unit::Seconds,
            connections_duration.clone(),
        );

        Self {
            connections_incoming,
            connections_incoming_error,
            connections_established,
            new_listen_addr,
            expired_listen_addr,
            external_addr_candidates,
            external_addr_confirmed,
            external_addr_expired,
            listener_closed,
            listener_error,
            dial_attempt,
            outgoing_connection_error,
            connections_establishment_duration,
            connections_duration,
            connections: Default::default(),
        }
    }