Preview of the proposed up-rust native-frame-model branch (up-rust b6b99c6d, up-spec f0e9b17) — not released documentation. branch · write-up

Struct UUri

Source
#[repr(C)]
pub struct UUri { /* private fields */ }
Expand description

A URI that represents a uProtocol resource identifier.

Implementations§

Source§

impl UUri

Source

pub fn to_uri(&self, include_scheme: bool) -> String

Serializes this UUri to a URI string.

§Arguments
  • include_scheme - Indicates whether to include the uProtocol scheme (up) in the URI.
§Returns

The URI as defined by the uProtocol Specification.

§Examples
use up_rust::UUri;

let uuri = UUri::try_from_parts("vin.vehicles", 0x0000_800A, 0x02, 0x1a50).unwrap();
let uri_string = uuri.to_uri(true);
assert_eq!(uri_string, "up://vin.vehicles/800A/2/1A50");
Source

pub fn try_from_parts( authority: &str, entity_id: u32, entity_version: u8, resource_id: u16, ) -> Result<Self, UUriError>

Creates a new UUri from its parts.

§Errors

Returns a UUriError::ValidationError if the authority does not comply with the UUri specification.

§Examples
use up_rust::UUri;

assert!(UUri::try_from_parts("vin", 0x0000_5a6b, 0x01, 0x0001).is_ok());
Source

pub fn any() -> Self

Gets a pattern URI that matches any given candidate URI.

Source

pub fn any_with_resource_id(resource_id: u16) -> Self

Gets a pattern URI that matches any given candidate URI with a specific resource ID.

Source

pub fn authority_name(&self) -> &str

Gets the authority name part from this uProtocol URI.

§Examples
use up_rust::UUri;

let uri = UUri::try_from_parts("my-vehicle", 0x10101234, 0x01, 0x9a10).unwrap();
assert_eq!(uri.authority_name(), "my-vehicle");
Source

pub fn uentity_type_id(&self) -> u16

§Examples
use up_rust::UUri;

let uri = UUri::try_from_parts("my-vehicle", 0x10101234, 0x01, 0x9a10).unwrap();
assert_eq!(uri.uentity_type_id(), 0x1234);
Source

pub fn uentity_instance_id(&self) -> u16

§Examples
use up_rust::UUri;

let uri = UUri::try_from_parts("my-vehicle", 0x10101234, 0x01, 0x9a10).unwrap();
assert_eq!(uri.uentity_instance_id(), 0x1010);
Source

pub fn uentity_major_version(&self) -> u8

§Examples
use up_rust::UUri;

let uri = UUri::try_from_parts("my-vehicle", 0x10101234, 0x01, 0x9a10).unwrap();
assert_eq!(uri.uentity_major_version(), 0x01);
Source

pub fn resource_id(&self) -> u16

§Examples
use up_rust::UUri;

let uri = UUri::try_from_parts("my-vehicle", 0x10101234, 0x01, 0x9a10).unwrap();
assert_eq!(uri.resource_id(), 0x9a10);
Source

pub fn clone_with_resource_id(&self, resource_id: u16) -> Self

Returns a copy of this URI with the resource id replaced.

Source

pub fn verify_authority(authority: &str) -> Result<(), UUriError>

Verifies that the given authority name complies with the UUri specification.

§Arguments
  • authority - The authority name to verify.
§Errors

Returns an error if the authority name is invalid.

§Examples
use up_rust::UUri;

assert!(UUri::verify_authority("my.vin").is_ok());
Source

pub fn is_remote(&self, other_uri: &UUri) -> bool

Check if an UUri is remote, by comparing authority fields. UUris with empty authority are considered to be local.

§Returns

‘true’ if other_uri has a different authority than Self, false otherwise.

§Examples
use std::str::FromStr;
use up_rust::UUri;

let authority_a = UUri::from_str("up://authority.a/100A/1/0").unwrap();
let authority_b = UUri::from_str("up://authority.b/200B/2/20").unwrap();
assert!(authority_a.is_remote(&authority_b));

let authority_local = UUri::from_str("up:///100A/1/0").unwrap();
assert!(!authority_local.is_remote(&authority_a));

