use generic params for arc_new_cyclic

This commit is contained in:
bdbai 2021-12-30 21:55:18 +08:00
parent ef472f1dc9
commit ce31cbc7a3
2 changed files with 8 additions and 2 deletions

View File

@ -415,7 +415,10 @@ impl<T> Rc<T> {
/// [`upgrade`]: Weak::upgrade
#[cfg(not(no_global_oom_handling))]
#[stable(feature = "arc_new_cyclic", since = "1.59.0")]
pub fn new_cyclic(data_fn: impl FnOnce(&Weak<T>) -> T) -> Rc<T> {
pub fn new_cyclic<F>(data_fn: F) -> Rc<T>
where
F: FnOnce(&Weak<T>) -> T,
{
// Construct the inner in the "uninitialized" state with a single
// weak reference.
let uninit_ptr: NonNull<_> = Box::leak(box RcBox {

View File

@ -392,7 +392,10 @@ impl<T> Arc<T> {
#[cfg(not(no_global_oom_handling))]
#[inline]
#[stable(feature = "arc_new_cyclic", since = "1.59.0")]
pub fn new_cyclic(data_fn: impl FnOnce(&Weak<T>) -> T) -> Arc<T> {
pub fn new_cyclic<F>(data_fn: F) -> Arc<T>
where
F: FnOnce(&Weak<T>) -> T,
{
// Construct the inner in the "uninitialized" state with a single
// weak reference.
let uninit_ptr: NonNull<_> = Box::leak(box ArcInner {