bee_network/alias.rs
1// Copyright 2020-2021 IOTA Stiftung
2// SPDX-License-Identifier: Apache-2.0
3
4/// A macro that creates a shorter representation of a [`PeerId`](crate::PeerId). Mostly useful in logging scenarios.
5///
6/// **NOTE**: This macro can panic if not used with a valid [`PeerId`](crate::PeerId), or provided with a `len > 52`.
7#[macro_export]
8macro_rules! alias {
9 ($peer_id:expr) => {
10 &$peer_id.to_base58()[46..]
11 };
12 ($peer_id:expr, $len:expr) => {
13 &$peer_id.to_base58()[(52 - $len)..]
14 };
15}