Struct Uri

Source
pub struct Uri {
    pub scheme: Scheme,
    pub user: Option<String>,
    pub password: Option<String>,
    pub host: Host,
    pub port: Option<u16>,
    pub parameters: Vec<Param>,
    pub headers: HashMap<String, String>,
    pub raw_uri: Option<String>,
}
Expand description

SIP URI components as defined in RFC 3261

Represents a complete SIP URI with all its components. URIs are used throughout the SIP protocol to identify endpoints, proxy servers, redirect servers, and other network elements.

§Structure

A complete SIP URI has the following format: sip:user:password@host:port;uri-parameters?headers

§Examples

use rvoip_sip_core::prelude::*;
use std::str::FromStr;

// Parse a URI from a string
let uri = Uri::from_str("sip:alice@example.com").unwrap();

// Create a URI programmatically
let uri = Uri::sip("example.com")
    .with_user("bob")
    .with_port(5060)
    .with_parameter(Param::transport("tcp"));

// Get components
assert_eq!(uri.scheme.as_str(), "sip");
assert_eq!(uri.username(), Some("bob"));
assert_eq!(uri.port, Some(5060));
assert_eq!(uri.transport(), Some("tcp"));

Fields§

§scheme: Scheme

URI scheme (sip, sips, tel)

§user: Option<String>

User part (optional)

§password: Option<String>

Password (optional, deprecated)

§host: Host

Host (required)

§port: Option<u16>

Port (optional)

§parameters: Vec<Param>

URI parameters (;key=value or ;key)

§headers: HashMap<String, String>

URI headers (?key=value)

§raw_uri: Option<String>

Raw URI string for custom schemes

Implementations§

Source§

impl Uri

Source

pub fn new(scheme: Scheme, host: Host) -> Uri

Create a new URI with the minimum required fields

§Parameters
  • scheme: The URI scheme
  • host: The host part
§Returns

A new URI instance with the given scheme and host

Source

pub fn scheme(&self) -> &Scheme

Returns the scheme of this URI

§Returns

The scheme (e.g., Sip, Sips, Tel)

Source

pub fn host_port(&self) -> String

Returns the host and port (if present) formatted as a string

§Returns

The host and port as a string (e.g., “example.com:5060”)

Source

pub fn sip(host: impl Into<String>) -> Uri

Create a new SIP URI with a domain host

§Parameters
  • host: The domain name
§Returns

A new URI with SIP scheme and the given domain host

§Examples
use rvoip_sip_core::prelude::*;

let uri = Uri::sip("example.com");
assert_eq!(uri.to_string(), "sip:example.com");
Source

pub fn sip_ipv4(host: impl Into<String>) -> Uri

Create a new SIP URI with an IPv4 host

§Parameters
  • host: The IPv4 address as a string
§Returns

A new URI with SIP scheme and the given IPv4 host

§Examples
use rvoip_sip_core::prelude::*;

let uri = Uri::sip_ipv4("192.168.1.1");
assert_eq!(uri.to_string(), "sip:192.168.1.1");
Source

pub fn sip_ipv6(host: impl Into<String>) -> Uri

Create a new SIP URI with an IPv6 host

§Parameters
  • host: The IPv6 address as a string
§Returns

A new URI with SIP scheme and the given IPv6 host

§Examples
use rvoip_sip_core::prelude::*;

let uri = Uri::sip_ipv6("2001:db8::1");
assert_eq!(uri.to_string(), "sip:[2001:db8::1]");
Source

pub fn sips(host: impl Into<String>) -> Uri

Create a new SIPS URI

§Parameters
  • host: The domain name
§Returns

A new URI with SIPS scheme and the given domain host

Source

pub fn tel(number: impl Into<String>) -> Uri

Create a new TEL URI

§Parameters
  • number: The telephone number
§Returns

A new URI with TEL scheme and the given number as host

Source

pub fn http(host: impl Into<String>) -> Uri

Create a new HTTP URI

§Parameters
  • host: The domain name
§Returns

A new URI with HTTP scheme and the given domain host

§Examples
use rvoip_sip_core::prelude::*;

let uri = Uri::http("example.com");
assert_eq!(uri.to_string(), "http:example.com");
Source

pub fn https(host: impl Into<String>) -> Uri

Create a new HTTPS URI

§Parameters
  • host: The domain name
§Returns

A new URI with HTTPS scheme and the given domain host

§Examples
use rvoip_sip_core::prelude::*;

let uri = Uri::https("example.com");
assert_eq!(uri.to_string(), "https:example.com");
Source

pub fn custom(uri_string: impl Into<String>) -> Uri

Create a new URI with a custom scheme by storing the entire URI string This is used for schemes that are not explicitly supported (like http, https) but need to be preserved in the Call-Info header

§Parameters
  • uri_string: The full URI string
§Returns

A new URI with the appropriate scheme and preserved raw string

Source

pub fn is_custom(&self) -> bool

Check if this URI has a custom scheme (non-SIP)

§Returns

true if this is a custom URI, false otherwise

Source

pub fn as_raw_uri(&self) -> Option<&str>

Get the raw URI string if this is a custom URI

§Returns

The raw URI string if this is a custom URI, None otherwise

Source

pub fn username(&self) -> Option<&str>

Get the username part of the URI, if present

§Returns

