Crates.io | jokeapi_rs |
lib.rs | jokeapi_rs |
version | 0.1.4 |
source | src |
created_at | 2021-06-01 03:09:59.231736 |
updated_at | 2021-07-01 04:18:25.007404 |
description | Rust wrapper for https://v2.jokeapi.dev/ |
homepage | |
repository | https://github.com/grvxs/jokeapi_rs |
max_upload_size | |
id | 404561 |
size | 46,565 |
Rust wrapper for JokeAPI
use jokeapi_rs::Joke;
fn main() {
println!("{}", Joke::new().fetch().joke());
}
Type can either be "single" or "twopart"
use jokeapi_rs::Joke;
fn main() {
println!("{}", Joke::new().of_type("single").fetch().joke());
}
use jokeapi_rs::Joke;
fn main() {
println!(
"{}",
Joke::new()
.categories(
["programming", "spooky"]
.iter()
.map(|x| x.to_string())
.collect()
)
.fetch()
.joke()
)
}
use jokeapi_rs::structs::joke::Data;
use jokeapi_rs::structs::joke::DataKind;
use jokeapi_rs::Joke;
fn main() {
let res: Data = Joke::new()
.of_type("single")
.categories(
["programming", "pun"]
.iter()
.map(|x| x.to_string())
.collect(),
)
.blacklist(["sexist", "nsfw"].iter().map(|x| x.to_string()).collect())
//.safe() // Uncomment to enable safe mode
.fetch();
// Get the joke
// .joke() method on res does the following for you
match res.kind.clone() {
DataKind::TwoPart { setup, delivery } => {
println!("{}\n{}", setup, delivery)
}
DataKind::Single { joke } => println!("{}", joke),
}
// Access all the json fields
println!("{:#?}", res);
}