pub struct UUri {
pub authority_name: String,
pub ue_id: u32,
pub ue_version_major: u32,
pub resource_id: u32,
pub special_fields: SpecialFields,
}
Fields§
§ue_id: u32
§ue_version_major: u32
§resource_id: u32
§special_fields: SpecialFields
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 {
authority_name: String::from("VIN.vehicles"),
ue_id: 0x0000_800A,
ue_version_major: 0x02,
resource_id: 0x0000_1a50,
..Default::default()
};
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: u32) -> Self
pub fn any_with_resource_id(resource_id: u32) -> Self
Gets a URI that consists of wildcards and the 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 check_validity(&self) -> Result<(), UUriError>
pub fn check_validity(&self) -> Result<(), UUriError>
Verifies that this UUri is indeed a valid uProtocol URI.
This check is not necessary, if any of UUri’s constructors functions has been used to create the URI. However, if the origin of a UUri is unknown, e.g. when it has been deserialized from a protobuf, then this function can be used to check if all properties are compliant with the uProtocol specification.
§Errors
Returns an error if this UUri is not a valid uProtocol URI. The returned error may contain details regarding the cause of the validation to have failed.
§Examples
use up_rust::UUri;
let uuri = UUri {
authority_name: "valid_name".into(),
ue_id: 0x1000,
ue_version_major: 0x01,
resource_id: 0x8100,
..Default::default()
};
assert!(uuri.check_validity().is_ok());
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".to_string();
assert!(authority_a.is_remote_authority(&authority_b));
let authority_local = "".to_string();
assert!(!authority_a.is_remote_authority(&authority_local));
let authority_wildcard = "*".to_string();
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>
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 {
authority_name: String::from("VIN.vehicles"),
ue_id: 0x0000_2310,
ue_version_major: 0x03,
resource_id: 0xa000,
..Default::default()
};
assert!(uri.verify_no_wildcards().is_ok());
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 {
resource_id: 0x7FFF,
..Default::default()
};
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 {
resource_id: 0x8000,
..Default::default()
};
assert!(uri.verify_rpc_method().is_err());
let uri = UUri {
resource_id: 0x0,
..Default::default()
};
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 {
resource_id: 0,
..Default::default()
};
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 {
resource_id: 0,
..Default::default()
};
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 {
resource_id: 0x4001,
..Default::default()
};
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 {
resource_id: 0x8000,
..Default::default()
};
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 {
resource_id: 0x7FFF,
..Default::default()
};
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 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 {
authority_name: String::from("VIN.vehicles"),
ue_id: 0x0000_800A,
ue_version_major: 0x02,
resource_id: 0x0000_1a50,
..Default::default()
};
let uri_string = String::from(&uuri);
assert_eq!(uri_string, "//VIN.vehicles/800A/2/1A50");
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
- TheString
to 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 {
authority_name: "VIN.vehicles".to_string(),
ue_id: 0x000A_8000,
ue_version_major: 0x02,
resource_id: 0x0000_1a50,
..Default::default()
};
let uri_from = UUri::from_str("//VIN.vehicles/A8000/2/1A50").unwrap();
assert_eq!(uri, uri_from);
Source§impl Message for UUri
impl Message for UUri
Source§fn is_initialized(&self) -> bool
fn is_initialized(&self) -> bool
true
for protobuf 3.Source§fn merge_from(&mut self, is: &mut CodedInputStream<'_>) -> Result<()>
fn merge_from(&mut self, is: &mut CodedInputStream<'_>) -> Result<()>
Source§fn compute_size(&self) -> u64
fn compute_size(&self) -> u64
Source§fn write_to_with_cached_sizes(
&self,
os: &mut CodedOutputStream<'_>,
) -> Result<()>
fn write_to_with_cached_sizes( &self, os: &mut CodedOutputStream<'_>, ) -> Result<()>
Source§fn special_fields(&self) -> &SpecialFields
fn special_fields(&self) -> &SpecialFields
Source§fn mut_special_fields(&mut self) -> &mut SpecialFields
fn mut_special_fields(&mut self) -> &mut SpecialFields
Source§fn default_instance() -> &'static UUri
fn default_instance() -> &'static UUri
Source§fn parse_from(is: &mut CodedInputStream<'_>) -> Result<Self, Error>
fn parse_from(is: &mut CodedInputStream<'_>) -> Result<Self, Error>
Source§fn cached_size(&self) -> u32
fn cached_size(&self) -> u32
compute_size
. Read moreSource§fn write_to(&self, os: &mut CodedOutputStream<'_>) -> Result<(), Error>
fn write_to(&self, os: &mut CodedOutputStream<'_>) -> Result<(), Error>
Source§fn write_length_delimited_to(
&self,
os: &mut CodedOutputStream<'_>,
) -> Result<(), Error>
fn write_length_delimited_to( &self, os: &mut CodedOutputStream<'_>, ) -> Result<(), Error>
Source§fn write_length_delimited_to_vec(&self, vec: &mut Vec<u8>) -> Result<(), Error>
fn write_length_delimited_to_vec(&self, vec: &mut Vec<u8>) -> Result<(), Error>
Source§fn merge_from_bytes(&mut self, bytes: &[u8]) -> Result<(), Error>
fn merge_from_bytes(&mut self, bytes: &[u8]) -> Result<(), Error>
Source§fn parse_from_reader(reader: &mut dyn Read) -> Result<Self, Error>
fn parse_from_reader(reader: &mut dyn Read) -> Result<Self, Error>
Source§fn parse_from_tokio_bytes(bytes: &Bytes) -> Result<Self, Error>
fn parse_from_tokio_bytes(bytes: &Bytes) -> Result<Self, Error>
Bytes
object.
Resulting message may share references to the passed bytes object.Source§fn check_initialized(&self) -> Result<(), Error>
fn check_initialized(&self) -> Result<(), Error>
Source§fn write_to_writer(&self, w: &mut dyn Write) -> Result<(), Error>
fn write_to_writer(&self, w: &mut dyn Write) -> Result<(), Error>
Source§fn write_length_delimited_to_writer(
&self,
w: &mut dyn Write,
) -> Result<(), Error>
fn write_length_delimited_to_writer( &self, w: &mut dyn Write, ) -> Result<(), Error>
Source§fn write_length_delimited_to_bytes(&self) -> Result<Vec<u8>, Error>
fn write_length_delimited_to_bytes(&self) -> Result<Vec<u8>, Error>
Source§fn unknown_fields(&self) -> &UnknownFields
fn unknown_fields(&self) -> &UnknownFields
Source§fn mut_unknown_fields(&mut self) -> &mut UnknownFields
fn mut_unknown_fields(&mut self) -> &mut UnknownFields
Source§impl MessageFull for UUri
impl MessageFull for UUri
Source§fn descriptor() -> MessageDescriptor
fn descriptor() -> MessageDescriptor
Source§fn reflect_eq(&self, other: &Self, mode: &ReflectEqMode) -> bool
fn reflect_eq(&self, other: &Self, mode: &ReflectEqMode) -> bool
Source§impl ProtobufValue for UUri
impl ProtobufValue for UUri
Source§type RuntimeType = RuntimeTypeMessage<UUri>
type RuntimeType = RuntimeTypeMessage<UUri>
Source§impl TryFrom<&UUri> for StaticUriProvider
impl TryFrom<&UUri> for StaticUriProvider
Source§fn try_from(source_uri: &UUri) -> Result<Self, Self::Error>
fn try_from(source_uri: &UUri) -> Result<Self, Self::Error>
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.
§Errors
Returns an error if the given UUri’s major version property is not a u8
.
§Examples
use up_rust::{LocalUriProvider, StaticUriProvider, UUri};
let source_uri = UUri::try_from("//my-vehicle/4210/5/0").unwrap();
assert!(StaticUriProvider::try_from(&source_uri).is_ok());
§Invalid Major Version
use up_rust::{LocalUriProvider, StaticUriProvider, UUri};
let uuri_with_invalid_version = UUri {
authority_name: "".to_string(),
ue_id: 0x5430,
ue_version_major: 0x1234, // not a u8
resource_id: 0x0000,
..Default::default()
};
assert!(StaticUriProvider::try_from(uuri_with_invalid_version).is_err());
Source§type Error = TryFromIntError
type Error = TryFromIntError
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
- TheString
to 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 {
authority_name: "".to_string(),
ue_id: 0x001A_8000,
ue_version_major: 0x02,
resource_id: 0x0000_1a50,
..Default::default()
};
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
- TheString
to 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 {
authority_name: "".to_string(),
ue_id: 0x001A_8000,
ue_version_major: 0x02,
resource_id: 0x0000_1a50,
..Default::default()
};
let uri_from = UUri::try_from("/1A8000/2/1A50".to_string()).unwrap();
assert_eq!(uri, uri_from);
Source§impl TryFrom<UUri> for StaticUriProvider
impl TryFrom<UUri> for StaticUriProvider
impl Eq for UUri
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> 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<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<M> MessageDyn for Mwhere
M: MessageFull,
impl<M> MessageDyn for Mwhere
M: MessageFull,
Source§fn descriptor_dyn(&self) -> MessageDescriptor
fn descriptor_dyn(&self) -> MessageDescriptor
Source§fn merge_from_dyn(&mut self, is: &mut CodedInputStream<'_>) -> Result<(), Error>
fn merge_from_dyn(&mut self, is: &mut CodedInputStream<'_>) -> Result<(), Error>
Source§fn write_to_with_cached_sizes_dyn(
&self,
os: &mut CodedOutputStream<'_>,
) -> Result<(), Error>
fn write_to_with_cached_sizes_dyn( &self, os: &mut CodedOutputStream<'_>, ) -> Result<(), Error>
Source§fn compute_size_dyn(&self) -> u64
fn compute_size_dyn(&self) -> u64
Source§fn is_initialized_dyn(&self) -> bool
fn is_initialized_dyn(&self) -> bool
true
for protobuf 3.