Skip to content

Commit

Permalink
Return refs to the next middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
sug0 committed Dec 2, 2024
1 parent 3fc8ed4 commit f77544c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
12 changes: 11 additions & 1 deletion crates/packet-forward/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,18 @@ pub struct PacketForwardMiddleware<M> {
}

impl<M> PacketForwardMiddleware<M> {
/// Return an immutable ref to the next middleware.
pub fn next(&self) -> &M {
&self.next
}

/// Return a mutable ref to the next middleware.
pub fn next_mut(&mut self) -> &mut M {
&mut self.next
}

/// Wrap an existing middleware in the PFM.
pub const fn next(next: M) -> Self {
pub const fn wrap(next: M) -> Self {
Self { next }
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/packet-forward/src/tests/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ fn failure_injection_err_msg(point: FailurePoint) -> String {
pub type DummyPfm = PacketForwardMiddleware<Store<DummyTransferModule>>;

pub fn get_dummy_pfm() -> DummyPfm {
PacketForwardMiddleware::next(Store::new(DummyTransferModule::new()))
PacketForwardMiddleware::wrap(Store::new(DummyTransferModule::new()))
}

pub fn get_dummy_coin(amount: u64) -> Coin<PrefixedDenom> {
Expand Down

0 comments on commit f77544c

Please sign in to comment.