hyperium / hyperium/hyper

Reduce lifetime requirements of `serve`.

Open
#1,669 8 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Currently the NewService trait, and a lot of the other parameters for serve require a 'static lifetime.
I'm a bit of a Rust rookie, but wouldn't it be better to tie it to the server itself?

As it stands, there's no safe way to do something like:
(Where self is some managed state)

fn start(self, port: u16) {
	let addr = ([127, 0, 0, 1], port).into();

	let service_factory =
		|| service_fn(|req| handle_incoming(&self, req));

	let server = Server::bind(&addr)
		.serve(service_factory)
		.map_err(|e| eprintln!("Server error: {}", e));

	hyper::rt::run(server);
}

I can't take a reference to self, because the lifetime is static.
Even though, the server is started on the next line, and it blocks.
So, once it gets to the end of this method, the server would have already stopped.

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 by reading the NewService trait and the serve entry point to map where the 'static lifetime requirements are imposed. Determine whether the requested server-tied lifetimes can be supported safely, and document the affected API behavior and tests needed to demonstrate that non-static managed state works.

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
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.