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
fn find(id: i32) -> Option<T>
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!") }
fn all() -> Vec<T>
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) }
fn create(model: T) -> Result<(), Error>
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);