Skip to content

Using Arc<AppState> with SignedCookieJar #1556

Answered by davidpdrsn
woile asked this question in Q&A
Discussion options

You must be logged in to vote

Since you cannot implement FromRef<Arc<AppState>> for Key I'd recommend a newtype:

#[derive(Clone)]
struct AppState(Arc<InnerState>);

// deref so you can still access the inner fields easily
impl Deref for AppState {
    type Target = InnerState;

    fn deref(&self) -> &Self::Target {
        &*self.0
    }
}

struct InnerState {
    key: Key
}

impl FromRef<AppState> for Key {
    fn from_ref(state: &AppState) -> Self {
        state.0.key.clone()
    }
}

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@woile
Comment options

@davidpdrsn
Comment options

@woile
Comment options

@davidpdrsn
Comment options

Answer selected by woile
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants