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 address

    • path a path to a function or a closure expr, its signature is Fn(config: &Self) -> $ty
    • ty (optional) default is [std::net::SocketAddr]
    • associate(optional) set whether the function to call need argument Self, if set associate the signature of function to call is Fn()->$ty

§logger

  • using logger(error="...", func="...",associate) to impl LoggerInitialization, the func and associate is similar to the path and associate of address(func(path="...", associate)) but the return type became Result<(),$error>
    • error the error that might occur during initialization the log system

§server

  • using server="..." to impl ConfigureServerEffect with internally call the provide func or just using server or ignore it to having an empty implement. The function look like fn (&self, Builder<AddrIncome>) -> Builder<AddrIncome>