spider-macro
Procedural macros for the spider-lib web scraping framework.
spider-macro provides procedural macros that simplify the implementation of key traits in the spider-lib framework. This crate contains attribute macros that reduce boilerplate code when defining scraped data structures.
Getting Started
To use spider-macro, add it to your project's Cargo.toml:
[]
= "0.2" # Main framework
= "0.1" # Proc-macros for spider-lib
Available Macros
#[scraped_item]
The #[scraped_item] attribute macro automatically implements the necessary traits for a struct to be used as a ScrapedItem within the spider-lib framework. This macro eliminates the need for manual implementations of serialization, deserialization, cloning, and type conversion traits.
use scraped_item;
When applied to a struct, this macro automatically adds:
#[derive(serde::Serialize, serde::Deserialize, Clone, Debug)]- An implementation of the
ScrapedItemtrait with methods for type erasure, cloning, and JSON conversion
How It Works
The #[scraped_item] macro generates the following implementations:
serde::Serializeandserde::Deserializefor serialization/deserializationCloneandDebugfor common operations- Implementation of the
ScrapedItemtrait with:as_any()for type erasurebox_clone()for boxed cloningto_json_value()for JSON conversion
This allows your structs to seamlessly integrate with spider-lib's item processing pipeline without requiring manual boilerplate code.
License
This project is licensed under the MIT License - see the LICENSE file for details.