Skip to main content

ServerAddress

Struct ServerAddress 

Source
pub struct ServerAddress { /* private fields */ }
Expand description

The address of a Lightstreamer server, parsed and checked at construction.

A Lightstreamer server is reached at a host and port, and this crate speaks to it over a WebSocket. Both spellings are accepted, because deployments publish their endpoint either way:

You writeMeaning
wss://push.example.comWebSocket over TLS
https://push.example.comthe same thing
ws://localhost:8080WebSocket, no TLS
http://localhost:8080the same thing
wss://[::1]:8080an IPv6 literal, which must be bracketed

§What an address may and may not contain

The address is a scheme, a host and an optional port, optionally followed by a base path. Everything else is refused here rather than somewhere further down, where the failure would be a connection error instead of a configuration one:

RejectedWhy
wss://user:secret@hostuserinfo is a credential, and a credential in an address ends up in every log line that mentions the address
wss://host?a=b, wss://host#fTLCP defines no query or fragment on the endpoint; carrying one would silently change what is requested
wss://host/a/../ba .. segment makes the composed endpoint depend on path normalisation this crate does not perform
wss://host:0, wss://host:99999not a port
wss:// hostnot a host

§The endpoint path

The TLCP endpoint path is not part of the address: this crate appends the /lightstreamer path the protocol fixes [docs/spec/01-foundations.md §6.2.1]. An address that already ends in /lightstreamer is accepted and not doubled. A base path is accepted too, for a server published behind a reverse proxy, and the fixed path is appended to it — https://example.com/push reaches /push/lightstreamer.

§Canonical form

ServerAddress::as_str returns the address with the scheme lowercased and any trailing / removed; the host is left in the caller’s own spelling. Because userinfo is refused, the canonical form is also the redacted form: it is safe to log.

§Examples

use lightstreamer_rs::ServerAddress;

let address = ServerAddress::try_new("https://push.lightstreamer.com")?;
assert!(address.is_secure());

A missing scheme is rejected rather than guessed at, because guessing https for an address the caller meant as plain http would silently change the security properties of the connection:

use lightstreamer_rs::ServerAddress;

assert!(ServerAddress::try_new("push.lightstreamer.com").is_err());

Implementations§

Source§

impl ServerAddress

Source

pub fn try_new(address: impl Into<String>) -> Result<Self, ConfigError>

Parses and checks a server address.

§Errors
§Examples
use lightstreamer_rs::{ConfigError, ServerAddress};

assert!(matches!(
    ServerAddress::try_new("ftp://push.example.com"),
    Err(ConfigError::UnsupportedScheme { .. })
));

// A credential in an address would reach every log line that mentions it.
assert!(matches!(
    ServerAddress::try_new("wss://alice:hunter2@push.example.com"),
    Err(ConfigError::AddressHasUserinfo)
));
Source

pub fn as_str(&self) -> &str

The address in canonical form: scheme lowercased, no trailing /, and nothing in it that needs redacting.

Source

pub const fn is_secure(&self) -> bool

Whether the connection will be encrypted.

True for the wss and https schemes, false for ws and http.

Trait Implementations§

Source§

impl Clone for ServerAddress

Source§

fn clone(&self) -> ServerAddress

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ServerAddress

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for ServerAddress

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for ServerAddress

Source§

impl Hash for ServerAddress

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for ServerAddress

Source§

fn cmp(&self, other: &ServerAddress) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for ServerAddress

Source§

fn eq(&self, other: &ServerAddress) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl PartialOrd for ServerAddress

Source§

fn partial_cmp(&self, other: &ServerAddress) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl StructuralPartialEq for ServerAddress

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more