Trait aide::ApiOverride

source ·
pub trait ApiOverride {
    type Target;
}
Expand description

Trait that allows implementing a custom Api definition for any type.

Two approaches are possible:

  1. Simple Type override for concrete types

#[derive(Debug)]
struct MyApiOverride;

impl ApiOverride for MyApiOverride {
    type Target = SomeType;
}

impl OperationInput for MyApiOverride {
    // override stuff
    // can be done with OperationOutput as well
}

async fn my_handler(WithApi(ty, ..): WithApi<MyApiOverride>) -> bool {
    assert_eq!(ty, SomeType);
    true
}
  1. Generic Type Override

#[derive(Debug)]
struct MyCustomXML<T>(PhantomData<T>);

impl<T> ApiOverride for MyCustomXML<T> {
    type Target = CustomXML<T>;
}

impl<T> OperationInput for MyCustomXML<T> {
    // override stuff with access to T
    // can be done with OperationOutput as well
}

async fn my_handler(WithApi(ty, ..): WithApi<MyCustomXML<SomeType>>) -> bool {
    assert_eq!(ty, CustomXML(SomeType));
    true
}

Required Associated Types§

source

type Target

The type that is being overridden

Implementors§