let authority_wildcard = UUri::from_str("up://*/100A/1/0").unwrap();
assert!(!authority_wildcard.is_remote(&authority_a));
assert!(!authority_a.is_remote(&authority_wildcard));
assert!(!authority_wildcard.is_remote(&authority_wildcard));
Source

pub fn is_remote_authority(&self, authority: &str) -> bool

Check if an authority is remote compared to the authority field of the UUri. Empty authorities are considered to be local.

§Returns

‘true’ if authority is a different than Self.authority_name, false otherwise.

§Examples
use std::str::FromStr;
use up_rust::UUri;

let authority_a = UUri::from_str("up://authority.a/100A/1/0").unwrap();
let authority_b = "authority.b";
assert!(authority_a.is_remote_authority(&authority_b));

let authority_local = "";
assert!(!authority_a.is_remote_authority(&authority_local));

let authority_wildcard = "*";
assert!(!authority_a.is_remote_authority(&authority_wildcard));
Source

pub fn has_empty_authority(&self) -> bool

Checks if this UUri has an empty authority name.

§Examples
use up_rust::UUri;

let uuri = UUri::try_from_parts("", 0x9b3a, 0x01, 0x145b).unwrap();
assert!(uuri.has_empty_authority());
Source

pub fn has_wildcard_authority(&self) -> bool

Checks if this UUri has a wildcard authority name.

§Examples
use up_rust::UUri;

let uuri = UUri::try_from_parts("*", 0x9b3a, 0x01, 0x145b).unwrap();
assert!(uuri.has_wildcard_authority());
Source

pub fn has_wildcard_entity_instance(&self) -> bool

Checks if this UUri has an entity identifier matching any instance.

§Examples
use up_rust::UUri;

let uuri = UUri::try_from_parts("vin", 0xFFFF_0123, 0x01, 0x145b).unwrap();
assert!(uuri.has_wildcard_entity_instance());
Source

pub fn has_wildcard_entity_type(&self) -> bool

Checks if this UUri has an entity identifier matching any type.

§Examples
use up_rust::UUri;

let uuri = UUri::try_from_parts("vin", 0x00C0_FFFF, 0x01, 0x145b).unwrap();
assert!(uuri.has_wildcard_entity_type());
Source

pub fn has_wildcard_version(&self) -> bool

Checks if this UUri has a wildcard major version.

§Examples
use up_rust::UUri;

let uuri = UUri::try_from_parts("vin", 0x9b3a, 0xFF, 0x145b).unwrap();
assert!(uuri.has_wildcard_version());
Source

pub fn has_wildcard_resource_id(&self) -> bool

Checks if this UUri has a wildcard entity identifier.

§Examples
use up_rust::UUri;

let uuri = UUri::try_from_parts("vin", 0x9b3a, 0x01, 0xFFFF).unwrap();
assert!(uuri.has_wildcard_resource_id());
Source

pub fn verify_no_wildcards(&self) -> Result<(), UUriError>

Verifies that this UUri does not contain any wildcards.

§Errors

Returns an error if any of this UUri’s properties contain a wildcard value.

§Examples
use up_rust::UUri;

let uri = UUri::try_from_parts("vin.vehicles", 0x0000_2310, 0x03, 0xa000).unwrap();
assert!(uri.verify_no_wildcards().is_ok());
Source

pub fn is_rpc_method(&self) -> bool

Checks if this UUri refers to a service method.

Returns true if 0 < resource ID < 0x8000.

§Examples
use up_rust::UUri;

let uri = UUri::try_from_parts("", 0xabcd, 0x01, 0x7FFF).unwrap();
assert!(uri.is_rpc_method());
Source

pub fn verify_rpc_method(&self) -> Result<(), UUriError>

Verifies that this UUri refers to a service method.

§Errors

Returns an error if Self::is_rpc_method fails or the UUri contains any wildcards.

§Examples
use up_rust::UUri;

let uri = UUri::try_from_parts("", 0xabcd, 0x01, 0x8000).unwrap();
assert!(uri.verify_rpc_method().is_err());

let uri = UUri::try_from_parts("", 0xabcd, 0x01, 0x0000).unwrap();
assert!(uri.verify_rpc_method().is_err());
Source

pub fn is_notification_destination(&self) -> bool

Checks if this UUri represents a destination for a Notification.

Returns true if resource ID is 0.

§Examples
use up_rust::UUri;

