Skip to main content

ftth_rsip/common/uri/param/
received.rs

1use rsip_derives::{IntoParam, NewType};
2use std::net::IpAddr;
3
4/// Simple NewType around String. Intended to be used for the `received` parameter found in the `Via`
5/// header.
6#[derive(NewType, IntoParam, Debug, PartialEq, Eq, Clone)]
7pub struct Received(String);
8
9impl Received {
10    pub fn parse(&self) -> Result<IpAddr, std::net::AddrParseError> {
11        self.0.parse()
12    }
13}
14
15#[cfg(feature = "test-utils")]
16impl testing_utils::Randomize for Received {
17    fn random() -> Self {
18        Self(std::net::IpAddr::random().to_string())
19    }
20}