newer_type_std/
alloc.rs

1use newer_type::target;
2
3macro_rules! impl_global_alloc {
4    () => {
5        /// This trait is empty declaration of [`::core::alloc::GlobalAlloc`] to be used
6        /// with [`newer_type::implement`].
7        ///
8        /// # Example
9        ///
10        /// ```
11        /// # use newer_type::implement;
12        /// #[implement(newer_type_std::alloc::GlobalAlloc)]
13        /// struct MyStruct {
14        ///     slot: std::alloc::System
15        /// }
16        /// ```
17        #[target(alternative = ::core::alloc::GlobalAlloc, newer_type = $crate::newer_type, repeater = $crate::Repeater)]
18        pub unsafe trait GlobalAlloc {
19            unsafe fn alloc(&self, layout: ::core::alloc::Layout) -> *mut ::core::primitive::u8;
20
21            unsafe fn dealloc(
22                &self,
23                ptr: *mut ::core::primitive::u8,
24                layout: ::core::alloc::Layout,
25            );
26
27            unsafe fn alloc_zeroed(
28                &self,
29                layout: ::core::alloc::Layout,
30            ) -> *mut ::core::primitive::u8;
31
32            unsafe fn realloc(
33                &self,
34                ptr: *mut ::core::primitive::u8,
35                layout: ::core::alloc::Layout,
36                new_size: ::core::primitive::usize,
37            ) -> *mut ::core::primitive::u8;
38        }
39    };
40}
41
42impl_global_alloc!();