Skip to main content

define_upnp_operation

Macro define_upnp_operation 

Source
macro_rules! define_upnp_operation {
    (
        operation: $op_struct:ident,
        action: $action:literal,
        service: $service:ident,
        request: {
            $($field:ident: $field_type:ty),* $(,)?
        },
        response: $response_type:ty,
        payload: |$req_param:ident| $payload_expr:expr,
        parse: |$xml_param:ident| $parse_expr:expr $(,)?
    ) => { ... };
}
Expand description

Simplified macro for defining UPnP operations with minimal boilerplate

This macro generates all the necessary structs and trait implementations for a UPnP operation.

§Example

define_upnp_operation! {
    operation: PlayOperation,
    action: "Play",
    service: AVTransport,
    request: {
        speed: String,
    },
    response: (),
    payload: |req| format!("<InstanceID>{}</InstanceID><Speed>{}</Speed>", req.instance_id, req.speed),
    parse: |_xml| Ok(()),
}