Git Product home page Git Product logo

persistent's Introduction

Iron

Build Status Crates.io Status License

Extensible, Concurrency Focused Web Development in Rust.

Response Timer Example

Note: This example works with the current iron code in this repository (master branch). If you are using iron 0.6 from crates.io, please refer to the corresponding example in the branch 0.6-maintenance.

extern crate iron;
extern crate time;

use iron::prelude::*;
use iron::{typemap, AfterMiddleware, BeforeMiddleware};
use time::precise_time_ns;

struct ResponseTime;

impl typemap::Key for ResponseTime { type Value = u64; }

impl BeforeMiddleware for ResponseTime {
    fn before(&self, req: &mut Request) -> IronResult<()> {
        req.extensions.insert::<ResponseTime>(precise_time_ns());
        Ok(())
    }
}

impl AfterMiddleware for ResponseTime {
    fn after(&self, req: &mut Request, res: Response) -> IronResult<Response> {
        let delta = precise_time_ns() - *req.extensions.get::<ResponseTime>().unwrap();
        println!("Request took: {} ms", (delta as f64) / 1000000.0);
        Ok(res)
    }
}

fn hello_world(_: &mut Request) -> IronResult<Response> {
    Ok(Response::with((iron::StatusCode::OK, "Hello World")))
}

fn main() {
    let mut chain = Chain::new(hello_world);
    chain.link_before(ResponseTime);
    chain.link_after(ResponseTime);
    Iron::new(chain).http("localhost:3000");
}

Overview

Iron is a high level web framework built in and for Rust, built on hyper. Iron is designed to take advantage of Rust's greatest features - its excellent type system and its principled approach to ownership in both single threaded and multi threaded contexts.

Iron is highly concurrent and can scale horizontally on more machines behind a load balancer or by running more threads on a more powerful machine. Iron avoids the bottlenecks encountered in highly concurrent code by avoiding shared writes and locking in the core framework.

Iron is 100% safe code:

$ rg unsafe src | wc
       0       0       0

Philosophy

Iron is meant to be as extensible and pluggable as possible; Iron's core is concentrated and avoids unnecessary features by leaving them to middleware, plugins, and modifiers.

Middleware, Plugins, and Modifiers are the main ways to extend Iron with new functionality. Most extensions that would be provided by middleware in other web frameworks are instead addressed by the much simpler Modifier and Plugin systems.

Modifiers allow external code to manipulate Requests and Response in an ergonomic fashion, allowing third-party extensions to get the same treatment as modifiers defined in Iron itself. Plugins allow for lazily-evaluated, automatically cached extensions to Requests and Responses, perfect for parsing, accessing, and otherwise lazily manipulating an http connection.

Middleware are only used when it is necessary to modify the control flow of a Request flow, hijack the entire handling of a Request, check an incoming Request, or to do final post-processing. This covers areas such as routing, mounting, static asset serving, final template rendering, authentication, and logging.

Iron comes with only basic modifiers for setting the status, body, and various headers, and the infrastructure for creating modifiers, plugins, and middleware. No plugins or middleware are bundled with Iron.

Performance

Iron averages 72,000+ requests per second for hello world and is mostly IO-bound, spending over 70% of its time in the kernel send-ing or recv-ing data.*

* Numbers from profiling on my OS X machine, your mileage may vary.

Core Extensions

Iron aims to fill a void in the Rust web stack - a high level framework that is extensible and makes organizing complex server code easy.

Extensions are painless to build. Some important ones are:

Middleware:

Plugins:

Both:

This allows for extremely flexible and powerful setups and allows nearly all of Iron's features to be swappable - you can even change the middleware resolution algorithm by swapping in your own Chain.

* Due to the rapidly evolving state of the Rust ecosystem, not everything builds all the time. Please be patient and file issues for breaking builds, we're doing our best.

Underlying HTTP Implementation

