Expand description
§aspect-core
Core abstractions for aspect-oriented programming in Rust.
This crate provides the fundamental traits and types for building and using aspects in Rust. Aspects help modularize cross-cutting concerns like logging, performance monitoring, caching, security, and more.
§Core Concepts
- Aspect: A module that encapsulates a cross-cutting concern
- JoinPoint: A point in program execution where an aspect can be applied
- Advice: The action taken by an aspect at a joinpoint
§Example
use aspect_core::prelude::*;
use std::any::Any;
// Define an aspect
#[derive(Default)]
struct Logger;
impl Aspect for Logger {
fn before(&self, ctx: &JoinPoint) {
println!("[ENTRY] {}", ctx.function_name);
}
fn after(&self, ctx: &JoinPoint, _result: &dyn Any) {
println!("[EXIT] {}", ctx.function_name);
}
}§Advice Types
- before: Runs before the target function
- after: Runs after successful execution
- after_error: Runs when an error occurs
- around: Wraps the entire function execution
§Thread Safety
All aspects must implement Send + Sync to be used across thread boundaries.
Re-exports§
pub use aspect::Aspect;pub use error::AspectError;pub use joinpoint::JoinPoint;pub use joinpoint::Location;pub use joinpoint::ProceedingJoinPoint;