11 stable releases

new 1.1.3 Feb 20, 2021
1.1.1 Feb 11, 2021
1.1.0 Jan 9, 2021
1.0.5 Dec 27, 2020

#92 in Asynchronous

Download history 60/week @ 2020-12-09 11/week @ 2020-12-16 15/week @ 2020-12-23 8/week @ 2020-12-30 35/week @ 2021-01-06 16/week @ 2021-01-13 16/week @ 2021-01-20 1/week @ 2021-01-27 10/week @ 2021-02-03 118/week @ 2021-02-10 57/week @ 2021-02-17

103 downloads per month

MPL-2.0 license

63KB
1K SLoC

KSoft.rs badge

A KSoft api wrapper written in pure Rust

Usage for asynchronous client

Cargo.toml

[dependencies.ksoft]
version = "1.1.3"

[dependencies.tokio]
version = "1.0"
features = ["macros"]

Usage example

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>;

ApiResponse example

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
    }
}

Usage for blocking client

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

Cargo.toml

[dependencies.ksoft]
version = "1.1.0"
default-features=false
features = ["blocking"]

Usage example

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
    }
}

Dependencies

~5–8.5MB
~193K SLoC