@@ -936,6 +936,35 @@ impl<T: ?Sized + Hash> Hash for Arc<T> {
936
936
}
937
937
}
938
938
939
+ #[ stable( feature = "fn_smart_ptr" , since = "1.11.0" ) ]
940
+ impl < I , F : ?Sized > Fn < I > for Arc < F >
941
+ where F : Fn < I >
942
+ {
943
+ extern "rust-call" fn call ( & self , args : I ) -> Self :: Output {
944
+ ( & * * self ) . call ( args)
945
+ }
946
+ }
947
+
948
+ #[ stable( feature = "fn_smart_ptr" , since = "1.11.0" ) ]
949
+ impl < I , F : ?Sized > FnMut < I > for Arc < F >
950
+ where F : Fn < I >
951
+ {
952
+ extern "rust-call" fn call_mut ( & mut self , args : I ) -> Self :: Output {
953
+ self . call ( args)
954
+ }
955
+ }
956
+
957
+ #[ stable( feature = "fn_smart_ptr" , since = "1.11.0" ) ]
958
+ impl < I , F : ?Sized > FnOnce < I > for Arc < F >
959
+ where F : Fn < I >
960
+ {
961
+ type Output = F :: Output ;
962
+ extern "rust-call" fn call_once ( self , args : I ) -> Self :: Output {
963
+ self . call ( args)
964
+ }
965
+ }
966
+
967
+
939
968
#[ stable( feature = "from_for_ptrs" , since = "1.6.0" ) ]
940
969
impl < T > From < T > for Arc < T > {
941
970
fn from ( t : T ) -> Self {
@@ -1172,6 +1201,12 @@ mod tests {
1172
1201
assert_eq ! ( format!( "{:?}" , a) , "5" ) ;
1173
1202
}
1174
1203
1204
+ #[ test]
1205
+ fn test_fn ( ) {
1206
+ let f = Arc :: new ( |i : i32 | -> i32 { i + 1 } ) ;
1207
+ assert_eq ! ( Some ( 1 ) . map( f) , Some ( 2 ) ) ;
1208
+ }
1209
+
1175
1210
// Make sure deriving works with Arc<T>
1176
1211
#[ derive( Eq , Ord , PartialEq , PartialOrd , Clone , Debug , Default ) ]
1177
1212
struct Foo {
0 commit comments