Global in alloc::alloc - Rust
Description: The global memory allocator.
Keywords: rust, rustlang, rust-lang, Global

# Struct alloc::alloc::Global
[−][src]

    pub struct Global;

🔬 This is a nightly-only experimental API. (`allocator_api` #32838)
Expand description

The global memory allocator.

This type implements the `Allocator` trait by forwarding calls to the allocator registered with the `#[global_allocator]` attribute if there is one, or the `std` crate’s default.

Note: while this type is unstable, the functionality it provides can be accessed through the free functions in `alloc`.

## Trait Implementations

[src]

### impl Allocator for Global

[src]

#### fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError>

🔬 This is a nightly-only experimental API. (`allocator_api` #32838)

Attempts to allocate a block of memory. Read more

[src]

#### fn allocate_zeroed(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError>

🔬 This is a nightly-only experimental API. (`allocator_api` #32838)

Behaves like `allocate`, but also ensures that the returned memory is zero-initialized. Read more

[src]

#### unsafe fn deallocate(&self, ptr: NonNull<u8>, layout: Layout)

🔬 This is a nightly-only experimental API. (`allocator_api` #32838)

Deallocates the memory referenced by `ptr`. Read more

[src]

#### unsafe fn grow(
&self,
ptr: NonNull<u8>,
old_layout: Layout,
new_layout: Layout
) -> Result<NonNull<[u8]>, AllocError>

🔬 This is a nightly-only experimental API. (`allocator_api` #32838)

Attempts to extend the memory block. Read more

[src]

#### unsafe fn grow_zeroed(
&self,
ptr: NonNull<u8>,
old_layout: Layout,
new_layout: Layout
) -> Result<NonNull<[u8]>, AllocError>

🔬 This is a nightly-only experimental API. (`allocator_api` #32838)

Behaves like `grow`, but also ensures that the new contents are set to zero before being returned. Read more

[src]

#### unsafe fn shrink(
&self,
ptr: NonNull<u8>,
old_layout: Layout,
new_layout: Layout
) -> Result<NonNull<[u8]>, AllocError>

🔬 This is a nightly-only experimental API. (`allocator_api` #32838)

Attempts to shrink the memory block. Read more

[src]

#### fn by_ref(&self) -> &Self

🔬 This is a nightly-only experimental API. (`allocator_api` #32838)

Creates a “by reference” adapter for this instance of `Allocator`. Read more

[src]

### impl Clone for Global

[src]

#### fn clone(&self) -> Global

Returns a copy of the value. Read more

1.0.0[src]

#### fn clone_from(&mut self, source: &Self)

Performs copy-assignment from `source`. Read more

[src]

### impl Debug for Global

[src]

#### fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

[src]

### impl Default for Global

[src]

#### fn default() -> Global

Returns the “default value” for a type. Read more

[src]

### impl Copy for Global

## Auto Trait Implementations

### impl RefUnwindSafe for Global

### impl Send for Global

### impl Sync for Global

### impl Unpin for Global

### impl UnwindSafe for Global

## Blanket Implementations

[src]

### impl<T> Any for T where
T: 'static + ?Sized,

[src]

#### pub fn type_id(&self) -> TypeId

Gets the `TypeId` of `self`. Read more

[src]

### impl<T> Borrow<T> for T where
T: ?Sized,

[src]

#### pub fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more

[src]

### impl<T> BorrowMut<T> for T where
T: ?Sized,

[src]

#### pub fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more

[src]

### impl<T> From<T> for T

[src]

#### pub fn from(t: T) -> T

Performs the conversion.

[src]

### impl<T, U> Into<U> for T where
U: From<T>,

[src]

#### pub fn into(self) -> U

Performs the conversion.

[src]

### impl<T> ToOwned for T where
T: Clone,

#### type Owned = T

The resulting type after obtaining ownership.

[src]

#### pub fn to_owned(&Self) -> T

Creates owned data from borrowed data, usually by cloning. Read more

[src]

#### pub fn clone_into(&Self, &mut T)

🔬 This is a nightly-only experimental API. (`toowned_clone_into` #41263)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

[src]

### impl<T, U> TryFrom<U> for T where
U: Into<T>,

#### type Error = Infallible

The type returned in the event of a conversion error.

[src]

#### pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.

[src]

### impl<T, U> TryInto<U> for T where
U: TryFrom<T>,

#### type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

[src]

#### pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.