Trait jplaceholder::model::Model[][src]

pub trait Model<T> {
    fn find(id: i32) -> Option<T>;
fn all() -> Vec<T>;
fn create(model: T) -> Result<(), Error>; }

Required Methods

Finds a resource by its ID

Example

use jplaceholder::Model;
use jplaceholder::Post;
 
match Post::find(2) {
  Some(post) => println!("Title of the article {}: {}", post.id, post.title),
  None => println!("Article not found!")
}

Gets all of the resources

Example

use jplaceholder::Model;
use jplaceholder::Post;
 
let posts: Vec<Post> = Post::all();
for post in posts {
    println!("The title of the post {} is: {}", post.id, post.title)
}

Creates a new resource

Example

use jplaceholder::Model;
use jplaceholder::Post;
 
let post = Post{id: 5, title: String::from("Hey"), body: String::from("hehe"), user_id: 5};
Post::create(post);

Implementors