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) { ... }
fn has_sig(sig: &str) -> bool { ... } }

Required methods

Provided methods

If 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:

  1. The type T implementing Signature must be Copy.
  2. The size of T must be equivalent to it’s DBus alignment (see here).
  3. Every possible bit-pattern must represent a valid instance of T. For example std::num::NonZeroU32 does not meet this requirement 0 is invalid.
  4. The type should not contain an Fd receieved from the message. When implementing Unmarshal the type should only dependent the 'buf lifetime. 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 ByteOrder to check if it matches native order before returning true. ByteOrder::NATIVE can be used to detect the native order.

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.

Check if this type fulfills this signature. This may expect to only be called with valid signatures. But it might be called with the wrong signature. This means for example you must check the length before indexing.

The default impl uses Signature::sig_str and compares it to the given signature. The same performance implications as for Signature::sig_str apply here.

Implementations on Foreign Types

Implementors