Iron is based on and uses hyper as its HTTP implementation, and lifts several types from it, including its header representation, status, and other core HTTP types. It is usually unnecessary to use hyper directly when using Iron, since Iron provides a facade over hyper's core facilities, but it is sometimes necessary to depend on it as well.

Installation

If you're using Cargo, just add Iron to your Cargo.toml:

[dependencies.iron]
version = "*"

The documentation is hosted online and auto-updated with each successful release. You can also use cargo doc to build a local copy.

Check out the examples directory!

You can run an individual example using cargo run --bin example-name inside the examples directory. Note that for benchmarking you should make sure to use the --release flag, which will cause cargo to compile the entire toolchain with optimizations. Without --release you will get truly sad numbers.

Getting Help

Feel free to ask questions as github issues in this or other related repos.

The best place to get immediate help is on IRC, on any of these channels on the mozilla network:

  • #rust-webdev
  • #iron
  • #rust

One of the maintainers or contributors is usually around and can probably help. We encourage you to stop by and say hi and tell us what you're using Iron for, even if you don't have any questions. It's invaluable to hear feedback from users and always nice to hear if someone is using the framework we've worked on.

Maintainers

Jonathan Reem (reem) is the core maintainer and author of Iron.

Commit Distribution (as of 8e55759):

Jonathan Reem (415)
Zach Pomerantz (123)
Michael Sproul (9)
Patrick Tran (5)
Corey Richardson (4)
Bryce Fisher-Fleig (3)
Barosl Lee (2)
Christoph Burgdorf (2)
da4c30ff (2)
arathunku (1)
Cengiz Can (1)
Darayus (1)
Eduardo Bautista (1)
Mehdi Avdi (1)
Michael Sierks (1)
Nerijus Arlauskas (1)
SuprDewd (1)

License

MIT

persistent's People

Contributors

aerialx avatar brycefisher avatar calebmer avatar djzin avatar duelinmarkers avatar eduardobautista avatar emberian avatar fuchsnj avatar iori-yja avatar klieth avatar lambda-fairy avatar phlmn avatar reem avatar s-panferov avatar sinkuu avatar skylerlipthay avatar steveklabnik avatar theptrk avatar trotter avatar untitaker avatar zgtm avatar zzmp avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

persistent's Issues

Allow to create Read/Write/State with an Arc<T>, not only just T

Sometimes it would be useful to pass an already created Arc<T> to the persistent middleware constructors instead of just T. For example, in my program a Db value is shared by the HTTP server and another part of the program. Therefore, when the HTTP server starts, there already is an Arc<Mutex<Db>> value which I'd like to use in my handlers. Naturally, I could use Read<Arc<Mutex<Db>>>, but then I get Arc<Arc<Mutex<Db>>>> in handlers which is kinda bad with its double Arc layer.

Update README

The README suggests using version 0.0.6 which is considerably old now that 0.2.0 is out. I also think some more examples would be beneficial since this crate provides a solution to sharing data amongst Iron handlers.

Getter for data

I'm trying to read the data inside a persistent struct from outside an Iron request. I can't see any way to do this other than forking the library. Am I missing something?

Is there any reason not to implement a getter for data?

explicit lifetimes now needed

With these versions:

$ rustc -v
rustc 0.12.0-nightly (43fd61981 2014-09-22 23:50:30 +0000)
$ cargo version
cargo 0.0.1-pre-nightly (a54cb70 2014-09-23 01:34:57 +0000)

