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 theHentai::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: u32
url: String
title: Title
num_pages: u32
media_id: String
scanlator: String
cover_url: String
num_favorites: u32
thumbnail_url: String
image_urls: Vec<String>
upload_date: DateTime<Utc>
Implementations
sourceimpl Hentai
impl Hentai
sourcepub async fn new(code: u32, mode: Website) -> Result<Self>
pub async fn new(code: u32, mode: Website) -> Result<Self>
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(())
}
sourcepub async fn random(mode: Website) -> Result<Self>
pub async fn random(mode: Website) -> Result<Self>
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:
BaseError
,- ToStrError,
- ConversionError, depending on the format of the response.
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(())
}
sourcepub fn from_json(path: PathBuf, mode: Website) -> Result<Self>
pub fn from_json(path: PathBuf, mode: Website) -> Result<Self>
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
Auto Trait Implementations
impl RefUnwindSafe for Hentai
impl Send for Hentai
impl Sync for Hentai
impl Unpin for Hentai
impl UnwindSafe for Hentai
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Instruments this type with the provided Span
, returning an
Instrumented
wrapper. Read more