iron / iron/persistent

example with a trait

Open
#62 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
45
Forks
31
PR merge metrics
No merged PRs in 30d

Description

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:

```rust
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;
}

struct Server {
chain: Chain
}

fn create_server(db: D) -> Server {

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

Server {
chain: chain
}
}

struct Store;

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

impl Key for Store {
type Value = Store;
}

fn main() {

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

*edit:* renamed issue & changed content

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.