| | | 1 | | //======================================================================= |
| | | 2 | | // SwiftArrayState.cs |
| | | 3 | | //======================================================================= |
| | | 4 | | // MIT License, Copyright (c) 2024–present David Oravsky (mrdav30) |
| | | 5 | | // See LICENSE file in the project root for full license information. |
| | | 6 | | //======================================================================= |
| | | 7 | | |
| | | 8 | | using MemoryPack; |
| | | 9 | | using System; |
| | | 10 | | using System.Text.Json.Serialization; |
| | | 11 | | |
| | | 12 | | namespace SwiftCollections; |
| | | 13 | | |
| | | 14 | | /// <summary> |
| | | 15 | | /// Represents an immutable snapshot of an array of items of the specified type. |
| | | 16 | | /// </summary> |
| | | 17 | | /// <remarks> |
| | | 18 | | /// This struct is intended for scenarios where a value-type representation of an array is needed, such as serialization |
| | | 19 | | /// The array referenced by the Items field should not be modified after construction to preserve immutability. |
| | | 20 | | /// </remarks> |
| | | 21 | | /// <typeparam name="T">The type of elements contained in the array.</typeparam> |
| | | 22 | | [Serializable] |
| | | 23 | | [MemoryPackable] |
| | | 24 | | public readonly partial struct SwiftArrayState<T> |
| | | 25 | | { |
| | | 26 | | /// <summary> |
| | | 27 | | /// Gets the array of items contained in the collection. |
| | | 28 | | /// </summary> |
| | | 29 | | [JsonInclude] |
| | | 30 | | [MemoryPackInclude] |
| | | 31 | | public readonly T[] Items; |
| | | 32 | | |
| | | 33 | | /// <summary> |
| | | 34 | | /// Initializes a new instance of the SwiftArrayState class with the specified items. |
| | | 35 | | /// </summary> |
| | | 36 | | /// <param name="items">The array of items to initialize the state with. Cannot be null.</param> |
| | | 37 | | [JsonConstructor] |
| | | 38 | | [MemoryPackConstructor] |
| | | 39 | | public SwiftArrayState(T[] items) |
| | | 40 | | { |
| | 89 | 41 | | Items = items; |
| | 89 | 42 | | } |
| | | 43 | | } |