shindan_maker

Struct ShindanClient

source
pub struct ShindanClient { /* private fields */ }
Expand description

A client for interacting with Shindan Maker.

Implementations§

source§

impl ShindanClient

source

pub fn new(domain: ShindanDomain) -> Result<Self>

Creates a new ShindanClient with the specified domain.

§Arguments
  • domain - The domain to use.
§Examples
use shindan_maker::{ShindanClient, ShindanDomain};

#[tokio::main]
async fn main() {
    let client = ShindanClient::new(ShindanDomain::En);
    assert!(client.is_ok());
}
source

pub async fn get_title(&self, id: &str) -> Result<String>

Gets the title of a shindan with the specified ID.

§Arguments
  • id - The ID of the shindan.
§Examples
use std::error::Error;
use shindan_maker::{ShindanClient, ShindanDomain};

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
    let client = ShindanClient::new(ShindanDomain::En)?;
    let title = client.get_title("1218842").await?;
    println!("Title: {}", title);
    Ok(())
}
source

pub async fn get_text_result( &self, id: &str, name: &str, ) -> Result<ShindanTextResult>

Gets the text result of a shindan with the specified ID and name.

§Arguments
  • id - The ID of the shindan.
  • name - The name to use.
§Examples
§Basic usage
use std::error::Error;
use shindan_maker::{ShindanClient, ShindanDomain, ShindanTextResult};

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
    let client = ShindanClient::new(ShindanDomain::En)?;
    let result = client.get_text_result("1218842", "test_user").await?;

    let ShindanTextResult { title, content } = result;
    println!("Result title: {}", title);
    println!("Result content: {:#?}", content);

    Ok(())
}
§Printing text segments
use shindan_maker::{ShindanClient, ShindanDomain, ShindanTextResult};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = ShindanClient::new(ShindanDomain::En)?;
    let result = client.get_text_result("1218842", "test_user").await?;

    let ShindanTextResult { title, content } = result;

    println!("Result title: {}", title);

    let mut text = String::new();
    for segment in content.iter() {
        match segment.type_.as_str() {
            "text" => {
                text.push_str(&segment.get_text().unwrap());
            }
            "image" => {
                text.push_str(&segment.get_image_url().unwrap());
            }
            _ => {}
        }
    }
    println!("Result text: {}", text);

    Ok(())
}
§Filtering segments by type
use shindan_maker::{ShindanClient, ShindanDomain, filter_segments_by_type};
use serde_json::json;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = ShindanClient::new(ShindanDomain::En)?;
    let result = client.get_text_result("1218842", "test_user").await?;

    println!("Result title: {}", result.title);

    let text_segments = filter_segments_by_type(&result.content, "text");
    assert_eq!(text_segments.len(), 2);

    Ok(())
}

Trait Implementations§

source§

impl Clone for ShindanClient

source§

fn clone(&self) -> ShindanClient

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

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

fn in_current_span(self) -> Instrumented<Self>

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

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

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

source§

impl<T> ToOwned for T
where T: Clone,

source§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more