Derive Macro async_proto::Protocol
source · [−]#[derive(Protocol)]
{
// Attributes available to this derive:
#[async_proto]
}
Expand description
Implements the Protocol
trait for this type.
The network representation is very simple:
- Attempting to read an
enum
with no variants errors immediately, without waiting for data to appear on the stream. - For non-empty
enum
s, the representation starts with the discriminant (a number representing the variant), starting with0
for the first variant declared and so on. - Then follow the
Protocol
representations of any fields of thestruct
or variant, in the order declared.
This representation can waste bandwidth for some types, e.g. struct
s with multiple bool
fields. For those, you may want to implement Protocol
manually.
Attributes
This macro’s behavior can be modified using attributes. Multiple attributes can be specified as #[async_proto(attr1, attr2, ...)]
or #[async_proto(attr1)] #[async_proto(attr2)] ...
. The following attributes are available:
#[async_proto(via = Proxy)]
: ImplementsProtocol
for this type (let’s call itT
) in terms of another type (Proxy
in this case) instead of using the variant- and field-based representation described above.&'a T
must implementInto<Proxy>
for all'a
, andProxy
must implementProtocol
andTryInto<T>
with anError
type that implementsInto<ReadError>
.#[async_proto(map_err = ...)]
: Removes the requirement for<Proxy as TryInto<T>>::Error
to implementInto<ReadError>
and instead uses the given expression (which should be anFnOnce(<Proxy as TryInto<T>>::Error) -> ReadError
) to convert the error.
#[async_proto(where(...))]
: Overrides the bounds for the generatedProtocol
implementation. The default is to requireProtocol + Send + Sync + 'static
for each type parameter of this type.
Compile errors
- This macro can’t be used with
union
s.