Skip to content

Commit

Permalink
alloc: initial TryBox implementation
Browse files Browse the repository at this point in the history
Introduce the alloc submodule and the TryBox type, a fork of the
upstream alloc crate and Box type respectively. The new type behaves
exactly like Box, except it only supports fallible allocations,
meaning that users must always handle potential errors.

Users must also explicitly set the allocator to use. Using a specific
allocator by default like the standard library does is complicated.
The standard library uses whichever allocator is set as global
(via the #[global_allocator] macro), which can be accessed via a
global instance (alloc::alloc::Global). However, the global instance
is gated behind an unstable feature, and the macro cannot be
reimplemented because it is a compiler intrinsic. As a workaround,
one may add new higher level types in the future which use a specific
allocator by default.

The new SvsmBox does not support unsized types (e.g. [T]), since that
requires unstable features. On the other hand, it has a few extra
methods for convenience like try_default_in(), try_clone() and
try_clone_in().

Signed-off-by: Carlos López <[email protected]>
  • Loading branch information
00xc committed Jan 4, 2024
1 parent c936b63 commit ba1d264
Show file tree
Hide file tree
Showing 4 changed files with 1,314 additions and 0 deletions.
Loading

0 comments on commit ba1d264

Please sign in to comment.