Core Concepts
Deep dive into the fundamental building blocks of aspect-rs.
What You’ll Learn
- The
Aspecttrait and its four advice methods JoinPointcontext and metadataProceedingJoinPointfor around advice- Advice types and when to use each
- Error handling with
AspectError
The Aspect Trait
Every aspect implements this trait:
#![allow(unused)]
fn main() {
pub trait Aspect: Send + Sync {
fn before(&self, ctx: &JoinPoint) {}
fn after(&self, ctx: &JoinPoint, result: &dyn Any) {}
fn after_throwing(&self, ctx: &JoinPoint, error: &dyn Any) {}
fn around(&self, pjp: ProceedingJoinPoint) -> Result<Box<dyn Any>, AspectError> {
pjp.proceed()
}
}
}
Key points:
- All methods have default implementations
- Must be
Send + Syncfor thread safety - Implement only the advice you need
Chapter Sections
- The Aspect Trait - Detailed API reference
- JoinPoint Context - Accessing execution metadata
- Advice Types - Comparison and use cases
- Error Handling - Working with errors and panics
See The Aspect Trait to continue.