[−][src]Macro uni_components::define_type
define_type!() { /* proc-macro */ }
Helps to define type for service output
Two parameters have to be specified: name
and variants
(doc
is optional).
doc
(optional)
Provide string literal there. It'll be used as doc for the new type.
name
(required)
It'll become the name of a new type so any identifier will works. Generic types may be specified as
//... name: TypeName<T,K> where T: Send, K: Sync {}, //...
Please take a look at {}
at the end of the line.
The minimal bound should be
T: 'static + Send + Sync + serde::Serialize + serde::de::DeserializeOwned
.
variants
(required)
It looks like array where each element are one possible vairant of service answer:
<VariantName> { code: <code_value>, body: <body_type>, doc: <doc_content>, }
will become identifier for the variant, - <code_value> (required) should be u16 and recommended to be one of allowed HTTP codes
body
(optional) parameter is optional and <body_type> have to be the type of data represented by the variantdoc
(optional) parameter is optional and <doc_content> have to be string literal, that literal will be added as documentation to the variant
Example
define_type!{ doc: " The type repsersents an answer for the question. Server may have the answer or may have not. ", name: QuestionAnswer, variants:[ Ok{ code: 200, body: String, doc: "Answer found:", }, NumberNotFound{ code: 404, doc: "Answer not found", }, ] }