Trait json_api::Resource [] [src]

pub trait Resource {
    fn kind() -> Key;
fn id(&self) -> String;
fn to_ident(&self, ctx: &mut Context) -> Result<Identifier, Error>;
fn to_object(&self, ctx: &mut Context) -> Result<Object, Error>; }

A trait indicating that the given type can be represented as a resource.

Implementing this trait manually is not recommended. The resource! macro provides a friendly DSL that implements trait with some additional functionality.

Example

#[macro_use]
extern crate json_api;

struct Post(u64);

resource!(Post, |&self| {
    kind "posts";
    id self.0;
});

Required Methods

Returns a key containing the type of resource.

Example

use json_api::Resource;

let kind = Post::kind();
assert_eq!(kind, "posts");

Returns a given resource's id as a string.

Example

use json_api::Resource;

let post = Post(25);
assert_eq!(post.id(), "25");

Renders a given resource as an identifier object.

Calling this function directly is not recommended. It is much more ergonomic to use the json_api::to_doc function.

Renders a given resource as a resource object.

Calling this function directly is not recommended. It is much more ergonomic to use the json_api::to_doc function.

Implementors