Skip to main content

Crate spider_macro

Crate spider_macro 

Source
Expand description

§spider-macro

Provides procedural macros for the spider-lib framework to reduce boilerplate code.

§Overview

The spider-macro crate contains procedural macros that automate the implementation of common traits and patterns used in the spider framework. These macros significantly reduce the amount of boilerplate code required when defining custom data structures for scraped items.

§Key Macros

  • #[scraped_item]: Derives the ScrapedItem trait along with necessary implementations for serialization, deserialization, cloning, and type conversions. This macro automatically implements all required traits for a struct to be used as a scraped item in the framework.

§Features

  • Automatic Trait Derivation: Implements Serialize, Deserialize, Clone, and Debug traits automatically
  • ScrapedItem Implementation: Provides the complete implementation of the ScrapedItem trait required by the framework
  • Type Safety: Maintains type safety while reducing boilerplate
  • Performance: Generates efficient code without runtime overhead

§Example

use spider_macro::scraped_item;

#[scraped_item]
struct Article {
    title: String,
    content: String,
    author: String,
    published_date: String,
}

// The macro generates all necessary implementations automatically
// including serialization, deserialization, and the ScrapedItem trait

Attribute Macros§

scraped_item
A procedural macro to derive the ScrapedItem trait.