1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
extern crate serde;

use FromRequest;
use data::JsonApiData;
use params::JsonApiParams;
use params::JsonApiResource;
use status::Status;
use std;
use to_json::ToJson;

pub trait JsonGet
    where Self: JsonApiResource + ToJson
{
    type Error: std::error::Error + Send;
    type Context: FromRequest;

    fn find(id: Self::JsonApiIdType,
            params: &JsonApiParams<Self::FilterField, Self::SortField>,
            ctx: Self::Context)
            -> Result<Option<JsonApiData<Self::Attrs>>, Self::Error>
        where Status: for<'b> From<&'b Self::Error>;
}

pub trait JsonPost
    where Self: JsonApiResource + ToJson
{
    type Error: std::error::Error + Send;
    type Context: FromRequest;

    fn create(json: JsonApiData<Self::Attrs>,
              params: &JsonApiParams<Self::FilterField, Self::SortField>,
              ctx: Self::Context)
              -> Result<JsonApiData<Self::Attrs>, Self::Error>
        where Status: for<'b> From<&'b Self::Error>;
}

pub trait JsonPatch
    where Self: JsonApiResource + ToJson
{
    type Error: std::error::Error + Send;
    type Context: FromRequest;

    fn update(id: Self::JsonApiIdType,
              json: JsonApiData<Self::Attrs>,
              params: &JsonApiParams<Self::FilterField, Self::SortField>,
              ctx: Self::Context)
              -> Result<JsonApiData<Self::Attrs>, Self::Error>
        where Status: for<'b> From<&'b Self::Error>;
}

pub trait JsonIndex
    where Self: JsonApiResource + ToJson
{
    type Error: std::error::Error + Send;
    type Context: FromRequest;

    fn find_all(params: &JsonApiParams<Self::FilterField, Self::SortField>,
                ctx: Self::Context)
                -> Result<Vec<JsonApiData<Self::Attrs>>, Self::Error>
        where Status: for<'b> From<&'b Self::Error>;
}

pub trait JsonDelete
    where Self: JsonApiResource
{
    type Error: std::error::Error + Send;
    type Context: FromRequest;

    fn delete(id: Self::JsonApiIdType, ctx: Self::Context) -> Result<(), Self::Error>
        where Status: for<'b> From<&'b Self::Error>;
}