I get these errors:

   Compiling persistent v0.1.0 (https://github.com/iron/persistent.git#c8e75f5b)
src/lib.rs:88:1: 88:70 error: the parameter type `D` may not live long enough; consider adding an explicit lifetime bound `D:'static`...
src/lib.rs:88 impl<P, D> Assoc<Arc<RWLock<D>>> for State<P, D> where P: Assoc<D> {}
              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:88:1: 88:70 note: ...so that the parameter `<generic #0>`, when instantiated with `alloc::arc::Arc<sync::lock::RWLock<D>>`, will meet its declared lifetime bou
nds.
src/lib.rs:88 impl<P, D> Assoc<Arc<RWLock<D>>> for State<P, D> where P: Assoc<D> {}
              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:88:1: 88:70 error: the parameter type `D` may not live long enough; consider adding an explicit lifetime bound `D:'static`...
src/lib.rs:88 impl<P, D> Assoc<Arc<RWLock<D>>> for State<P, D> where P: Assoc<D> {}
              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:88:1: 88:70 note: ...so that the parameter `<generic #0>`, when instantiated with `State<P,D>`, will meet its declared lifetime bounds.
src/lib.rs:88 impl<P, D> Assoc<Arc<RWLock<D>>> for State<P, D> where P: Assoc<D> {}
              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:88:1: 88:70 error: the parameter type `D` may not live long enough; consider adding an explicit lifetime bound `D:'static`...
src/lib.rs:88 impl<P, D> Assoc<Arc<RWLock<D>>> for State<P, D> where P: Assoc<D> {}
              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:88:1: 88:70 note: ...so that the parameter `<generic #0>`, when instantiated with `State<P,D>`, will meet its declared lifetime bounds.
src/lib.rs:88 impl<P, D> Assoc<Arc<RWLock<D>>> for State<P, D> where P: Assoc<D> {}
              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:89:1: 89:61 error: the parameter type `D` may not live long enough; consider adding an explicit lifetime bound `D:'static`...
src/lib.rs:89 impl<P, D> Assoc<Arc<D>> for Read<P, D> where P: Assoc<D> {}
              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:89:1: 89:61 note: ...so that the parameter `<generic #0>`, when instantiated with `alloc::arc::Arc<D>`, will meet its declared lifetime bounds.
src/lib.rs:89 impl<P, D> Assoc<Arc<D>> for Read<P, D> where P: Assoc<D> {}
              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:89:1: 89:61 error: the parameter type `D` may not live long enough; consider adding an explicit lifetime bound `D:'static`...
src/lib.rs:89 impl<P, D> Assoc<Arc<D>> for Read<P, D> where P: Assoc<D> {}
              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:89:1: 89:61 note: ...so that the parameter `<generic #0>`, when instantiated with `Read<P,D>`, will meet its declared lifetime bounds.
src/lib.rs:89 impl<P, D> Assoc<Arc<D>> for Read<P, D> where P: Assoc<D> {}
              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:89:1: 89:61 error: the parameter type `D` may not live long enough; consider adding an explicit lifetime bound `D:'static`...
src/lib.rs:89 impl<P, D> Assoc<Arc<D>> for Read<P, D> where P: Assoc<D> {}
              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:89:1: 89:61 note: ...so that the parameter `<generic #0>`, when instantiated with `Read<P,D>`, will meet its declared lifetime bounds.
src/lib.rs:89 impl<P, D> Assoc<Arc<D>> for Read<P, D> where P: Assoc<D> {}
              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:90:1: 90:69 error: the parameter type `D` may not live long enough; consider adding an explicit lifetime bound `D:'static`...
src/lib.rs:90 impl<P, D> Assoc<Arc<Mutex<D>>> for Write<P, D> where P: Assoc<D> {}
              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:90:1: 90:69 note: ...so that the parameter `<generic #0>`, when instantiated with `alloc::arc::Arc<sync::lock::Mutex<D>>`, will meet its declared lifetime boun
ds.
src/lib.rs:90 impl<P, D> Assoc<Arc<Mutex<D>>> for Write<P, D> where P: Assoc<D> {}
              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:90:1: 90:69 error: the parameter type `D` may not live long enough; consider adding an explicit lifetime bound `D:'static`...
src/lib.rs:90 impl<P, D> Assoc<Arc<Mutex<D>>> for Write<P, D> where P: Assoc<D> {}
              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:90:1: 90:69 note: ...so that the parameter `<generic #0>`, when instantiated with `Write<P,D>`, will meet its declared lifetime bounds.
src/lib.rs:90 impl<P, D> Assoc<Arc<Mutex<D>>> for Write<P, D> where P: Assoc<D> {}
              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:90:1: 90:69 error: the parameter type `D` may not live long enough; consider adding an explicit lifetime bound `D:'static`...
src/lib.rs:90 impl<P, D> Assoc<Arc<Mutex<D>>> for Write<P, D> where P: Assoc<D> {}
              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/lib.rs:90:1: 90:69 note: ...so that the parameter `<generic #0>`, when instantiated with `Write<P,D>`, will meet its declared lifetime bounds.
src/lib.rs:90 impl<P, D> Assoc<Arc<Mutex<D>>> for Write<P, D> where P: Assoc<D> {}
              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
error: aborting due to 9 previous errors
Build failed, waiting for other jobs to finish...
Could not compile `persistent`.

I'm going try to fix this.

update for iron 0.4.0

It would be nice if it could be updated for iron 0.4.0 to have latest of iron, persist, etc... work nice together.

Cheers, Joost

PersistentInto for T is Failing with mysql::Pool

I get the following output when trying to persist the mysql::Pool struct.

error[E0277]: the trait bound `mysql::conn::pool::Pool: persistent::PersistentInto<std::sync::Arc<mysql::Pool>>` is not satisfied
  --> src/bin/bin.rs:70:23
   |
70 |     chain.link_before(Read::<DBKey>::one(pool));
   |                       ^^^^^^^^^^^^^^^^^^ trait `mysql::conn::pool::Pool: persistent::PersistentInto<std::sync::Arc<mysql::Pool>>` not satisfied
   |
   = note: required by `<persistent::Read<P>>::one`

I thought it might be due a mismatched dependency so I forked the and set the iron dependency to 0.5.1 (which is what I am using), but this didn't work as well. Any ideas on how to resolve this?

Relicense under dual MIT/Apache-2.0

This issue was automatically generated. Feel free to close without ceremony if
you do not agree with re-licensing or if it is not possible for other reasons.
Respond to @cmr with any questions or concerns, or pop over to
#rust-offtopic on IRC to discuss.

You're receiving this because someone (perhaps the project maintainer)
published a crates.io package with the license as "MIT" xor "Apache-2.0" and
the repository field pointing here.

TL;DR the Rust ecosystem is largely Apache-2.0. Being available under that
license is good for interoperation. The MIT license as an add-on can be nice
for GPLv2 projects to use your code.

Why?

The MIT license requires reproducing countless copies of the same copyright
header with different names in the copyright field, for every MIT library in
use. The Apache license does not have this drawback. However, this is not the
primary motivation for me creating these issues. The Apache license also has
protections from patent trolls and an explicit contribution licensing clause.
However, the Apache license is incompatible with GPLv2. This is why Rust is
dual-licensed as MIT/Apache (the "primary" license being Apache, MIT only for
GPLv2 compat), and doing so would be wise for this project. This also makes
this crate suitable for inclusion and unrestricted sharing in the Rust
standard distribution and other projects using dual MIT/Apache, such as my
personal ulterior motive, the Robigalia project.

Some ask, "Does this really apply to binary redistributions? Does MIT really
require reproducing the whole thing?" I'm not a lawyer, and I can't give legal
advice, but some Google Android apps include open source attributions using
this interpretation. Others also agree with
it
.
But, again, the copyright notice redistribution is not the primary motivation
for the dual-licensing. It's stronger protections to licensees and better
interoperation with the wider Rust ecosystem.

How?

To do this, get explicit approval from each contributor of copyrightable work
(as not all contributions qualify for copyright, due to not being a "creative
work", e.g. a typo fix) and then add the following to your README:

## License

Licensed under either of

 * Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
 * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)

at your option.

### Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted
for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any
additional terms or conditions.

and in your license headers, if you have them, use the following boilerplate
(based on that used in Rust):

// Copyright 2016 persistent developers
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

It's commonly asked whether license headers are required. I'm not comfortable
making an official recommendation either way, but the Apache license
recommends it in their appendix on how to use the license.

Be sure to add the relevant LICENSE-{MIT,APACHE} files. You can copy these
from the Rust repo for a plain-text
version.

And don't forget to update the license metadata in your Cargo.toml to:

license = "MIT/Apache-2.0"

I'll be going through projects which agree to be relicensed and have approval
by the necessary contributors and doing this changes, so feel free to leave
the heavy lifting to me!

Contributor checkoff

To agree to relicensing, comment with :

I license past and future contributions under the dual MIT/Apache-2.0 license, allowing licensees to chose either at their option.

Or, if you're a contributor, you can check the box in this repo next to your
name. My scripts will pick this exact phrase up and check your checkbox, but
I'll come through and manually review this issue later as well.

Issue when impl Trait Key

Hi,

I have a issue when i impl Key trait in Struct that include Arcr2d2::Pool type field.
could you help me sort out the issue? Thanks!

// This is struct 
pub struct App {
    pool: Arc<r2d2::Pool<PostgresConnectionManager>>,
}
src/main.rs:63:5: 63:53 error: the trait bound `r2d2_postgres::PostgresConnectionManager: r2d2::ManageConnection` is not satisfied [E0277]
src/main.rs:63     pool: Arc<r2d2::Pool<PostgresConnectionManager>>,
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/main.rs:63:5: 63:53 help: run `rustc --explain E0277` to see a detailed explanation
src/main.rs:63:5: 63:53 note: required by `r2d2::Pool`
src/main.rs:66:6: 66:9 error: the trait bound `r2d2_postgres::PostgresConnectionManager: r2d2::ManageConnection` is not satisfied [E0277]
src/main.rs:66 impl Key for App { type Value = App; }
                    ^~~
src/main.rs:66:6: 66:9 help: run `rustc --explain E0277` to see a detailed explanation
src/main.rs:66:6: 66:9 note: required because of the requirements on the impl of `std::marker::Reflect` for `alloc::arc::ArcInner<r2d2::SharedPool<r2d2_postgres::PostgresConnectionManager>>`
src/main.rs:66:6: 66:9 note: required because of the requirements on the impl of `std::marker::Reflect` for `std::marker::PhantomData<alloc::arc::ArcInner<r2d2::SharedPool<r2d2_postgres::PostgresConnectionManager>>>`
src/main.rs:66:6: 66:9 note: required because of the requirements on the impl of `std::marker::Reflect` for `std::ptr::Shared<alloc::arc::ArcInner<r2d2::SharedPool<r2d2_postgres::PostgresConnectionManager>>>`
src/main.rs:66:6: 66:9 note: required because of the requirements on the impl of `std::marker::Reflect` for `std::sync::Arc<r2d2::SharedPool<r2d2_postgres::PostgresConnectionManager>>`
src/main.rs:66:6: 66:9 note: required because of the requirements on the impl of `std::marker::Reflect` for `r2d2::Pool<r2d2_postgres::PostgresConnectionManager>`
src/main.rs:66:6: 66:9 note: required because of the requirements on the impl of `std::marker::Reflect` for `alloc::arc::ArcInner<r2d2::Pool<r2d2_postgres::PostgresConnectionManager>>`
src/main.rs:66:6: 66:9 note: required because of the requirements on the impl of `std::marker::Reflect` for `std::marker::PhantomData<alloc::arc::ArcInner<r2d2::Pool<r2d2_postgres::PostgresConnectionManager>>>`
src/main.rs:66:6: 66:9 note: required because of the requirements on the impl of `std::marker::Reflect` for `std::ptr::Shared<alloc::arc::ArcInner<r2d2::Pool<r2d2_postgres::PostgresConnectionManager>>>`
src/main.rs:66:6: 66:9 note: required because of the requirements on the impl of `std::marker::Reflect` for `std::sync::Arc<r2d2::Pool<r2d2_postgres::PostgresConnectionManager>>`
src/main.rs:66:6: 66:9 note: required because of the requirements on the impl of `std::marker::Reflect` for `App`
src/main.rs:66:6: 66:9 note: required by `iron::typemap::Key`
src/main.rs:89:5: 91:6 error: the trait bound `r2d2_postgres::PostgresConnectionManager: r2d2::ManageConnection` is not satisfied [E0277]
src/main.rs:89     pub fn conn(&self) -> Result<Connection, Error> {
src/main.rs:90         Ok(try!(self.pool.get()))
src/main.rs:91     }
src/main.rs:89:5: 91:6 help: run `rustc --explain E0277` to see a detailed explanation
src/main.rs:89:5: 91:6 note: required by `r2d2::PooledConnection`

example with a trait

Could you provide an example that uses a Trait? Or do you know a repository where I can find code examples?
Here is what I'd like to do:

extern crate iron;
extern crate mount;
extern crate persistent;

use std::io;
use iron::prelude::*;
use iron::typemap::Key;
use persistent::State;
use mount::Mount;

struct X;

trait Db {
    fn get(&mut self, id: &str) -> Result<X, io::Error>; 
}

struct Server {
    chain: Chain
}

fn create_server<D: Db + Key>(db: D) -> Server {

    let mount = Mount::new();
    let chain = Chain::new(mount);
    chain.link(State::<D>::both(db));

    Server {
        chain: chain
    }
}

struct Store; 

impl Db for Store {
    fn get(&mut self, id: &str) -> Result<X, io::Error> {
        Ok(X{})
    } 
}

impl Key for Store {
    type Value = Store;
}

fn main() {

    let store = Store {};
    let s = create_server(store);
}

edit: renamed issue & changed content

Unstable feature not compiling with rustc beta

Compiling persistent v0.0.4
/home/vesakaihlavirta/.cargo/registry/src/github.com-1ecc6299db9ec823/persistent-0.0.4/src/lib.rs:3:1: 3:18 error: unstable feature
/home/vesakaihlavirta/.cargo/registry/src/github.com-1ecc6299db9ec823/persistent-0.0.4/src/lib.rs:3 #![feature(core)]
                                                                                                    ^~~~~~~~~~~~~~~~~
note: this feature may not be used in the beta release channel
error: aborting due to previous error
   Compiling router v0.0.10
Build failed, waiting for other jobs to finish...
Could not compile `persistent`.

Example in README does not compile

The example on the front page does not compile anymore

src/web.rs:20:21: 20:53 error: type `&mut iron::request::Request` does not implement any method in scope named `get`
src/web.rs:20     let mutex = req.get::<Write<HitCounter, uint>>().unwrap();
                                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/web.rs:23:5: 23:11 error: the type of this value must be known in this context
src/web.rs:23     *count += 1;
                  ^~~~~~
error: aborting due to 2 previous errors

I've tried several fixes but the magic of typemap makes it really unintuitive.

Attempt 1 based on TypeMap's README: let mutex = req.extensions.find::<Write<HitCounter, uint>>().unwrap();

src/web.rs:20:17: 20:65 error: incorrect number of type parameters given for this method [E0036]
src/web.rs:20     let mutex = req.extensions.find::<Write<HitCounter, uint>>().unwrap();
                              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Attempt 2: let mutex = req.extensions::<Write<HitCounter, uint>>.find().unwrap();

src/web.rs:21:21: 21:26 error: the type of this value must be known in this context
src/web.rs:21     let mut count = mutex.lock();
                                  ^~~~~
src/web.rs:23:5: 23:11 error: the type of this value must be known in this context
src/web.rs:23     *count += 1;
                  ^~~~~~
error: aborting due to 2 previous errors

Every other attempt fails with a similar error. My guess is the the type information is lost in all the casting and magic, but I have no idea where it is or how to fix it

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.