authorgravatar for mikael@lilotux.netMikael Berthe <mikael@lilotux.net> 2022-12-11 15:39:25+01:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-12-11 17:42:26+02:00
log05890a12f532ba9d58904a14381ec174b9efe473
treedb097170ebee0efa39ed427b4d70c49fe19bc80b
parent6f77bef4dc3fea3fcec9d805322009c979de9a88

std: Update ArrayList documentation

Calling `deinit` might still be required after using `toOwnedSlice` now.

1 files changed, 6 insertions(+), 6 deletions(-)

lib/std/array_list.zig+6-6
...@@ -51,7 +51,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {...@@ -51,7 +51,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
51 return if (alignment) |a| ([:s]align(a) T) else [:s]T;51 return if (alignment) |a| ([:s]align(a) T) else [:s]T;
52 }52 }
5353
54 /// Deinitialize with `deinit` or use `toOwnedSlice`.54 /// Deinitialize with `deinit`.
55 pub fn init(allocator: Allocator) Self {55 pub fn init(allocator: Allocator) Self {
56 return Self{56 return Self{
57 .items = &[_]T{},57 .items = &[_]T{},
...@@ -62,7 +62,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {...@@ -62,7 +62,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
6262
63 /// Initialize with capacity to hold at least `num` elements.63 /// Initialize with capacity to hold at least `num` elements.
64 /// The resulting capacity is likely to be equal to `num`.64 /// The resulting capacity is likely to be equal to `num`.
65 /// Deinitialize with `deinit` or use `toOwnedSlice`.65 /// Deinitialize with `deinit`.
66 pub fn initCapacity(allocator: Allocator, num: usize) Allocator.Error!Self {66 pub fn initCapacity(allocator: Allocator, num: usize) Allocator.Error!Self {
67 var self = Self.init(allocator);67 var self = Self.init(allocator);
68 try self.ensureTotalCapacityPrecise(num);68 try self.ensureTotalCapacityPrecise(num);
...@@ -78,7 +78,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {...@@ -78,7 +78,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
7878
79 /// ArrayList takes ownership of the passed in slice. The slice must have been79 /// ArrayList takes ownership of the passed in slice. The slice must have been
80 /// allocated with `allocator`.80 /// allocated with `allocator`.
81 /// Deinitialize with `deinit` or use `toOwnedSlice`.81 /// Deinitialize with `deinit`.
82 pub fn fromOwnedSlice(allocator: Allocator, slice: Slice) Self {82 pub fn fromOwnedSlice(allocator: Allocator, slice: Slice) Self {
83 return Self{83 return Self{
84 .items = slice,84 .items = slice,
...@@ -475,7 +475,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {...@@ -475,7 +475,7 @@ pub fn ArrayListAligned(comptime T: type, comptime alignment: ?u29) type {
475/// An ArrayList, but the allocator is passed as a parameter to the relevant functions475/// An ArrayList, but the allocator is passed as a parameter to the relevant functions
476/// rather than stored in the struct itself. The same allocator **must** be used throughout476/// rather than stored in the struct itself. The same allocator **must** be used throughout
477/// the entire lifetime of an ArrayListUnmanaged. Initialize directly or with477/// the entire lifetime of an ArrayListUnmanaged. Initialize directly or with
478/// `initCapacity`, and deinitialize with `deinit` or use `toOwnedSlice`.478/// `initCapacity`, and deinitialize with `deinit`.
479pub fn ArrayListUnmanaged(comptime T: type) type {479pub fn ArrayListUnmanaged(comptime T: type) type {
480 return ArrayListAlignedUnmanaged(T, null);480 return ArrayListAlignedUnmanaged(T, null);
481}481}
...@@ -483,7 +483,7 @@ pub fn ArrayListUnmanaged(comptime T: type) type {...@@ -483,7 +483,7 @@ pub fn ArrayListUnmanaged(comptime T: type) type {
483/// An ArrayListAligned, but the allocator is passed as a parameter to the relevant483/// An ArrayListAligned, but the allocator is passed as a parameter to the relevant
484/// functions rather than stored in the struct itself. The same allocator **must**484/// functions rather than stored in the struct itself. The same allocator **must**
485/// be used throughout the entire lifetime of an ArrayListAlignedUnmanaged.485/// be used throughout the entire lifetime of an ArrayListAlignedUnmanaged.
486/// Initialize directly or with `initCapacity`, and deinitialize with `deinit` or use `toOwnedSlice`.486/// Initialize directly or with `initCapacity`, and deinitialize with `deinit`.
487pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) type {487pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) type {
488 if (alignment) |a| {488 if (alignment) |a| {
489 if (a == @alignOf(T)) {489 if (a == @alignOf(T)) {
...@@ -514,7 +514,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ...@@ -514,7 +514,7 @@ pub fn ArrayListAlignedUnmanaged(comptime T: type, comptime alignment: ?u29) typ
514514
515 /// Initialize with capacity to hold at least num elements.515 /// Initialize with capacity to hold at least num elements.
516 /// The resulting capacity is likely to be equal to `num`.516 /// The resulting capacity is likely to be equal to `num`.
517 /// Deinitialize with `deinit` or use `toOwnedSlice`.517 /// Deinitialize with `deinit`.
518 pub fn initCapacity(allocator: Allocator, num: usize) Allocator.Error!Self {518 pub fn initCapacity(allocator: Allocator, num: usize) Allocator.Error!Self {
519 var self = Self{};519 var self = Self{};
520 try self.ensureTotalCapacityPrecise(allocator, num);520 try self.ensureTotalCapacityPrecise(allocator, num);