Skip to content

Commit 0caccdf

Browse files
committed
Implement Fn traits for Rc and Arc
1 parent bad3bf6 commit 0caccdf

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

src/liballoc/rc.rs

+23
Original file line numberDiff line numberDiff line change
@@ -1436,6 +1436,29 @@ impl<T: ?Sized> fmt::Pointer for Rc<T> {
14361436
}
14371437
}
14381438

1439+
#[stable(feature = "rc_fn", since = "1.45.0")]
1440+
impl<A, F: Fn<A> + ?Sized> FnOnce<A> for Rc<F> {
1441+
type Output = <F as FnOnce<A>>::Output;
1442+
1443+
extern "rust-call" fn call_once(self, args: A) -> Self::Output {
1444+
<F as Fn<A>>::call(&*self, args)
1445+
}
1446+
}
1447+
1448+
#[stable(feature = "rc_fn", since = "1.45.0")]
1449+
impl<A, F: Fn<A> + ?Sized> FnMut<A> for Rc<F> {
1450+
extern "rust-call" fn call_mut(&mut self, args: A) -> Self::Output {
1451+
<F as Fn<A>>::call(self, args)
1452+
}
1453+
}
1454+
1455+
#[stable(feature = "rc_fn", since = "1.45.0")]
1456+
impl<A, F: Fn<A> + ?Sized> Fn<A> for Rc<F> {
1457+
extern "rust-call" fn call(&self, args: A) -> Self::Output {
1458+
<F as Fn<A>>::call(self, args)
1459+
}
1460+
}
1461+
14391462
#[stable(feature = "from_for_ptrs", since = "1.6.0")]
14401463
impl<T> From<T> for Rc<T> {
14411464
fn from(t: T) -> Self {

src/liballoc/sync.rs

+23
Original file line numberDiff line numberDiff line change
@@ -2066,6 +2066,29 @@ impl<T: ?Sized + Hash> Hash for Arc<T> {
20662066
}
20672067
}
20682068

2069+
#[stable(feature = "rc_fn", since = "1.45.0")]
2070+
impl<A, F: Fn<A> + ?Sized> FnOnce<A> for Arc<F> {
2071+
type Output = <F as FnOnce<A>>::Output;
2072+
2073+
extern "rust-call" fn call_once(self, args: A) -> Self::Output {
2074+
<F as Fn<A>>::call(&*self, args)
2075+
}
2076+
}
2077+
2078+
#[stable(feature = "rc_fn", since = "1.45.0")]
2079+
impl<A, F: Fn<A> + ?Sized> FnMut<A> for Arc<F> {
2080+
extern "rust-call" fn call_mut(&mut self, args: A) -> Self::Output {
2081+
<F as Fn<A>>::call(self, args)
2082+
}
2083+
}
2084+
2085+
#[stable(feature = "rc_fn", since = "1.45.0")]
2086+
impl<A, F: Fn<A> + ?Sized> Fn<A> for Arc<F> {
2087+
extern "rust-call" fn call(&self, args: A) -> Self::Output {
2088+
<F as Fn<A>>::call(self, args)
2089+
}
2090+
}
2091+
20692092
#[stable(feature = "from_for_ptrs", since = "1.6.0")]
20702093
impl<T> From<T> for Arc<T> {
20712094
fn from(t: T) -> Self {

0 commit comments

Comments
 (0)