Trait async_rustbus::rustbus_core::wire::marshal::traits::Signature [−][src]
pub trait Signature {
fn signature() -> Type;
fn alignment() -> usize;
unsafe fn valid_slice(_bo: ByteOrder) -> bool { ... }
fn sig_str(s_buf: &mut SignatureBuffer) { ... }
}Required methods
Provided methods
unsafe fn valid_slice(_bo: ByteOrder) -> bool
unsafe fn valid_slice(_bo: ByteOrder) -> boolIf this returns true,
it indicates that for implementing type T,
Rust’s [T] is identical to DBus’s array format
and can be copied into a message after aligning the first element.
The default implementation is false but can be overridden for a performance gain
if it is valid.
Safety
Calls to this function should always be safe. Implementors should respect this property.
The reason this method is unsafe is to indicate to people implementing Signature that
overriding it has the potential to induce unsound behavior
if the following rules aren’t followed:
- The type
TimplementingSignaturemust beCopy. - The size of
Tmust be equivalent to it’s DBus alignment (see here). - Every possible bit-pattern must represent a valid instance of
T. For examplestd::num::NonZeroU32does not meet this requirement0is invalid. - The type should not contain an Fd receieved from the message.
When implementing
Unmarshalthe type should only dependent the'buflifetime. It should never require the use of'fds.
Notes
- This method exists because of limitiation with Rust type system.
Should
#[feature(specialization)]ever become stablized this will hopefully be unnecessary. - This method should use the
ByteOrderto check if it matches native order before returningtrue.ByteOrder::NATIVEcan be used to detect the native order.
fn sig_str(s_buf: &mut SignatureBuffer)
fn sig_str(s_buf: &mut SignatureBuffer)Appends the signature of the type to the SignatureBuffer.
By using SignatureBuffer, implementations of this method can avoid unnecessary allocations
by only allocating if a signature is dynamic.
The default implementation of sig_str can be pretty slow.
If type, that Signature is being implemented for, has a static (unchanging) signature
then overriding this method can have a significant performance benefit when marshal/unmarshalling
the type inside variants.
Implementations on Foreign Types
Implementors
impl<S> Signature for async_rustbus::rustbus_core::wire::marshal::traits::ObjectPath<S> where
S: AsRef<str>,