File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed
Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -461,6 +461,35 @@ buffer_from_slice :: proc "contextless" (backing: $T/[]$E) -> [dynamic]E {
461461 }
462462}
463463
464+ /*
465+ Create a dynamic array from slice.
466+
467+ This procedure creates a dynamic array, using slice `backing` as the backing
468+ buffer for the dynamic array. The resulting dynamic array will panic
469+ if attempted to grow beyond the size of the specified slice.
470+ */
471+ @(require_results)
472+ buffer_from_slice_panicking :: proc " contextless" (backing: $T /[]$E ) -> [dynamic ]E {
473+ return transmute ([dynamic ]E)Raw_Dynamic_Array {
474+ data = raw_data (backing),
475+ len = 0 ,
476+ cap = len (backing),
477+ allocator = Allocator {
478+ procedure = proc (
479+ _ : rawptr ,
480+ _ : Allocator_Mode,
481+ _, _: int ,
482+ _ : rawptr ,
483+ _ : int ,
484+ loc := #caller_location ,
485+ ) -> ([]byte , Allocator_Error) {
486+ panic (" atempted to grow slice-backed buffer" , loc)
487+ },
488+ data = nil ,
489+ },
490+ }
491+ }
492+
464493/*
465494Check whether a number is a power of two.
466495
You can’t perform that action at this time.
0 commit comments