11use crate :: {
2+ error:: AllocError ,
23 type_props:: {
3- varsized_nonnull_from_raw_parts,
4- varsized_pointer_from_raw_parts,
5- VarSized ,
6- PtrProps ,
7- SizedProps ,
8- USIZE_MAX_NO_HIGH_BIT
4+ varsized_nonnull_from_raw_parts, varsized_pointer_from_raw_parts, PtrProps , SizedProps ,
5+ VarSized , USIZE_MAX_NO_HIGH_BIT ,
96 } ,
10- error:: AllocError ,
11- Alloc
7+ Alloc ,
128} ;
139use core:: {
1410 alloc:: Layout ,
@@ -96,12 +92,6 @@ pub(crate) fn zsl_check<Ret, F: Fn(Layout) -> Result<Ret, AllocError>>(
9692 }
9793}
9894
99- /// Checks equality between two [`NonNull`] pointers.
100- #[ must_use]
101- pub fn nonnull_eq < T : ?Sized > ( a : NonNull < T > , b : NonNull < T > ) -> bool {
102- peq ( a. as_ptr ( ) as * const T , b. as_ptr ( ) as * const T )
103- }
104-
10595/// Aligns the given value up to a non-zero alignment.
10696#[ must_use]
10797pub const fn align_up ( n : usize , align : NonZeroUsize ) -> usize {
@@ -131,6 +121,7 @@ pub const fn dangling_nonnull_for(layout: Layout) -> NonNull<u8> {
131121///
132122/// The caller must ensure the `alignment` is a valid power of two.
133123#[ must_use]
124+ #[ inline]
134125pub const unsafe fn dangling_nonnull ( align : usize ) -> NonNull < u8 > {
135126 transmute :: < NonZeroUsize , NonNull < u8 > > ( NonZeroUsize :: new_unchecked ( align) )
136127}
@@ -200,6 +191,7 @@ impl<'a, T: ?Sized, A: Alloc + ?Sized> AllocGuard<'a, T, A> {
200191 const_if ! {
201192 "extra_const" ,
202193 "Creates a new guard from a pointer and a reference to an allocator." ,
194+ #[ inline]
203195 pub const fn new( ptr: NonNull <T >, alloc: & ' a A ) -> AllocGuard <' a, T , A > {
204196 AllocGuard { ptr, alloc }
205197 }
@@ -209,6 +201,7 @@ impl<'a, T: ?Sized, A: Alloc + ?Sized> AllocGuard<'a, T, A> {
209201 "extra_extra_const" ,
210202 "Initializes the value by writing to the contained pointer." ,
211203 #[ cfg_attr( miri, track_caller) ]
204+ #[ inline]
212205 pub const fn init( & mut self , elem: T )
213206 where
214207 T : Sized
@@ -224,6 +217,7 @@ impl<'a, T: ?Sized, A: Alloc + ?Sized> AllocGuard<'a, T, A> {
224217 "Releases ownership of the allocation, preventing deallocation, and returns the raw \
225218 pointer.",
226219 #[ must_use]
220+ #[ inline]
227221 pub const fn release( self ) -> NonNull <T > {
228222 let ptr = self . ptr;
229223 forget( self ) ;
@@ -244,6 +238,7 @@ impl<T: ?Sized, A: Alloc + ?Sized> Drop for AllocGuard<'_, T, A> {
244238impl < T : ?Sized , A : Alloc + ?Sized > Deref for AllocGuard < ' _ , T , A > {
245239 type Target = NonNull < T > ;
246240
241+ #[ inline]
247242 fn deref ( & self ) -> & NonNull < T > {
248243 & self . ptr
249244 }
@@ -299,6 +294,7 @@ impl<'a, T, A: Alloc + ?Sized> SliceAllocGuard<'a, T, A> {
299294 const_if ! {
300295 "extra_const" ,
301296 "Creates a new slice guard for `full` elements at `ptr` in the given allocator." ,
297+ #[ inline]
302298 pub const fn new( ptr: NonNull <T >, alloc: & ' a A , full: usize )
303299 -> SliceAllocGuard <' a, T , A > {
304300 SliceAllocGuard {
@@ -315,6 +311,7 @@ impl<'a, T, A: Alloc + ?Sized> SliceAllocGuard<'a, T, A> {
315311 "Release ownership of the slice without deallocating memory, returning a `NonNull<T>` \
316312 pointer to the slice.",
317313 #[ must_use]
314+ #[ inline]
318315 pub const fn release( self ) -> NonNull <[ T ] > {
319316 let ret = self . get_init_part( ) ;
320317 forget( self ) ;
@@ -327,6 +324,7 @@ impl<'a, T, A: Alloc + ?Sized> SliceAllocGuard<'a, T, A> {
327324 "Release ownership of the slice without deallocating memory, returning a `NonNull<T>` \
328325 pointer to the slice's first element.",
329326 #[ must_use]
327+ #[ inline]
330328 pub const fn release_first( self ) -> NonNull <T > {
331329 let ret = self . ptr;
332330 forget( self ) ;
@@ -370,6 +368,7 @@ impl<'a, T, A: Alloc + ?Sized> SliceAllocGuard<'a, T, A> {
370368 "extra_extra_const" ,
371369 "Sets the initialized element count.\n \n # Safety\n \n The caller must ensure the new \
372370 count is correct.",
371+ #[ inline]
373372 pub const unsafe fn set_init( & mut self , init: usize ) {
374373 self . init = init;
375374 }
@@ -379,6 +378,7 @@ impl<'a, T, A: Alloc + ?Sized> SliceAllocGuard<'a, T, A> {
379378 "extra_extra_const" ,
380379 "Initializes the next element of the slice with `elem`.\n \n # Errors\n \n Returns \
381380 `Err(elem)` if the slice is at capacity.",
381+ #[ inline]
382382 pub const fn init( & mut self , elem: T ) -> Result <( ) , T > {
383383 if self . init == self . full {
384384 return Err ( elem) ;
@@ -394,6 +394,7 @@ impl<'a, T, A: Alloc + ?Sized> SliceAllocGuard<'a, T, A> {
394394 "extra_extra_const" ,
395395 "Initializes the next element of the slice with `elem`.\n \n # Safety\n \n The caller must \
396396 ensure that the slice is not at capacity. (`initialized() < full()`)",
397+ #[ inline]
397398 pub const unsafe fn init_unchecked( & mut self , elem: T ) {
398399 ptr:: write( self . ptr. as_ptr( ) . add( self . init) , elem) ;
399400 self . init += 1 ;
@@ -426,6 +427,7 @@ impl<'a, T, A: Alloc + ?Sized> SliceAllocGuard<'a, T, A> {
426427 "extra_const" ,
427428 "Returns how many elements have been initialized." ,
428429 #[ must_use]
430+ #[ inline]
429431 pub const fn initialized( & self ) -> usize {
430432 self . init
431433 }
@@ -435,6 +437,7 @@ impl<'a, T, A: Alloc + ?Sized> SliceAllocGuard<'a, T, A> {
435437 "extra_const" ,
436438 "Returns the total number of elements in the slice." ,
437439 #[ must_use]
440+ #[ inline]
438441 pub const fn full( & self ) -> usize {
439442 self . full
440443 }
@@ -444,6 +447,7 @@ impl<'a, T, A: Alloc + ?Sized> SliceAllocGuard<'a, T, A> {
444447 "extra_const" ,
445448 "Returns `true` if every element in the slice has been initialized." ,
446449 #[ must_use]
450+ #[ inline]
447451 pub const fn is_full( & self ) -> bool {
448452 self . init == self . full
449453 }
@@ -453,6 +457,7 @@ impl<'a, T, A: Alloc + ?Sized> SliceAllocGuard<'a, T, A> {
453457 "extra_const" ,
454458 "Returns `true` if no elements have been initialized." ,
455459 #[ must_use]
460+ #[ inline]
456461 pub const fn is_empty( & self ) -> bool {
457462 self . init == 0
458463 }
@@ -508,6 +513,7 @@ impl<T, A: Alloc + ?Sized> Drop for SliceAllocGuard<'_, T, A> {
508513impl < T , A : Alloc + ?Sized > Deref for SliceAllocGuard < ' _ , T , A > {
509514 type Target = NonNull < T > ;
510515
516+ #[ inline]
511517 fn deref ( & self ) -> & NonNull < T > {
512518 & self . ptr
513519 }
0 commit comments