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 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(())
}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)