Skip to content

abiriadev/Nekos.life-rs

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Crates.io Crates.io docs.rs GitHub

nekoslife

Nekos.life wrapper for Rust.

About

this is nekos.life implementation for the rust programming language,
you can find out more information about nekos.life at their website and github.

this crate provides a way to interact with thier API, to convert the result into useful and readable types.

and provides both of async and blocking api as well.

Quick Start

first of all, you need to add below to your Cargo.toml:

[dependencies]
nekoslife = "0.2.1"

the easiest way to use this crate is seding single request to img endpoint,

// we need async context to use 'get' method.
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // 'get' method will return 'Future'.
    // so you have to use '.await' to get the result.
    // in this case, the return type
    // of the method is 'Result<String, Error>',
    // so we can use '?' operator here.
    let url: String =
        nekoslife::get(nekoslife::Category::Waifu).await?;

    // print out the recieved url
    println!("{url}");

    Ok(())
}

the get function is one of the most important functions,
it takes any type that implements IntoUrl trait, and this case, the Category enum is that type.

then it will return a Future of Result<UrlString, Error>.

you can also pass string instead of Category.

let result = nekoslife::get("neko").await?;

more information about strings and full list of available category variants, check out Category document.

Blocking

you can use blocking version of get function,

first, you need to enable the blocking feature from this crate.

[dependencies.nekoslife]
features = ["blocking"]

then, replace the get function with blocking::get.

// get the image url from 'Neko' category
let url = nekoslife::blocking::get(
    nekoslife::Category::Neko
)?;
// in this case, the return type will be 'String'

// then do something with the url.
println!("{url}");

for more information, check out the implementation and the blocking module.

Other Endpoints

you can use more endpoints (not just img endpoint),

for example, below uses OwOify endpoint.

// get owoified version of "hello, world"
let owo =
    nekoslife::get(nekoslife::OwOify("hello, world"))
        .await?;

// this will be converted version of our text.
assert_eq!(owo, "hewwo, wowwd");

for more information about text based endpoints, check out text module.

License

this crate is licensed under MIT license.

Documentation

check out the API documentation for more information.

Releases

No releases published

Packages

No packages published

Languages

  • Rust 100.0%