[][src]Trait rustnao::ToJSON

pub trait ToJSON {
    fn to_json(&self) -> Result<String>;
fn to_json_pretty(&self) -> Result<String>; }

A trait to convert to JSON and pretty JSON strings.

Example

Implementing for a Sauce vector into a pretty JSON string:

use rustnao::{HandlerBuilder, ToJSON};
let handle = HandlerBuilder::new().api_key("your_api_key").num_results(999).db(999).build();
let result = handle.get_sauce("./tests/test.jpg", None, None);
if result.is_ok() {
	result.unwrap().to_json_pretty();
}

Required methods

fn to_json(&self) -> Result<String>

Converts to a Result containing a JSON string.

Example

use rustnao::{HandlerBuilder, ToJSON};
let handle = HandlerBuilder::new().api_key("your_api_key").num_results(999).db(999).build();
let result = handle.get_sauce("./tests/test.jpg", None, None);
if result.is_ok() {
	result.unwrap().to_json();
}

Errors

There may be a problem converting the object to a JSON string, so this will throw an Error if that is encountered.

fn to_json_pretty(&self) -> Result<String>

Converts to a Result containing a pretty JSON string.

Example

use rustnao::{HandlerBuilder, ToJSON};
let handle = HandlerBuilder::new().api_key("your_api_key").num_results(999).db(999).build();
let result = handle.get_sauce("./tests/test.jpg", None, None);
if result.is_ok() {
	result.unwrap().to_json_pretty();
}

Errors

There may be a problem converting the object to a JSON string, so this will throw an Error if that is encountered.

Loading content...

Implementations on Foreign Types

impl ToJSON for Vec<Sauce>[src]

fn to_json_pretty(&self) -> Result<String>[src]

Converts a Sauce vector into a pretty JSON string.

fn to_json(&self) -> Result<String>[src]

Converts a Sauce vector into a JSON string.

Loading content...

Implementors

Loading content...