pub struct ClientAddress(/* private fields */);Expand description
A validated client socket address.
This newtype wrapper provides type safety and prevents mixing up client addresses with other socket addresses in the codebase.
§Examples
use std::net::SocketAddr;
use nntp_proxy::types::ClientAddress;
let addr: SocketAddr = "127.0.0.1:8119".parse().unwrap();
let client_addr = ClientAddress::from(addr);
println!("Client connected from: {}", client_addr);Implementations§
Source§impl ClientAddress
impl ClientAddress
Sourcepub const fn new(addr: SocketAddr) -> Self
pub const fn new(addr: SocketAddr) -> Self
Create a new client address from a socket address.
§Examples
use std::net::SocketAddr;
use nntp_proxy::types::ClientAddress;
let addr: SocketAddr = "192.168.1.100:12345".parse().unwrap();
let client_addr = ClientAddress::new(addr);Sourcepub const fn as_socket_addr(&self) -> &SocketAddr
pub const fn as_socket_addr(&self) -> &SocketAddr
Get the underlying socket address.
§Examples
use std::net::SocketAddr;
use nntp_proxy::types::ClientAddress;
let addr: SocketAddr = "10.0.0.5:9999".parse().unwrap();
let client_addr = ClientAddress::from(addr);
assert_eq!(client_addr.as_socket_addr(), &addr);Sourcepub const fn into_inner(self) -> SocketAddr
pub const fn into_inner(self) -> SocketAddr
Convert into the underlying socket address.
§Examples
use std::net::SocketAddr;
use nntp_proxy::types::ClientAddress;
let addr: SocketAddr = "172.16.0.1:5555".parse().unwrap();
let client_addr = ClientAddress::from(addr);
let socket_addr = client_addr.into_inner();
assert_eq!(socket_addr, addr);Sourcepub const fn is_ipv4(&self) -> bool
pub const fn is_ipv4(&self) -> bool
Check if this is an IPv4 address.
§Examples
use nntp_proxy::types::ClientAddress;
use std::net::SocketAddr;
let addr = ClientAddress::from("127.0.0.1:8119".parse::<SocketAddr>().unwrap());
assert!(addr.is_ipv4());
let addr6 = ClientAddress::from("[::1]:8119".parse::<SocketAddr>().unwrap());
assert!(!addr6.is_ipv4());Sourcepub const fn is_ipv6(&self) -> bool
pub const fn is_ipv6(&self) -> bool
Check if this is an IPv6 address.
§Examples
use nntp_proxy::types::ClientAddress;
use std::net::SocketAddr;
let addr = ClientAddress::from("[::1]:8119".parse::<SocketAddr>().unwrap());
assert!(addr.is_ipv6());
let addr4 = ClientAddress::from("127.0.0.1:8119".parse::<SocketAddr>().unwrap());
assert!(!addr4.is_ipv6());Methods from Deref<Target = SocketAddr>§
1.7.0 · Sourcepub fn ip(&self) -> IpAddr
pub fn ip(&self) -> IpAddr
Returns the IP address associated with this socket address.
§Examples
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
let socket = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8080);
assert_eq!(socket.ip(), IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)));1.0.0 · Sourcepub fn port(&self) -> u16
pub fn port(&self) -> u16
Returns the port number associated with this socket address.
§Examples
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
let socket = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8080);
assert_eq!(socket.port(), 8080);1.16.0 · Sourcepub fn is_ipv4(&self) -> bool
pub fn is_ipv4(&self) -> bool
Returns true if the IP address in this SocketAddr is an
IPv4 address, and false otherwise.
§Examples
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
let socket = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 8080);
assert_eq!(socket.is_ipv4(), true);
assert_eq!(socket.is_ipv6(), false);1.16.0 · Sourcepub fn is_ipv6(&self) -> bool
pub fn is_ipv6(&self) -> bool
Returns true if the IP address in this SocketAddr is an
IPv6 address, and false otherwise.
§Examples
use std::net::{IpAddr, Ipv6Addr, SocketAddr};
let socket = SocketAddr::new(IpAddr::V6(Ipv6Addr::new(0, 0, 0, 0, 0, 65535, 0, 1)), 8080);
assert_eq!(socket.is_ipv4(), false);
assert_eq!(socket.is_ipv6(), true);Trait Implementations§
Source§impl AsRef<SocketAddr> for ClientAddress
impl AsRef<SocketAddr> for ClientAddress
Source§fn as_ref(&self) -> &SocketAddr
fn as_ref(&self) -> &SocketAddr
Converts this type into a shared reference of the (usually inferred) input type.
Source§impl Clone for ClientAddress
impl Clone for ClientAddress
Source§fn clone(&self) -> ClientAddress
fn clone(&self) -> ClientAddress
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreimpl Copy for ClientAddress
Source§impl Debug for ClientAddress
impl Debug for ClientAddress
Source§impl Deref for ClientAddress
impl Deref for ClientAddress
Source§impl Display for ClientAddress
impl Display for ClientAddress
impl Eq for ClientAddress
Source§impl From<ClientAddress> for SocketAddr
impl From<ClientAddress> for SocketAddr
Source§fn from(value: ClientAddress) -> Self
fn from(value: ClientAddress) -> Self
Converts to this type from the input type.
Source§impl From<SocketAddr> for ClientAddress
impl From<SocketAddr> for ClientAddress
Source§fn from(value: SocketAddr) -> Self
fn from(value: SocketAddr) -> Self
Converts to this type from the input type.
Source§impl Hash for ClientAddress
impl Hash for ClientAddress
Source§impl PartialEq for ClientAddress
impl PartialEq for ClientAddress
impl StructuralPartialEq for ClientAddress
Auto Trait Implementations§
impl Freeze for ClientAddress
impl RefUnwindSafe for ClientAddress
impl Send for ClientAddress
impl Sync for ClientAddress
impl Unpin for ClientAddress
impl UnsafeUnpin for ClientAddress
impl UnwindSafe for ClientAddress
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreimpl<T> Key for T
Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> ToCompactString for Twhere
T: Display,
impl<T> ToCompactString for Twhere
T: Display,
Source§fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
Fallible version of
ToCompactString::to_compact_string() Read moreSource§fn to_compact_string(&self) -> CompactString
fn to_compact_string(&self) -> CompactString
Converts the given value to a
CompactString. Read more