hyperium / hyperium/hyper

Does Server have to be 'static?

Open
#2,144 2 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
16.3k
Forks
1.8k
Avg merge
1d 22h
Merged PRs (30d)
14

Description

I'm wondering if it could be okay for Server to grow a lifetime parameter, reflecting the inner MakeServiceRef. I can't see why this is not allowed:

pub async fn run<'a, A>(addr: &'a SocketAddr, app: &'a A) -> Result<(), hyper::Error>
    where
        A: Application<RequestBody = Body, ResponseBody = Body> + Send + Sync,
    {
        Server::bind(addr)
            .serve(make_service_fn(move |_| {
                async {
                    Ok::<_, Infallible>(service_fn(move |req| {
                        let cx = Context::new(app, req);
                        A::handle(cx).map(Ok::<_, Infallible>)
                    }))
                }
            }))
            .await
    }

errors with:

error: cannot infer an appropriate lifetime
  --> mendes/src/lib.rs:37:51
   |
37 |     pub async fn run<'a, A>(addr: &'a SocketAddr, app: &'a A) -> Result<(), hyper::Error>
   |                                                   ^^^ ...but this borrow...
...
42 |             .serve(make_service_fn(move |_| {
   |              ----- this return type evaluates to the `'static` lifetime...
   |
note: ...can't outlive the lifetime `'a` as defined on the function body at 37:22
  --> mendes/src/lib.rs:37:22
   |
37 |     pub async fn run<'a, A>(addr: &'a SocketAddr, app: &'a A) -> Result<(), hyper::Error>
   |                      ^^

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the reproduction in mendes/src/lib.rs, especially run, Server::bind, make_service_fn, and service_fn. Read the corresponding Server and MakeServiceRef APIs to determine whether the requested lifetime support is feasible; done means reaching a documented decision or an accepted implementation approach.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
api, backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
28/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.