Enum Method

Source
pub enum Method {
Show 15 variants Invite, Ack, Bye, Cancel, Register, Options, Subscribe, Notify, Update, Refer, Info, Message, Prack, Publish, Extension(String),
}
Expand description

SIP request methods as defined in RFC 3261 and extensions

This enum represents the standard SIP methods defined in RFC 3261 and common extensions. It also supports custom extension methods through the Extension variant.

Each method has specific semantics in the SIP protocol:

  • Some methods can establish dialogs (e.g., INVITE, SUBSCRIBE)
  • Some methods require responses (most methods except ACK and CANCEL)
  • Some methods are defined in the core specification, while others are extensions

§Examples

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

// Core methods
let invite = Method::Invite;
let register = Method::Register;

// Extension methods
let subscribe = Method::Subscribe;
let message = Method::Message;

// Custom extension method
let custom = Method::Extension("CUSTOM".to_string());

// Converting to string
assert_eq!(invite.to_string(), "INVITE");
assert_eq!(custom.to_string(), "CUSTOM");

// Parsing from string
assert_eq!(Method::from_str("BYE").unwrap(), Method::Bye);

Variants§

§

Invite

INVITE: Initiates a session

§

Ack

ACK: Confirms a final response to an INVITE

§

Bye

BYE: Terminates a session

§

Cancel

CANCEL: Cancels a pending request

§

Register

REGISTER: Registers contact information

§

Options

OPTIONS: Queries capabilities

§

Subscribe

SUBSCRIBE: Requests notification of an event

§

Notify

NOTIFY: Sends notification of an event

§

Update

UPDATE: Modifies state of a session without changing dialog state

§

Refer

REFER: Asks recipient to issue a request

§

Info

INFO: Sends mid-session information

§

Message

MESSAGE: Transports instant messages

§

Prack

PRACK: Provisional acknowledgment

§

Publish

PUBLISH: Publishes event state

§

Extension(String)

Custom extension method

Implementations§

Source§

impl Method

Source

pub fn creates_dialog(&self) -> bool

Returns true if the method can establish a dialog

In SIP, only certain methods can create dialogs between user agents. The primary methods that establish dialogs are INVITE and SUBSCRIBE.

§Returns

true if the method can create a dialog, false otherwise

§Examples
use rvoip_sip_core::prelude::*;

// Methods that create dialogs
assert!(Method::Invite.creates_dialog());
assert!(Method::Subscribe.creates_dialog());

// Methods that don't create dialogs
assert!(!Method::Register.creates_dialog());
assert!(!Method::Message.creates_dialog());
assert!(!Method::Extension("CUSTOM".to_string()).creates_dialog());
Source

pub fn requires_response(&self) -> bool

Returns true if the method requires a response

Most SIP methods require a response, but there are exceptions. ACK and CANCEL are special methods that do not require responses according to the SIP specification.

§Returns

true if the method requires a response, false otherwise

§Examples
use rvoip_sip_core::prelude::*;

// Methods that require responses
assert!(Method::Invite.requires_response());
assert!(Method::Register.requires_response());
assert!(Method::Subscribe.requires_response());

// Methods that don't require responses
assert!(!Method::Ack.requires_response());
assert!(!Method::Cancel.requires_response());
Source

pub fn is_standard(&self) -> bool

Returns true if the method is standardized (not an extension)

This method distinguishes between methods defined in the SIP specifications and custom extension methods. It returns true for all enum variants except Method::Extension.

§Returns

true if the method is a standard SIP method, false for custom extensions

§Examples
use rvoip_sip_core::prelude::*;

// Standard methods
assert!(Method::Invite.is_standard());
assert!(Method::Register.is_standard());
assert!(Method::Subscribe.is_standard());

// Custom extension
assert!(!Method::Extension("CUSTOM".to_string()).is_standard());
Source

pub fn as_str(&self) -> &str

Converts the method to its string representation

Returns the canonical string representation of the SIP method. For standard methods, this is the uppercase name as defined in the SIP specifications. For extension methods, it’s the string stored in the Extension variant.

§Returns

A string slice representing the method

§Examples
use rvoip_sip_core::prelude::*;

assert_eq!(Method::Invite.as_str(), "INVITE");
assert_eq!(Method::Ack.as_str(), "ACK");
assert_eq!(Method::Register.as_str(), "REGISTER");

let custom = Method::Extension("CUSTOM".to_string());
assert_eq!(custom.as_str(), "CUSTOM");

Trait Implementations§

Source§

impl Clone for Method

Source§

fn clone(&self) -> Method

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 Method

Source§

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

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

impl<'de> Deserialize<'de> for Method

Source§

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

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

impl Display for Method

Source§

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

Formats the Method as a string.

This implementation uses as_str() to convert the method to its string representation.

§Examples
use rvoip_sip_core::prelude::*;

assert_eq!(Method::Invite.to_string(), "INVITE");
assert_eq!(Method::Register.to_string(), "REGISTER");

// In a formatted string
let method = Method::Invite;
let formatted = format!("SIP method: {}", method);
assert_eq!(formatted, "SIP method: INVITE");
Source§

impl FromStr for Method

Source§

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

Parses a string into a Method.

This method converts a string to the corresponding Method enum variant. It recognizes all standard SIP methods defined in RFC 3261 and common extensions. If the string doesn’t match any standard method but is not empty, it creates a Method::Extension variant with the string.

§Parameters
  • s: The string to parse
§Returns

A Result containing the parsed Method, or an error if parsing fails

§Errors

Returns Error::InvalidMethod if the input string is empty.

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

// Standard methods
assert_eq!(Method::from_str("INVITE").unwrap(), Method::Invite);
assert_eq!(Method::from_str("BYE").unwrap(), Method::Bye);

// Extension method
let custom = Method::from_str("CUSTOM").unwrap();
assert!(matches!(custom, Method::Extension(s) if s == "CUSTOM"));

// Error case
assert!(Method::from_str("").is_err());
Source§

type Err = Error

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

impl Hash for Method

Source§

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

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 PartialEq for Method

Source§

fn eq(&self, other: &Method) -> 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 Method

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 Method

Source§

impl StructuralPartialEq for Method

Auto Trait Implementations§

§

impl Freeze for Method

§

impl RefUnwindSafe for Method

§

impl Send for Method

§

impl Sync for Method

§

impl Unpin for Method

§

impl UnwindSafe for Method

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,