#[repr(C)]pub struct UUri { /* private fields */ }Expand description
A URI that represents a uProtocol resource identifier.
Implementations§
Source§impl UUri
impl UUri
Sourcepub fn to_uri(&self, include_scheme: bool) -> String
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");Sourcepub fn try_from_parts(
authority: &str,
entity_id: u32,
entity_version: u8,
resource_id: u16,
) -> Result<Self, UUriError>
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());Sourcepub fn any_with_resource_id(resource_id: u16) -> Self
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.
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");Sourcepub fn uentity_type_id(&self) -> u16
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);Sourcepub fn uentity_instance_id(&self) -> u16
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);Sourcepub fn uentity_major_version(&self) -> u8
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);Sourcepub fn resource_id(&self) -> u16
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);Sourcepub fn clone_with_resource_id(&self, resource_id: u16) -> Self
pub fn clone_with_resource_id(&self, resource_id: u16) -> Self
Returns a copy of this URI with the resource id replaced.
Sourcepub fn is_remote(&self, other_uri: &UUri) -> bool
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));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));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());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());Sourcepub fn has_wildcard_entity_instance(&self) -> bool
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());Sourcepub fn has_wildcard_entity_type(&self) -> bool
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());Sourcepub fn has_wildcard_version(&self) -> bool
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());Sourcepub fn has_wildcard_resource_id(&self) -> bool
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());Sourcepub fn verify_no_wildcards(&self) -> Result<(), UUriError>
pub fn verify_no_wildcards(&self) -> Result<(), UUriError>
Sourcepub fn is_rpc_method(&self) -> bool
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());Sourcepub fn verify_rpc_method(&self) -> Result<(), UUriError>
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());Sourcepub fn is_notification_destination(&self) -> bool
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());Sourcepub fn is_rpc_response(&self) -> bool
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());Sourcepub fn verify_rpc_response(&self) -> Result<(), UUriError>
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());Sourcepub fn is_event(&self) -> bool
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());Sourcepub fn verify_event(&self) -> Result<(), UUriError>
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());Sourcepub fn matches(&self, candidate: &UUri) -> bool
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 From<&UUri> for StaticUriProvider
impl From<&UUri> for StaticUriProvider
Source§fn from(source_uri: &UUri) -> Self
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
impl From<&UUri> for String
Source§fn from(uri: &UUri) -> Self
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<UUri> for StaticUriProvider
impl From<UUri> for StaticUriProvider
Source§impl FromStr for UUri
impl FromStr for UUri
Source§fn from_str(uri: &str) -> Result<Self, Self::Err>
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- TheStringto be converted into aUUri.
§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§impl ProtobufMappable for UUri
impl ProtobufMappable for UUri
Source§fn parse_from_protobuf_bytes(proto: &[u8]) -> Result<Self, SerializationError>
fn parse_from_protobuf_bytes(proto: &[u8]) -> Result<Self, SerializationError>
Source§fn parse_from_packed_protobuf_bytes(
proto: &[u8],
) -> Result<Self, SerializationError>
fn parse_from_packed_protobuf_bytes( proto: &[u8], ) -> Result<Self, SerializationError>
Source§fn write_to_protobuf_bytes(&self) -> Result<Vec<u8>, SerializationError>
fn write_to_protobuf_bytes(&self) -> Result<Vec<u8>, SerializationError>
Source§fn write_to_packed_protobuf_bytes(&self) -> Result<Vec<u8>, SerializationError>
fn write_to_packed_protobuf_bytes(&self) -> Result<Vec<u8>, SerializationError>
Source§impl TryFrom<&str> for UUri
impl TryFrom<&str> for UUri
Source§fn try_from(uri: &str) -> Result<Self, Self::Error>
fn try_from(uri: &str) -> Result<Self, Self::Error>
Attempts to serialize a String into a UUri.
§Arguments
uri- TheStringto be converted into aUUri.
§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§impl TryFrom<String> for UUri
impl TryFrom<String> for UUri
Source§fn try_from(uri: String) -> Result<Self, Self::Error>
fn try_from(uri: String) -> Result<Self, Self::Error>
Attempts to serialize a String into a UUri.
§Arguments
uri- TheStringto be converted into aUUri.
§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);