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 theScrapedItemtrait 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, andDebugtraits automatically - ScrapedItem Implementation: Provides the complete implementation of the
ScrapedItemtrait required by the framework - Type Safety: Maintains type safety while reducing boilerplate
- Performance: Generates efficient code without runtime overhead
Usage
use scraped_item;
// The macro generates all necessary implementations automatically
// including serialization, deserialization, and the ScrapedItem trait
How It Works
The #[scraped_item] macro generates:
#[derive(serde::Serialize, serde::Deserialize, Clone, Debug)]annotations- Complete implementation of the
ScrapedItemtrait with:as_any()method for type erasurebox_clone()method for creating boxed clonesto_json_value()method for converting to JSON values
License
This project is licensed under the MIT License - see the LICENSE file for details.