| ... | @@ -855,6 +855,9 @@ pub const FixedBufferAllocator = struct { | ... | @@ -855,6 +855,9 @@ pub const FixedBufferAllocator = struct { |
| 855 | | 855 | |
| 856 | pub const ThreadSafeFixedBufferAllocator = @compileError("ThreadSafeFixedBufferAllocator has been replaced with `threadSafeAllocator` on FixedBufferAllocator"); | 856 | pub const ThreadSafeFixedBufferAllocator = @compileError("ThreadSafeFixedBufferAllocator has been replaced with `threadSafeAllocator` on FixedBufferAllocator"); |
| 857 | | 857 | |
| | 858 | /// Returns a `StackFallbackAllocator` allocating using either a |
| | 859 | /// `FixedBufferAllocator` on an array of size `size` and falling back to |
| | 860 | /// `fallback_allocator` if that fails. |
| 858 | pub fn stackFallback(comptime size: usize, fallback_allocator: Allocator) StackFallbackAllocator(size) { | 861 | pub fn stackFallback(comptime size: usize, fallback_allocator: Allocator) StackFallbackAllocator(size) { |
| 859 | return StackFallbackAllocator(size){ | 862 | return StackFallbackAllocator(size){ |
| 860 | .buffer = undefined, | 863 | .buffer = undefined, |
| ... | @@ -863,6 +866,10 @@ pub fn stackFallback(comptime size: usize, fallback_allocator: Allocator) StackF | ... | @@ -863,6 +866,10 @@ pub fn stackFallback(comptime size: usize, fallback_allocator: Allocator) StackF |
| 863 | }; | 866 | }; |
| 864 | } | 867 | } |
| 865 | | 868 | |
| | 869 | /// An allocator that attempts to allocate using a |
| | 870 | /// `FixedBufferAllocator` using an array of size `size`. If the |
| | 871 | /// allocation fails, it will fall back to using |
| | 872 | /// `fallback_allocator`. Easily created with `stackFallback`. |
| 866 | pub fn StackFallbackAllocator(comptime size: usize) type { | 873 | pub fn StackFallbackAllocator(comptime size: usize) type { |
| 867 | return struct { | 874 | return struct { |
| 868 | const Self = @This(); | 875 | const Self = @This(); |