Skip to main content

ProceedingJoinPoint

Struct ProceedingJoinPoint 

Source
pub struct ProceedingJoinPoint<'a> { /* private fields */ }
Expand description

A proceeding joinpoint that can be used in “around” advice.

This type wraps the original function execution and allows aspects to control when (or if) the function runs.

§Example

use aspect_core::prelude::*;
use std::any::Any;

struct TimingAspect;

impl Aspect for TimingAspect {
    fn around(&self, pjp: ProceedingJoinPoint) -> Result<Box<dyn Any>, AspectError> {
        let start = std::time::Instant::now();
        let result = pjp.proceed()?;
        let elapsed = start.elapsed();
        println!("Execution took: {:?}", elapsed);
        Ok(result)
    }
}

Implementations§

Source§

impl<'a> ProceedingJoinPoint<'a>

Source

pub fn new<F>(f: F, context: JoinPoint) -> Self
where F: FnOnce() -> Result<Box<dyn Any>, AspectError> + 'a,

Creates a new ProceedingJoinPoint.

§Parameters
  • f: The original function to execute
  • context: Information about the joinpoint
Source

pub fn proceed(self) -> Result<Box<dyn Any>, AspectError>

Proceeds with the original function execution.

This consumes the ProceedingJoinPoint and executes the wrapped function.

§Returns

The result of the function execution.

§Example
fn around(&self, pjp: ProceedingJoinPoint) -> Result<Box<dyn Any>, AspectError> {
    println!("Before proceed");
    let result = pjp.proceed()?;
    println!("After proceed");
    Ok(result)
}
Source

pub fn context(&self) -> &JoinPoint

Returns a reference to the joinpoint context.

§Example
fn around(&self, pjp: ProceedingJoinPoint) -> Result<Box<dyn Any>, AspectError> {
    let ctx = pjp.context();
    println!("Calling: {}", ctx.function_name);
    pjp.proceed()
}

Trait Implementations§

Source§

impl<'a> Debug for ProceedingJoinPoint<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.