Skip to content

Commit

Permalink
Add test and ChangeLog entry for VRc::map_dyn
Browse files Browse the repository at this point in the history
  • Loading branch information
tronical committed Jul 22, 2022
1 parent 3276d2b commit 2bf3f83
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
5 changes: 5 additions & 0 deletions helper_crates/vtable/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Changelog
All notable changes to this crate will be documented in this file.

## [0.1.9] - Unreleased

- Added `VRc::map_dyn`, the equivalent of `VRc::map` to create a `VRcMapped`
when the VRc is already type erased

## [0.1.8] - 2022-07-05

- Changed the representation of the different types to use NonNull
Expand Down
18 changes: 18 additions & 0 deletions helper_crates/vtable/tests/test_vrc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,24 @@ fn rc_map_test() {
assert!(def.upgrade().is_none());
}

#[test]
fn rc_map_dyn_test() {
fn get_struct_value(instance: &VRcMapped<AppVTable, SomeStruct>) -> u8 {
let field_ref = SomeStruct::FIELD_OFFSETS.e.apply_pin(instance.as_pin_ref());
*field_ref
}

let app_rc = AppStruct::new();
let app_dyn = VRc::into_dyn(app_rc);

let some_struct_ref = VRc::map_dyn(app_dyn.clone(), |app_dyn| {
let app_ref = VRef::downcast_pin(app_dyn).unwrap();
AppStruct::FIELD_OFFSETS.some.apply_pin(app_ref)
});

assert_eq!(get_struct_value(&some_struct_ref), 55);
}

#[test]
fn rc_map_origin() {
let app_rc = AppStruct::new();
Expand Down

0 comments on commit 2bf3f83

Please sign in to comment.