The username as a string slice, or None if not set

Source

pub fn with_user(self, user: impl Into<String>) -> Uri

Set the user part of the URI

§Parameters
  • user: The user part to set
§Returns

Self for method chaining

Source

pub fn with_password(self, password: impl Into<String>) -> Uri

Set the password part of the URI (deprecated in SIP)

§Parameters
  • password: The password to set
§Returns

Self for method chaining

§Note

Passwords in SIP URIs are deprecated for security reasons, but supported for compatibility.

Source

pub fn with_port(self, port: u16) -> Uri

Set the port part of the URI

§Parameters
  • port: The port number
§Returns

Self for method chaining

Source

pub fn with_parameter(self, param: Param) -> Uri

Add a parameter to the URI

§Parameters
  • param: The parameter to add
§Returns

Self for method chaining

§Examples
use rvoip_sip_core::prelude::*;

let uri = Uri::sip("example.com")
    .with_parameter(Param::transport("tcp"))
    .with_parameter(Param::ttl(60));

assert_eq!(uri.to_string(), "sip:example.com;transport=tcp;ttl=60");
Source

pub fn with_header( self, key: impl Into<String>, value: impl Into<String>, ) -> Uri

Add a header to the URI

§Parameters
  • key: The header name
  • value: The header value
§Returns

Self for method chaining

§Examples
use rvoip_sip_core::prelude::*;

let uri = Uri::sip("example.com")
    .with_header("subject", "Meeting")
    .with_header("priority", "urgent");

// Headers are added to the URI string
let uri_str = uri.to_string();
assert!(uri_str.contains("subject=Meeting"));
assert!(uri_str.contains("priority=urgent"));
Source

pub fn transport(&self) -> Option<&str>

Returns the transport parameter if present

§Returns

The transport value as a string slice, or None if not set

§Examples
use rvoip_sip_core::prelude::*;

let uri = Uri::sip("example.com")
    .with_parameter(Param::transport("tcp"));

assert_eq!(uri.transport(), Some("tcp"));
Source

pub fn is_phone_number(&self) -> bool

Returns the user=phone parameter if present

§Returns

true if the URI has the user=phone parameter, false otherwise

§Examples
use rvoip_sip_core::prelude::*;
use std::str::FromStr;

let uri = Uri::from_str("sip:+12125551212@example.com;user=phone").unwrap();
assert!(uri.is_phone_number());

let uri = Uri::sip("example.com").with_user("alice");
assert!(!uri.is_phone_number());

Trait Implementations§

Source§

impl Clone for Uri

Source§

fn clone(&self) -> Uri

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Uri

Source§

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

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

impl<'de> Deserialize<'de> for Uri

Source§

fn deserialize<__D>( __deserializer: __D, ) -> Result<Uri, <__D as Deserializer<'de>>::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for Uri

Source§

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

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

impl<'a> From<&'a str> for Uri

Source§

fn from(s: &'a str) -> Uri

Converts to this type from the input type.
Source§

impl FromStr for Uri

Source§

type Err = Error

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Uri, Error>

Parses a string s to return a value of this type. Read more
Source§

impl PartialEq for Uri

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Uri

Source§

fn serialize<__S>( &self, __serializer: __S, ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Eq for Uri

Source§

impl StructuralPartialEq for Uri

Auto Trait Implementations§

§

impl Freeze for Uri

§

impl RefUnwindSafe for Uri

§

impl Send for Uri

§

impl Sync for Uri

§

impl Unpin for Uri

§

impl UnwindSafe for Uri

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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. 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> SipJson for T

Source§

fn to_sip_value(&self) -> Result<SipValue, SipJsonError>

Convert this type to a SipValue. Read more
Source§

fn from_sip_value(value: &SipValue) -> Result<T, SipJsonError>

Create this type from a SipValue. Read more
Source§

impl<T> SipJsonExt for T

Source§

fn path(&self, path: impl AsRef<str>) -> Option<SipValue>

Simple path accessor that returns an Option directly

Source§

fn path_str(&self, path: impl AsRef<str>) -> Option<String>

Get a string value at the given path

Source§

fn path_str_or(&self, path: impl AsRef<str>, default: &str) -> String

Get a string value at the given path, or return the default value if not found

Source§

fn to_sip_value(&self) -> Result<SipValue, SipJsonError>

Convert to a SipValue. Read more
Source§

fn from_sip_value(value: &SipValue) -> Result<T, SipJsonError>

Convert from a SipValue. Read more
Source§

fn get_path(&self, path: impl AsRef<str>) -> SipValue

Access a value via path notation (e.g., “headers.from.tag”). Read more
Source§

fn path_accessor(&self) -> PathAccessor

Get a PathAccessor for chained access to fields. Read more
Source§

fn query(&self, query_str: impl AsRef<str>) -> Vec<SipValue>

Query for values using a JSONPath-like syntax. Read more
Source§

fn to_json_string(&self) -> Result<String, SipJsonError>

Convert to a JSON string. Read more
Source§

fn to_json_string_pretty(&self) -> Result<String, SipJsonError>

Convert to a pretty-printed JSON string. Read more
Source§

fn from_json_str(json_str: &str) -> Result<T, SipJsonError>

Create from a JSON string. Read more
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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> SipMessageJson for T
where T: SipJsonExt,