Files
Beam/Beam.Models/ImmutableState.cs
T

24 lines
724 B
C#

using System.Text.Json.Serialization;
using Beam.Abstractions;
namespace Beam.Models {
public readonly struct ImmutableState : IReadOnlyState {
private readonly string[] state;
[JsonConstructor]
public ImmutableState(params IEnumerable<string> state) {
this.state = state.ToArray();
}
public ReadOnlySpan<string> GetState() => this.state;
public readonly State Copy()
=> new((string[])(state ?? []).Clone());
IState IReadOnlyState.Copy()
=> Copy();
public readonly string this[Index i] => state[i];
public static implicit operator State(ImmutableState state)
=> state.Copy();
}
}