Skip to content

Commit

Permalink
Add docs for lib.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
kuy committed Sep 25, 2019
1 parent ed55603 commit 144928a
Showing 1 changed file with 111 additions and 1 deletion.
112 changes: 111 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,113 @@
//! Rust wrapper for [jsonbox.io](https://jsonbox.io/).
//!
//! ## Usage
//!
//! ```rust
//! // Declaration
//! use jsonbox::{Client, Error};
//! use serde::{Deserialize, Serialize};
//!
//! // Define struct
//! #[derive(Serialize, Deserialize)]
//! pub struct Data {
//! pub name: String,
//! pub message: String,
//! }
//!
//! fn main() -> Result<(), Error> {
//! // Create client with <BOX_ID>
//! let client = Client::new("enjoy_your_first_jsonbox_rs");
//!
//! // Put data
//! let data = Data {
//! name: "kuy".into(),
//! message: "Hello, Jsonbox!".into(),
//! };
//! let (record, meta) = client.create(&data)?;
//! println!("CREATE: data={:?}, meta={:?}", record, meta);
//!
//! Ok(())
//! }
//! ```
//!
//! ### CREATE
//!
//! ```rust
//! let data = Data {
//! name: "kuy".into(),
//! message: "Hello, Jsonbox!".into(),
//! };
//! let (record, meta) = client.create(&data)?;
//! println!("CREATE: data={:?}, meta={:?}", record, meta);
//! ```
//!
//! ### READ
//!
//! #### all (default parameters)
//!
//! ```rust
//! let all = client.read().all::<Data>()?;
//! println!("READ: len={}, all={:?}", all.len(), all);
//! ```
//!
//! #### with specific id
//!
//! ```rust
//! let (record, meta) = client.read().id("5d876d852a780700177c0557")?;
//! println!("READ: data={:?}, meta={:?}", record, meta);
//! ```
//!
//! #### with limit
//!
//! ```rust
//! let few = client.read().limit(10).run::<Data>()?;
//! println!("READ: len={}, few={:?}", few.len(), few);
//! ```
//!
//! #### with skip
//!
//! ```rust
//! let rest = client.read().skip(5).run::<Data>()?;
//! println!("READ: len={}, rest={:?}", rest.len(), rest);
//! ```
//!
//! #### with order (asc/desc)
//!
//! ```rust
//! let asc = client.read().order_by("name").run::<Data>()?;
//! println!("READ: len={}, asc={:?}", asc.len(), asc);
//!
//! let desc = client.read().order_by("count").desc().run::<Data>()?;
//! println!("READ: len={}, desc={:?}", desc.len(), desc);
//! ```
//!
//! #### with filter
//!
//! ```rust
//! let filtered = client
//! .read()
//! .filter_by("name:{}", "Json Box")
//! .run::<Data>()?;
//! println!("READ: len={}, filtered={:?}", filtered.len(), filtered);
//! ```
//!
//! See [baisc example](https://github.com/kuy/jsonbox-rs/blob/master/examples/basic.rs) or [official documentation](https://github.com/vasanthv/jsonbox#filtering) for more about filters.
//!
//! ### UPDATE
//!
//! ```rust
//! let data = Data::new("kuy", "Hello, Jsonbox!");
//! client.update("5d876d852a780700177c0557", &data)?;
//! println!("UPDATE: OK");
//! ```
//!
//! ### DELETE
//!
//! ```rust
//! client.delete("5d876d852a780700177c0557")?;
//! println!("DELETE: OK");
//! ```
#[cfg(test)]
extern crate matches;

Expand All @@ -6,5 +116,5 @@ mod error;
mod query_builder;
mod url;

pub use crate::error::{Error, Result};
pub use crate::client::Client;
pub use crate::error::{Error, Result};

0 comments on commit 144928a

Please sign in to comment.