Derive Macro axum_starter::Provider
source · #[derive(Provider)]
{
// Attributes available to this derive:
#[provider]
}
Expand description
implement Provider<T>
for each field of the struct
§Example
use std::net::SocketAddr;
use axum_starter;
use axum_starter_macro::Provider;
#[derive(Debug, Provider)]
#[provider(r#ref)]
struct Configure {
// this will impl `Provider<&String>`
// because of the `ref` on container and its own `transparent`
#[provider(transparent)]
foo: String,
// this will not impl provide
#[provider(skip)]
bar: SocketAddr,
// this will impl `Provide<FooBar>`
// where `FooBar` is `struct FooBar((i32,i32));`
// `ignore_global` will ignore the `ref` on the container
#[provider(ignore_global)]
foo_bar: (i32, i32),
}
fn foo_fetch(foo: &String, FooBar(foo_bar): FooBar){
// do somethings
}
- using
r#ref
to implProvider
provide reference instant of Owned (with clone) .Can be using on container to apply on all fields - using
transparent
to implProvider
the original type instant of generate a wrapper type. Can be using on container to apply on all fields - using
ignore_global
to ignore theref
andtransparent
setting on container - using
skip
to not implProvider
for this field - using
map_to(ty , by)
to adding extra provide for Type by the giving function, if the type need lifetime mark, addinglifetime = "'a"
, then using'a
in your type for example& 'a str