let uri = UUri::try_from_parts("", 0xabcd, 0x01, 0x0000).unwrap();
assert!(uri.is_notification_destination());
Source

pub fn is_rpc_response(&self) -> bool

Checks if this UUri represents an RPC response address.

Returns true if resource ID is 0.

§Examples
use up_rust::UUri;

let uri = UUri::try_from_parts("", 0xabcd, 0x01, 0x0000).unwrap();
assert!(uri.is_rpc_response());
Source

pub fn verify_rpc_response(&self) -> Result<(), UUriError>

Verifies that this UUri represents an RPC response address.

§Errors

Returns an error if Self::is_rpc_response fails or the UUri contains any wildcards.

§Examples
use up_rust::UUri;

let uri = UUri::try_from_parts("", 0xabcd, 0x01, 0x4001).unwrap();
assert!(uri.verify_rpc_response().is_err());
Source

pub fn is_event(&self) -> bool

Checks if this UUri can be used as the source of an event.

Returns true if resource ID >= 0x8000.

§Examples
use up_rust::UUri;

let uri = UUri::try_from_parts("", 0xabcd, 0x01, 0x8000).unwrap();
assert!(uri.is_event());
Source

pub fn verify_event(&self) -> Result<(), UUriError>

Verifies that this UUri can be used as the source of an event.

§Errors

Returns an error if Self::is_event fails or the UUri contains any wildcards.

§Examples
use up_rust::UUri;

let uri = UUri::try_from_parts("", 0xabcd, 0x01, 0x7FFF).unwrap();
assert!(uri.verify_event().is_err());
Source

pub fn matches(&self, candidate: &UUri) -> bool

Checks if a given candidate URI matches a pattern.

§Returns

true if the candiadate matches the pattern represented by this UUri.

§Examples
use up_rust::UUri;

let pattern = UUri::try_from("//vin/A14F/3/FFFF").unwrap();
let candidate = UUri::try_from("//vin/A14F/3/B1D4").unwrap();
assert!(pattern.matches(&candidate));

Trait Implementations§

Source§

impl AsRef<UUri> for ExactUUri

Source§

fn as_ref(&self) -> &UUri

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Clone for UUri

Source§

fn clone(&self) -> UUri

Returns a copy 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 UUri

Source§

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

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

impl Display for UUri

Source§

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

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

impl From<&UUri> for StaticUriProvider

Source§

fn from(source_uri: &UUri) -> Self

Creates a URI provider from a UUri.

§Arguments
  • source_uri - The UUri to take the entity’s authority, entity ID and version information from. The UUri’s resource ID is ignored.
§Examples
use up_rust::{LocalUriProvider, StaticUriProvider, UUri};

let source_uri = UUri::try_from("//my-vehicle/4210/5/1000").unwrap();
let provider = StaticUriProvider::from(&source_uri);
assert_eq!(provider.get_authority(), "my-vehicle");
assert_eq!(provider.get_source_uri(), source_uri.clone_with_resource_id(0x0000));
Source§

impl From<&UUri> for String

Source§

fn from(uri: &UUri) -> Self

Serializes a uProtocol URI to a URI string.

§Arguments
  • uri - The URI to serialize. Note that the given URI is not validated before serialization. In particular, the URI’s version and resource ID length are not checked to be within limits.
§Returns

The output of UUri::to_uri without including the uProtocol scheme.

§Examples
use up_rust::UUri;

let uuri = UUri::try_from_parts("vin.vehicles", 0x0000_800A, 0x02, 0x0000_1a50).unwrap();
let uri_string = String::from(&uuri);
assert_eq!(uri_string, "//vin.vehicles/800A/2/1A50");
Source§

impl From<ExactUUri> for UUri

Source§

fn from(value: ExactUUri) -> Self

Converts to this type from the input type.
Source§

impl From<UUri> for StaticUriProvider

Source§

fn from(value: UUri) -> Self

Converts to this type from the input type.
Source§

impl FromStr for UUri

Source§

fn from_str(uri: &str) -> Result<Self, Self::Err>

Attempts to parse a String into a UUri.

As part of the parsing, the authority of the URI is getting normalized. This means that all characters are converted to lowercase, no bytes that are in the unreserved character set remain percent-encoded, and all alphabetical characters in percent-encodings are converted to uppercase.

