Skip to content

how about adding reload feature for axum? #2161

Answered by jplatte
zishon asked this question in Q&A
Discussion options

You must be logged in to vote

Alright, so it's just a small struct that is cloned everywhere and parsed using the toml crate. In that case, I would recommend making your state type

use std::sync::RwLock;

struct AppState {
    // Could also use the arc_swap crate for Arc<ArcSwap<Arc<AppConfig>>>
    config: Arc<RwLock<AppConfigInner>>,
}

// With the derived Deserialize impl, you can use
// toml::from_str::<AppConfigInner>(&raw_config)
// directly, instead of going through toml::Value
#[derive(Deserialize)]
struct AppConfig {
    app_id: String,
    app_secret: String,
}

// To allow extracting State<AppConfig> but supplying `.with_state(<AppState instance>)`
impl FromRef<AppState> for AppConfig {
    fn from_ref(state: 

Replies: 4 comments 11 replies

Comment options

You must be logged in to vote
1 reply
@zishon
Comment options

Comment options

You must be logged in to vote
9 replies
@zishon
Comment options

@jplatte
Comment options

@zishon
Comment options

@jplatte
Comment options

Answer selected by zishon
@zishon
Comment options

This comment has been hidden.

@jplatte

This comment has been hidden.

Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants