Skip to content

Commit 2ecb96e

Browse files
bors[bot]ltratt
andauthored
Merge #20
20: Add new_from_layout_unchecked. r=ptersilie a=ltratt The size/align checks are not cheap if this is called in a tight loop. Co-authored-by: Laurence Tratt <[email protected]>
2 parents 10fdb18 + 01ad15c commit 2ecb96e

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/gc.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,20 @@ impl<T> Gc<T> {
7171
tl.align()
7272
);
7373
}
74+
unsafe { Gc::new_from_layout_unchecked(layout) }
75+
}
76+
77+
/// Constructs a new `Gc<MaybeUninit<T>>` which is capable of storing data
78+
/// up-to the size permissible by `layout`.
79+
///
80+
/// This can be useful if you want to store a value with a custom layout,
81+
/// but have the collector treat the value as if it were T.
82+
///
83+
/// # Safety
84+
///
85+
/// The caller is responsible for ensuring that both `layout`'s size and
86+
/// alignment must match or exceed that required to store `T`.
87+
pub unsafe fn new_from_layout_unchecked(layout: Layout) -> Gc<MaybeUninit<T>> {
7488
Gc::from_inner(GcBox::new_from_layout(layout))
7589
}
7690
}

0 commit comments

Comments
 (0)