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
impl Uri
Sourcepub fn host_port(&self) -> String
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”)
Sourcepub fn custom(uri_string: impl Into<String>) -> Uri
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
Sourcepub fn is_custom(&self) -> bool
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
Sourcepub fn as_raw_uri(&self) -> Option<&str>
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
Sourcepub fn username(&self) -> Option<&str>
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
Sourcepub fn with_password(self, password: impl Into<String>) -> Uri
pub fn with_password(self, password: impl Into<String>) -> Uri
Sourcepub fn with_parameter(self, param: Param) -> Uri
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");
Sourcepub fn with_header(
self,
key: impl Into<String>,
value: impl Into<String>,
) -> Uri
pub fn with_header( self, key: impl Into<String>, value: impl Into<String>, ) -> Uri
Add a header to the URI
§Parameters
key
: The header namevalue
: 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"));
Sourcepub fn is_phone_number(&self) -> bool
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<'de> Deserialize<'de> for Uri
impl<'de> Deserialize<'de> for Uri
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<Uri, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<Uri, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl Serialize for Uri
impl Serialize for Uri
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
impl Eq for Uri
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> 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
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<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> SipJson for Twhere
T: Serialize + DeserializeOwned,
impl<T> SipJson for Twhere
T: Serialize + DeserializeOwned,
Source§fn to_sip_value(&self) -> Result<SipValue, SipJsonError>
fn to_sip_value(&self) -> Result<SipValue, SipJsonError>
Source§fn from_sip_value(value: &SipValue) -> Result<T, SipJsonError>
fn from_sip_value(value: &SipValue) -> Result<T, SipJsonError>
Source§impl<T> SipJsonExt for T
impl<T> SipJsonExt for T
Source§fn path(&self, path: impl AsRef<str>) -> Option<SipValue>
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>
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
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