Crates.io | ksoft |
lib.rs | ksoft |
version | 1.1.4 |
source | src |
created_at | 2020-12-13 22:09:11.130041 |
updated_at | 2021-03-26 22:03:47.955935 |
description | KSoft.SI api wrapper written in pure Rust |
homepage | |
repository | https://github.com/KSoft-Si/KSoft.rs |
max_upload_size | |
id | 322533 |
size | 86,145 |
A KSoft api wrapper written in pure Rust
[dependencies.ksoft]
version = "1.1.4"
[dependencies.tokio]
version = "1.0"
features = ["macros"]
use ksoft::Client;
#[tokio::main]
async fn main() {
let client = Client::new("TOKEN HERE"); //create the client
if let Ok(meme) = client.images.random_meme().await { //try to get a random meme handling the possible error
//Do some logical stuff here...
} else {
//Error handling stuff
}
}
Also there is an extra error management tool, it is ApiResponse, its behaviour is the same as Result, as it is a renaming of it used to difference between an http error and an API error or unsuccessful response
pub type ApiResponse<S, E> = Result<S, E>;
use ksoft::Client;
#[tokio::main]
async fn main() {
let client = Client::new("TOKEN HERE"); //create the client
if let Ok(image) = client.images.get_image("image id here").await { //image var will be ApiResponse<Image, ImageError>
match image {
Ok(image) => {
//Do something with the image
},
Err(why) => { //In this case, why will be an ImageError struct
//Do some handling stuff
}
}
} else {
//Error handling stuff
}
}
This is an optional feature for those people that want a blocking client for non-asynchronous contexts
Both features cannot be enabled at the same time
[dependencies.ksoft]
version = "1.1.4"
default-features=false
features = ["blocking"]
use ksoft::blocking::Client;
fn main() {
let client = Client::new("TOKEN HERE"); //create the client
if let Ok(meme) = client.images.random_meme() { //try to get a random meme handling the possible error
//Do some logical stuff here...
} else {
//Error handling stuff
}
}