Derive Macro axum_starter::Configure
source · #[derive(Configure)]
{
// Attributes available to this derive:
#[conf]
}
Expand description
help macro from impl ServeAddress
, LoggerInitialization
, ConfigureServerEffect
§Example
use std::net::SocketAddr;
use axum_starter_macro::{Configure, Provider};
#[derive(Debug, Provider, Configure)]
#[conf(
address(provide),
logger(error = "log::SetLoggerError", func = "Self::init_log"),
server
)]
struct Configure {
#[provider(transparent)]
bar: SocketAddr,
}
impl Configure {
fn init_log(&self) -> Result<(), log::SetLoggerError>{
// initial the logger
Ok(())
}
}
§Usage
§address
-
using
address(provide)
direct using the config provide to get address, -
using
address(provide(ty = "..."))
similar to previous one, but using the provide type Note: the provided type need impl Intostd::net::SocketAddr -
using
address(func(path = "...", ty = "...", associate))
using provide function get the socket addresspath
a path to a function or a closure expr, its signature isFn(config: &Self) -> $ty
ty
(optional) default is [std::net::SocketAddr]associate
(optional) set whether the function to call need argumentSelf
, if setassociate
the signature of function to call isFn()->$ty
§logger
- using
logger(error="...", func="...",associate)
to implLoggerInitialization
, thefunc
andassociate
is similar to thepath
andassociate
ofaddress(func(path="...", associate))
but the return type becameResult<(),$error>
error
the error that might occur during initialization the log system
§server
- using
server="..."
to implConfigureServerEffect
with internally call theprovide
func or just usingserver
or ignore it to having an empty implement. The function look likefn (&self, Builder<AddrIncome>) -> Builder<AddrIncome>