pub trait Key:
Eq
+ PartialEq
+ PartialOrd
+ Ord
+ Hash
+ Clone
+ Serialize
+ CdrEncodingSize {
// Provided method
fn hash_key(&self, force_md5: bool) -> KeyHash { ... }
}
Expand description
Trait for instance lookup key in a WITH_KEY topic.
The corresponding data sample type must implement Keyed
.
If the topic is NO_KEY, both of these can be ignored.
It is a combination of traits from the standard library
and Serde traits
and a RustDDS-specific trait
- CdrEncodingSize , for which we provide a derive macro.
No other methods are required, so for many types it should be possible to
#[derive]
all the prerequisite traits and implement as impl Key for Foo {}
. Consider also deriving Copy
for your key, if the usual
preconditions are satisfied.
Note: When implementing Key, DeserializeOwned cannot and need not be
derived, as it is a type alias. Derive (or implement) the Deserialize
trait instead.
§Example
use rustdds::*;
use serde::{Serialize, Deserialize};
#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord,
Serialize, Deserialize, CdrEncodingSize)]
pub struct MyKey {
number: u32,
name: String,
}
impl Key for MyKey {}
Provided Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.