@@ -2867,6 +2867,7 @@ impl<T: Sized> NonNull<T> {
2867
2867
/// sentinel value. Types that lazily allocate must track initialization by
2868
2868
/// some other means.
2869
2869
#[ stable( feature = "nonnull" , since = "1.25.0" ) ]
2870
+ #[ inline]
2870
2871
pub fn dangling ( ) -> Self {
2871
2872
unsafe {
2872
2873
let ptr = mem:: align_of :: < T > ( ) as * mut T ;
@@ -2882,12 +2883,14 @@ impl<T: ?Sized> NonNull<T> {
2882
2883
///
2883
2884
/// `ptr` must be non-null.
2884
2885
#[ stable( feature = "nonnull" , since = "1.25.0" ) ]
2886
+ #[ inline]
2885
2887
pub const unsafe fn new_unchecked ( ptr : * mut T ) -> Self {
2886
2888
NonNull { pointer : NonZero ( ptr as _ ) }
2887
2889
}
2888
2890
2889
2891
/// Creates a new `NonNull` if `ptr` is non-null.
2890
2892
#[ stable( feature = "nonnull" , since = "1.25.0" ) ]
2893
+ #[ inline]
2891
2894
pub fn new ( ptr : * mut T ) -> Option < Self > {
2892
2895
if !ptr. is_null ( ) {
2893
2896
Some ( NonNull { pointer : NonZero ( ptr as _ ) } )
@@ -2898,6 +2901,7 @@ impl<T: ?Sized> NonNull<T> {
2898
2901
2899
2902
/// Acquires the underlying `*mut` pointer.
2900
2903
#[ stable( feature = "nonnull" , since = "1.25.0" ) ]
2904
+ #[ inline]
2901
2905
pub fn as_ptr ( self ) -> * mut T {
2902
2906
self . pointer . 0 as * mut T
2903
2907
}
@@ -2908,6 +2912,7 @@ impl<T: ?Sized> NonNull<T> {
2908
2912
/// it were actually an instance of T that is getting borrowed. If a longer
2909
2913
/// (unbound) lifetime is needed, use `&*my_ptr.as_ptr()`.
2910
2914
#[ stable( feature = "nonnull" , since = "1.25.0" ) ]
2915
+ #[ inline]
2911
2916
pub unsafe fn as_ref ( & self ) -> & T {
2912
2917
& * self . as_ptr ( )
2913
2918
}
@@ -2918,12 +2923,14 @@ impl<T: ?Sized> NonNull<T> {
2918
2923
/// it were actually an instance of T that is getting borrowed. If a longer
2919
2924
/// (unbound) lifetime is needed, use `&mut *my_ptr.as_ptr()`.
2920
2925
#[ stable( feature = "nonnull" , since = "1.25.0" ) ]
2926
+ #[ inline]
2921
2927
pub unsafe fn as_mut ( & mut self ) -> & mut T {
2922
2928
& mut * self . as_ptr ( )
2923
2929
}
2924
2930
2925
2931
/// Cast to a pointer of another type
2926
2932
#[ stable( feature = "nonnull_cast" , since = "1.27.0" ) ]
2933
+ #[ inline]
2927
2934
pub fn cast < U > ( self ) -> NonNull < U > {
2928
2935
unsafe {
2929
2936
NonNull :: new_unchecked ( self . as_ptr ( ) as * mut U )
@@ -2963,48 +2970,55 @@ impl<T: ?Sized> Eq for NonNull<T> {}
2963
2970
2964
2971
#[ stable( feature = "nonnull" , since = "1.25.0" ) ]
2965
2972
impl < T : ?Sized > PartialEq for NonNull < T > {
2973
+ #[ inline]
2966
2974
fn eq ( & self , other : & Self ) -> bool {
2967
2975
self . as_ptr ( ) == other. as_ptr ( )
2968
2976
}
2969
2977
}
2970
2978
2971
2979
#[ stable( feature = "nonnull" , since = "1.25.0" ) ]
2972
2980
impl < T : ?Sized > Ord for NonNull < T > {
2981
+ #[ inline]
2973
2982
fn cmp ( & self , other : & Self ) -> Ordering {
2974
2983
self . as_ptr ( ) . cmp ( & other. as_ptr ( ) )
2975
2984
}
2976
2985
}
2977
2986
2978
2987
#[ stable( feature = "nonnull" , since = "1.25.0" ) ]
2979
2988
impl < T : ?Sized > PartialOrd for NonNull < T > {
2989
+ #[ inline]
2980
2990
fn partial_cmp ( & self , other : & Self ) -> Option < Ordering > {
2981
2991
self . as_ptr ( ) . partial_cmp ( & other. as_ptr ( ) )
2982
2992
}
2983
2993
}
2984
2994
2985
2995
#[ stable( feature = "nonnull" , since = "1.25.0" ) ]
2986
2996
impl < T : ?Sized > hash:: Hash for NonNull < T > {
2997
+ #[ inline]
2987
2998
fn hash < H : hash:: Hasher > ( & self , state : & mut H ) {
2988
2999
self . as_ptr ( ) . hash ( state)
2989
3000
}
2990
3001
}
2991
3002
2992
3003
#[ unstable( feature = "ptr_internals" , issue = "0" ) ]
2993
3004
impl < T : ?Sized > From < Unique < T > > for NonNull < T > {
3005
+ #[ inline]
2994
3006
fn from ( unique : Unique < T > ) -> Self {
2995
3007
NonNull { pointer : unique. pointer }
2996
3008
}
2997
3009
}
2998
3010
2999
3011
#[ stable( feature = "nonnull" , since = "1.25.0" ) ]
3000
3012
impl < ' a , T : ?Sized > From < & ' a mut T > for NonNull < T > {
3013
+ #[ inline]
3001
3014
fn from ( reference : & ' a mut T ) -> Self {
3002
3015
NonNull { pointer : NonZero ( reference as _ ) }
3003
3016
}
3004
3017
}
3005
3018
3006
3019
#[ stable( feature = "nonnull" , since = "1.25.0" ) ]
3007
3020
impl < ' a , T : ?Sized > From < & ' a T > for NonNull < T > {
3021
+ #[ inline]
3008
3022
fn from ( reference : & ' a T ) -> Self {
3009
3023
NonNull { pointer : NonZero ( reference as _ ) }
3010
3024
}
0 commit comments