pub struct Hentai {
    pub id: u32,
    pub url: String,
    pub title: Title,
    pub tags: Vec<Tag>,
    pub num_pages: u32,
    pub media_id: String,
    pub scanlator: String,
    pub cover_url: String,
    pub num_favorites: u32,
    pub thumbnail_url: String,
    pub image_urls: Vec<String>,
    pub upload_date: DateTime<Utc>,
}
Expand description

The main object containing the formatted information retrieved from nhentai. The raw image data is converted to into image URLs. A brief explanation of each field is located below.

  • id is the six-digit code of the doujin. This is redundant if you are using the Hentai::new() constructor.
  • url is the direct link to the doujin created from the provided six-digit code.
  • scanlator is the user that created translations for the doujin (not always present).
  • Fields suffixed with “url” or “urls” are links to the doujin’s image files.
  • Fields starting with “num” are statistics provided by nhentai. These may not be accurate for newly uploaded doujins.
  • title contains the three different titles for the doujin provided by nhentai.
  • Likewise, tags contains all the tags for the doujin.
  • media_id is the separate code that nhentai uses to denote where the image files for doujins are from. You will see this in the image urls (it is unrelated to the six-digit codes).
  • upload_date is a chrono::DateTime object that indicates when the doujin was uploaded to nhentai. This is not the creation date of the doujin.

Fields

id: u32url: Stringtitle: Titletags: Vec<Tag>num_pages: u32media_id: Stringscanlator: Stringcover_url: Stringnum_favorites: u32thumbnail_url: Stringimage_urls: Vec<String>upload_date: DateTime<Utc>

Implementations

Generates a new Hentai object for the provided six-digit code.

This makes a request to the primary nhentai endpoint located at /api/gallery/{id}. The JSON response is deserialized and converted into a Hentai object. This can fail at several stages, so it is important to handle the result accordingly. To make things simpler, Result<Hentai, HentaiError> is used.

A malformed code may result in an invalid url (http::uri::InvalidUri), the request to the endpoint may fail (hyper::Error), or the JSON response may be invalid (serde_json::Error).

More information about the Website enum can be found in its section. The sample below depends on tokio.

use hentai::{Hentai, Result, Website};

#[tokio::main]
async fn main() -> Result<()> {
    let response = Hentai::new(165961, Website::NET).await?;
    println!("{:?}", response); // makes use of the Debug trait on Hentai

    Ok(())
}

Generates a Hentai object for a randomly selected doujin from nhentai’s random endpoint.

A six-digit code is taken from the response headers from this request. If the code cannot be retrieved from the header, the following errors can be raised:

The sample below depends on tokio.

use hentai::{Hentai, Result, Website};

#[tokio::main]
async fn main() -> Result<()> {
    let response = Hentai::random(Website::XXX).await?;
    println!("{:?}", response);

    Ok(())
}

Generates a new Hentai object from the doujin JSON located at the provided file path.

This may fail if there is not a file at the provided path (std::io::Error), or if the contents of the file are invalid (serde_json::Error).

The sample below assumes that you have a valid doujin JSON file called sample.json in the same directory as the executable.

use hentai::{Hentai, Result, Website};
use std::env;

fn main() -> Result<()> {
    let mut path = env::current_exe()?;
    path.pop();
    path.push("sample.json");

    let response = Hentai::from_json(path, Website::XXX)?;
    println!("{:?}", response);

    Ok(())
}

Trait Implementations

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.