pub struct Post {
pub title: String,
pub content: String,
pub featured_image_url: String,
pub publication_date: Option<String>,
pub author: Option<String>,
pub error: String,
}Expand description
Represents a scraped news post with all extracted metadata.
This structure contains the complete article data extracted from a website, including the Markdown-formatted content and associated metadata.
§Fields
- title: The article’s title extracted from the
<title>tag or meta tags - content: The article body, automatically converted to Markdown format
- featured_image_url: URL to the main article image from Open Graph meta tag
- publication_date: ISO 8601 formatted publication date if available
- author: Article author extracted from meta tags
- error: Empty string on success, contains error message if scraping failed
§Examples
// Create a post after scraping
let post = Post {
title: "Breaking News".to_string(),
content: "# Article Content\n\nThis is the main article...".to_string(),
featured_image_url: "https://example.com/image.jpg".to_string(),
publication_date: Some("2024-01-15T10:30:00Z".to_string()),
author: Some("Jane Doe".to_string()),
error: String::new(),
};
// Check if scraping was successful
assert!(post.error.is_empty());
assert_eq!(post.title, "Breaking News");§Error Handling
When scraping fails, the Post is still returned with an error message in the error field:
let failed_post = Post {
title: String::new(),
content: String::new(),
featured_image_url: String::new(),
publication_date: None,
author: None,
error: "Failed to fetch URL: connection timeout".to_string(),
};
if !failed_post.error.is_empty() {
eprintln!("Scraping failed: {}", failed_post.error);
}Fields§
§title: StringThe article title
content: StringThe article content in Markdown format
featured_image_url: StringURL to the featured/hero image
publication_date: Option<String>Publication date (ISO 8601 format, if available)
Article author (if available)
error: StringError message; empty string if no error
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Post
impl RefUnwindSafe for Post
impl Send for Post
impl Sync for Post
impl Unpin for Post
impl UnsafeUnpin for Post
impl UnwindSafe for Post
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