pub struct ShindanClient { /* private fields */ }Expand description
A client for interacting with Shindan Maker.
Implementations§
source§impl ShindanClient
impl ShindanClient
sourcepub fn new(domain: ShindanDomain) -> Result<Self>
pub fn new(domain: ShindanDomain) -> Result<Self>
sourcepub fn init_browser(self) -> Result<Self>
pub fn init_browser(self) -> Result<Self>
Initializes the browser for image results.
§Examples
use shindan_maker::{ShindanClient, ShindanDomain};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = ShindanClient::new(ShindanDomain::En)?.init_browser();
assert!(client.is_ok());
Ok(())
}sourcepub async fn get_title(&self, id: &str) -> Result<String>
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(())
}sourcepub async fn get_text_result(
&self,
id: &str,
name: &str,
) -> Result<ShindanTextResult>
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(())
}sourcepub async fn get_image_result(
&self,
id: &str,
name: &str,
) -> Result<ShindanImageResult>
pub async fn get_image_result( &self, id: &str, name: &str, ) -> Result<ShindanImageResult>
Gets the image result of a shindan with the specified ID and name.
§Arguments
id- The ID of the shindan.name- The name to use.
§Examples
use std::error::Error;
use base64::Engine;
use shindan_maker::{ShindanClient, ShindanDomain};
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
let client = ShindanClient::new(ShindanDomain::En)?.init_browser()?;
let result = client.get_image_result("1218842", "test_user").await?;
println!("Result title: {}", result.title);
let png_data = base64::prelude::BASE64_STANDARD.decode(result.base64)?;
std::fs::write("test.png", png_data)?;
Ok(())
}Trait Implementations§
source§impl Clone for ShindanClient
impl Clone for ShindanClient
source§fn clone(&self) -> ShindanClient
fn clone(&self) -> ShindanClient
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for ShindanClient
impl !RefUnwindSafe for ShindanClient
impl Send for ShindanClient
impl Sync for ShindanClient
impl Unpin for ShindanClient
impl !UnwindSafe for ShindanClient
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit)source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more