Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extern crate mio;
- extern crate slab;
- use mio::Poll;
- use slab::Slab;
- fn main() {
- let server = Server::new();
- server.example();
- }
- struct Server {
- poll: Poll,
- conns: Slab<Connection>,
- }
- impl Server {
- pub fn new() -> Server {
- let poll = Poll::new().expect("failed to create poll");
- Server {
- poll,
- conns: Slab::with_capacity(1000),
- }
- }
- pub fn example(&self) {
- let conn = Connection::new(&mut self.poll, 0);
- }
- }
- struct Connection<'a> {
- poll: &mut Poll,
- // sock ...
- // addr ...
- x: u8,
- }
- impl<'a> Connection<'a> {
- pub fn new(poll: &'a mut Poll, x: u8) -> Connection {
- Connection { poll, x }
- }
- }
Add Comment
Please, Sign In to add comment