Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get outside of filter (or allow +=ing into ext) #165

Closed
remexre opened this issue Feb 1, 2019 · 3 comments
Closed

get outside of filter (or allow +=ing into ext) #165

remexre opened this issue Feb 1, 2019 · 3 comments

Comments

@remexre
Copy link
Contributor

remexre commented Feb 1, 2019

I'm trying to accumulate into a request extension; it'd be convenient to have either a non-filter way to get the current value of a request extension, or a way to "add into" request extensions that are... AddAssign? Extend? frunk::Semigroup?

@seanmonstar
Copy link
Owner

I don't quite follow, mind expanding?

@remexre
Copy link
Contributor Author

remexre commented Feb 1, 2019

Basically, either of:

fn get2<T: 'static + Clone + Send + Sync>() -> Option<T> {
    ::route::with(|route| route.extensions_mut().get(val).cloned())
}

// or

fn semigroup_append<T: 'static + Semigroup + Send + Sync>(t: T) {
    ::route::with(move |route| {
        let mut exts = route.extensions_mut();
        let val = exts.get::<T>()
            .map(|prev| prev.combine(&t))
            .unwrap_or(t);
        exts.insert(val);
    });
}

EDIT: With possibly AddAssign/Extend versions instead of Semigroup, to avoid a dependency on frunk.

@jxs
Copy link
Collaborator

jxs commented Jul 7, 2020

this is now achievable with the Filter to Service conversion.
Also see #16 (comment)

@jxs jxs closed this as completed Jul 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants