pub struct Attachment {}Expand description
File attachment metadata.
Fields§
§id: u64§filename: StringUnixtime + microtime upload identifier; this is afterall the filename on 4chan CDN.
ext: StringOriginal filename the user uploaded (no extension).
size: u64Extension, including the leading dot (e.g. ".jpg").
md5: StringSize in bytes.
width: i3224-character base64-packed MD5.
height: i32§thumbnail_width: i32§thumbnail_height: i32§spoiler: bool§custom_spoiler: Option<u8>§deleted: bool§mobile_optimized: boolImplementations§
Source§impl Attachment
impl Attachment
Sourcepub fn url(&self, board: &str) -> String
pub fn url(&self, board: &str) -> String
Full-resolution URL on i.4cdn.org.
Examples found in repository?
examples/poll_thread.rs (line 69)
57fn print_post(board: &str, p: &Post) {
58 let who = match (&p.trip, &p.id) {
59 (Some(t), Some(id)) => format!("{} {} ({})", p.name, t, id),
60 (Some(t), None) => format!("{} {}", p.name, t),
61 (None, Some(id)) => format!("{} ({})", p.name, id),
62 (None, None) => p.name.clone(),
63 };
64 println!("--- >>{} {} [{}] ---", p.no, who, p.now);
65 if let Some(sub) = &p.sub {
66 println!("Subject: {}", sub);
67 }
68 if let Some(att) = &p.attachment {
69 println!("File: {} ({} bytes)", att.url(board), att.size);
70 }
71 if let Some(com) = &p.com {
72 println!("{}", com);
73 }
74 println!();
75}More examples
examples/catalog_images.rs (line 16)
7async fn main() -> chan::Result<()> {
8 let board = env::args().nth(1).unwrap_or_else(|| "po".to_string());
9 let client = chan::Client::new();
10 let catalog = client.get_board_catalog(&board).await?;
11
12 let mut count = 0usize;
13 for thread in catalog.threads() {
14 if let Some(att) = &thread.op.attachment {
15 if !att.is_animated() {
16 println!("{}", att.url(&board));
17 count += 1;
18 }
19 }
20 for reply in &thread.last_replies {
21 if let Some(att) = &reply.attachment {
22 if !att.is_animated() {
23 println!("{}", att.url(&board));
24 count += 1;
25 }
26 }
27 }
28 }
29 eprintln!("/{}/: {} still-image URLs", board, count);
30 Ok(())
31}Sourcepub fn thumbnail_url(&self, board: &str) -> String
pub fn thumbnail_url(&self, board: &str) -> String
Thumbnail URL. Always a compressed JPEG, regardless of the original extension.
pub fn is_video(&self) -> bool
Sourcepub fn is_animated(&self) -> bool
pub fn is_animated(&self) -> bool
Examples found in repository?
examples/catalog_images.rs (line 15)
7async fn main() -> chan::Result<()> {
8 let board = env::args().nth(1).unwrap_or_else(|| "po".to_string());
9 let client = chan::Client::new();
10 let catalog = client.get_board_catalog(&board).await?;
11
12 let mut count = 0usize;
13 for thread in catalog.threads() {
14 if let Some(att) = &thread.op.attachment {
15 if !att.is_animated() {
16 println!("{}", att.url(&board));
17 count += 1;
18 }
19 }
20 for reply in &thread.last_replies {
21 if let Some(att) = &reply.attachment {
22 if !att.is_animated() {
23 println!("{}", att.url(&board));
24 count += 1;
25 }
26 }
27 }
28 }
29 eprintln!("/{}/: {} still-image URLs", board, count);
30 Ok(())
31}Trait Implementations§
Source§impl Clone for Attachment
impl Clone for Attachment
Source§fn clone(&self) -> Attachment
fn clone(&self) -> Attachment
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for Attachment
impl Debug for Attachment
Auto Trait Implementations§
impl Freeze for Attachment
impl RefUnwindSafe for Attachment
impl Send for Attachment
impl Sync for Attachment
impl Unpin for Attachment
impl UnsafeUnpin for Attachment
impl UnwindSafe for Attachment
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