Skip to content

Instantly share code, notes, and snippets.

@blechatellier
Last active May 7, 2019 00:17
Show Gist options
  • Save blechatellier/a4fabf9251250cfa208b817a2d6b5b73 to your computer and use it in GitHub Desktop.
Save blechatellier/a4fabf9251250cfa208b817a2d6b5b73 to your computer and use it in GitHub Desktop.
Trying to get a persistent reference working with Iron, not sure how to set an appropriate lifetime here. I want to be able to re-use the controller on different routes.
[package]
name = "iron-lifetime"
version = "0.1.0"
edition = "2018"
[dependencies]
iron = "0.6.*"
router = "0.6.*"
persistent = "0.4.0"
use iron::prelude::*;
use iron::typemap::Key;
use router::Router;
use persistent::Read;
pub struct Controller;
pub struct Rest {
controller: Controller,
}
impl Key for &Controller {
type Value = Self;
}
impl Rest {
pub fn run(&self) {
let router = Router::new();
let mut chain = Chain::new(router);
chain.link(Read::<&Controller>::both(&self.controller));
Iron::new(chain).http(format!("0.0.0.0:1234")).ok();
}
}
fn main() {
Rest {
controller: Controller,
}.run();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment