Skip to content

Make Service::call() take &mut self#6

Closed
petoknm wants to merge 1 commit intoreu:masterfrom
petoknm:fnmut-service
Closed

Make Service::call() take &mut self#6
petoknm wants to merge 1 commit intoreu:masterfrom
petoknm:fnmut-service

Conversation

@petoknm
Copy link
Contributor

@petoknm petoknm commented Jan 25, 2025

I found it useful in a single threaded environment to have the option to use an FnMut service.

Example:

let mut counter = 0;
Server::bind((address, port))
    .serve_single_thread(|_| {
        counter += 1;
        Response::builder().status(200).body(format!("count = {}", counter))
    })
    .unwrap();

@petoknm
Copy link
Contributor Author

petoknm commented Jan 25, 2025

Just sharing what changes I made and found useful for my somewhat special circumstances. So I will fully understand if you don't want these changes upstream. :)

@reu
Copy link
Owner

reu commented Jan 28, 2025

This actually makes a lot of sense! I was so focused on Hyper when I first built this, that I didn't even take into consideration the possibility of having mutable services, which does fit really well into the sync nature of Touche.

I will just give a code review, but I really like the idea, thanks @petoknm!

@reu
Copy link
Owner

reu commented Jan 29, 2025

Hey @petoknm I just opened #9 with some small tweaks but this looks great!

@reu reu closed this Jan 29, 2025
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

Successfully merging this pull request may close these issues.

2 participants