pub struct ServiceBinding { /* private fields */ }Expand description
Represents a network service binding, encapsulating protocol and socket address.
This struct is used to define how a service binds to a network interface and port.
It’s an URL without path and some restrictions:
- Only some schemes are accepted:
udp,http,https. - The port number must be greater than zero. The service should be already listening on that port.
- The authority part of the URL must be a valid socket address (wildcard is accepted).
Besides it accepts some non well-formed URLs, like:http://127.0.0.1:7070 or https://127.0.0.1:7070. Those URLs are not valid because they use non standard ports (80 and 443).
NOTICE: It does not represent a public valid URL clients can connect to. It represents the service’s internal URL configuration after assigning a port. If the port in the configuration is not zero, it’s basically the same information you get from the configuration (binding address + protocol).
§Examples
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
use torrust_net_primitives::service_binding::{ServiceBinding, Protocol};
let service_binding = ServiceBinding::new(Protocol::HTTP, SocketAddr::new(IpAddr::V4(Ipv4Addr::LOCALHOST), 7070)).unwrap();
assert_eq!(service_binding.url().to_string(), "http://127.0.0.1:7070/".to_string());Implementations§
Source§impl ServiceBinding
impl ServiceBinding
Sourcepub fn new(protocol: Protocol, bind_address: SocketAddr) -> Result<Self, Error>
pub fn new(protocol: Protocol, bind_address: SocketAddr) -> Result<Self, Error>
§Errors
This function will return an error if the port number is zero.
pub fn bind_address(&self) -> SocketAddr
pub fn bind_address_ip_type(&self) -> IpType
pub fn bind_address_ip_family(&self) -> IpFamily
Trait Implementations§
Source§impl Clone for ServiceBinding
impl Clone for ServiceBinding
Source§fn clone(&self) -> ServiceBinding
fn clone(&self) -> ServiceBinding
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 moreSource§impl Debug for ServiceBinding
impl Debug for ServiceBinding
Source§impl<'de> Deserialize<'de> for ServiceBinding
impl<'de> Deserialize<'de> for ServiceBinding
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl Display for ServiceBinding
impl Display for ServiceBinding
impl Eq for ServiceBinding
Source§impl From<ServiceBinding> for Url
impl From<ServiceBinding> for Url
Source§fn from(service_binding: ServiceBinding) -> Self
fn from(service_binding: ServiceBinding) -> Self
Converts to this type from the input type.
Source§impl Hash for ServiceBinding
impl Hash for ServiceBinding
Source§impl PartialEq for ServiceBinding
impl PartialEq for ServiceBinding
Source§fn eq(&self, other: &ServiceBinding) -> bool
fn eq(&self, other: &ServiceBinding) -> bool
Tests for
self and other values to be equal, and is used by ==.Source§impl Serialize for ServiceBinding
impl Serialize for ServiceBinding
impl StructuralPartialEq for ServiceBinding
Auto Trait Implementations§
impl Freeze for ServiceBinding
impl RefUnwindSafe for ServiceBinding
impl Send for ServiceBinding
impl Sync for ServiceBinding
impl Unpin for ServiceBinding
impl UnsafeUnpin for ServiceBinding
impl UnwindSafe for ServiceBinding
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