pub trait ToJSON {
// Required methods
fn to_json(&self) -> Result<String>;
fn to_json_pretty(&self) -> Result<String>;
}
Expand description
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::default().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§
Sourcefn to_json(&self) -> Result<String>
fn to_json(&self) -> Result<String>
Converts to a Result containing a JSON string.
§Example
use rustnao::{HandlerBuilder, ToJSON};
let handle = HandlerBuilder::default().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.
Sourcefn to_json_pretty(&self) -> Result<String>
fn to_json_pretty(&self) -> Result<String>
Converts to a Result containing a pretty JSON string.
§Example
use rustnao::{HandlerBuilder, ToJSON};
let handle = HandlerBuilder::default().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.