#[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
enumwith no variants errors immediately, without waiting for data to appear on the stream. - For non-empty
enums, the representation starts with the discriminant (a number representing the variant), starting with0for the first variant declared and so on. - Then follow the
Protocolrepresentations of any fields of thestructor variant, in the order declared.
This representation can waste bandwidth for some types, e.g. structs 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(as_string)]: ImplementsProtocolfor this type by converting from and to a string using theFromStrandToStringtraits. TheFromStrerror type must implementInto<ReadErrorKind>.#[async_proto(map_err = ...)]: Removes the requirement for theFromStrerror type to implementInto<ReadErrorKind>and instead uses the given expression (which should be anFnOnce(<T as FromStr>::Err) -> ReadErrorKind) to convert the error.
#[async_proto(attr(...))]: Adds the given attribute(s) to theProtocolimplementation. For example, the implementation can be documented using#[async_proto(attr(doc = "..."))]. May be specified multiple times.#[async_proto(via = Proxy)]: ImplementsProtocolfor this type (let’s call itT) in terms of another type (Proxyin this case) instead of using the variant- and field-based representation described above.&'a Tmust implementInto<Proxy>for all'a, andProxymust implementProtocolandTryInto<T>with anErrortype that implementsInto<ReadErrorKind>.#[async_proto(clone)]: Replaces the requirement for&'a Tto implementInto<Proxy>with requirements forTto implementCloneandInto<Proxy>.#[async_proto(map_err = ...)]: Removes the requirement for<Proxy as TryInto<T>>::Errorto implementInto<ReadErrorKind>and instead uses the given expression (which should be anFnOnce(<Proxy as TryInto<T>>::Error) -> ReadErrorKind) to convert the error.
#[async_proto(where(...))]: Overrides the bounds for the generatedProtocolimplementation. The default is to requireProtocol + Send + Sync + 'staticfor each type parameter of this type.
§Compile errors
- This macro can’t be used with
unions.