Git Product home page Git Product logo

persistent's Issues

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.

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`.

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 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

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?

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

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.

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

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.

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?

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.

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.