Skip to content

Commit

Permalink
test: add case for borrow extend across scopes
Browse files Browse the repository at this point in the history
  • Loading branch information
snormore committed Apr 25, 2024
1 parent 6269950 commit 01cc510
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,25 @@ mod tests {

use super::*;

#[test]
fn test_owned_ref_cell_extend_borrow_across_scopes() {
let cell = OwnedRefCell::new(10);

// Function that extends the mutable borrow across its original scope
fn extend_borrow<T>(mut borrow: OwnedRefMut<T>, modifier: T) -> OwnedRefMut<T>
where
T: std::ops::AddAssign,
{
*borrow += modifier;
borrow
}

let borrow_mut = cell.borrow_mut();
let extended_borrow = extend_borrow(borrow_mut, 5);

assert_eq!(*extended_borrow, 15);
}

#[test]
fn borrow_mut_modify_and_borrow_after_drop() {
let cell = OwnedRefCell::new(10);
Expand Down

0 comments on commit 01cc510

Please sign in to comment.