§Arguments
  • uri - The String to be converted into a UUri.
§Returns

A Result containing either the UUri representation of the URI or a SerializationError.

§Examples
use std::str::FromStr;
use up_rust::UUri;

let uri = UUri::try_from_parts("vin.vehicles", 0x000A_8000, 0x02, 0x0000_1a50).unwrap();
let uri_from = UUri::from_str("//vin.vehicles/A8000/2/1A50").unwrap();
assert_eq!(uri, uri_from);
Source§

type Err = UUriError

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

impl Hash for UUri

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 PartialEq<&str> for UUri

Source§

fn eq(&self, other: &&str) -> 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 PartialEq<String> for UUri

Source§

fn eq(&self, other: &String) -> 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 PartialEq<str> for UUri

Source§

fn eq(&self, other: &str) -> 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 PartialEq for UUri

Source§

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

Source§

fn parse_from_protobuf_bytes(proto: &[u8]) -> Result<Self, SerializationError>

Parses an instance of this type from the given protobuf bytes. Read more
Source§

fn parse_from_packed_protobuf_bytes( proto: &[u8], ) -> Result<Self, SerializationError>

Parses an instance of this type from the given packed protobuf bytes. Read more
Source§

fn write_to_protobuf_bytes(&self) -> Result<Vec<u8>, SerializationError>

Serializes this instance to protobuf bytes. Read more
Source§

fn write_to_packed_protobuf_bytes(&self) -> Result<Vec<u8>, SerializationError>

Serializes this instance to packed protobuf bytes. Read more
Source§

impl TryFrom<&UUri> for ExactUUri

Source§

type Error = UUriError

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

fn try_from(value: &UUri) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<&str> for UUri

Source§

fn try_from(uri: &str) -> Result<Self, Self::Error>

Attempts to serialize a String into a UUri.

§Arguments
  • uri - The String to be converted into a UUri.
§Returns

A Result containing either the UUri representation of the URI or a SerializationError.

§Examples
use up_rust::UUri;

let uri = UUri::try_from_parts("", 0x001A_8000, 0x02, 0x1a50).unwrap();
let uri_from = UUri::try_from("/1A8000/2/1A50").unwrap();
assert_eq!(uri, uri_from);
Source§

type Error = UUriError

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

impl TryFrom<String> for UUri

Source§

fn try_from(uri: String) -> Result<Self, Self::Error>

Attempts to serialize a String into a UUri.

§Arguments
  • uri - The String to be converted into a UUri.
§Returns

A Result containing either the UUri representation of the URI or a SerializationError.

§Examples
use up_rust::UUri;

let uri = UUri::try_from_parts("", 0x001A_8000, 0x02, 0x1a50).unwrap();
let uri_from = UUri::try_from("/1A8000/2/1A50".to_string()).unwrap();
assert_eq!(uri, uri_from);
Source§

type Error = UUriError

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

impl TryFrom<UUri> for ExactUUri

Source§

type Error = UUriError

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

fn try_from(value: UUri) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl Eq for UUri

Source§

impl StructuralPartialEq for UUri

Auto Trait Implementations§

§

impl Freeze for UUri

§

impl RefUnwindSafe for UUri

§

impl Send for UUri

§

impl Sync for UUri

§

impl Unpin for UUri

§

impl UnwindSafe for UUri

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
§

impl<T> Any for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

§

fn type_name(&self) -> &'static str

§

impl<T> AnySync for T
where T: Any + Send + Sync,

§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

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.

§

impl<T> Instrument for T

§

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

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

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<TCore> UWithNativePrefixWire for TCore

Source§

fn into_native_prefix_wire_transport<W>( self, wire: W, ) -> UWireTransport<TCore, W, NativePrefixFrameMetadataCodec>
where W: UWire,

Wraps this core with an external or custom selected wire using canonical metadata.
Source§

fn into_protobuf_transport( self, ) -> UWireTransport<TCore, ProtobufWire, NativePrefixFrameMetadataCodec>

Wraps this core with the Protocol Buffers selected-wire profile.
Source§

fn into_stable_container_transport( self, ) -> UWireTransport<TCore, StableContainerWireFormat, NativePrefixFrameMetadataCodec>

Wraps this core with the stable-container selected-wire profile.
§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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