Serde

Kind of a port of Rust's Serde crate.
git clone https://git.philomathiclife.com/repos/Serde
Log | Files | Refs | README

De.cs (27421B)


      1 using Std;
      2 using Std.Clone;
      3 using Std.Cmp;
      4 using Std.Convert;
      5 using Std.Error;
      6 using Std.Maybe;
      7 using Std.Num;
      8 using Std.Result;
      9 using System;
     10 using System.Diagnostics;
     11 using System.Runtime.InteropServices;
     12 using System.Text;
     13 #region Namespaces
     14 namespace Serde.De {
     15     #region Types
     16     [StructLayout(LayoutKind.Explicit, CharSet = CharSet.Unicode, Pack = 8, Size = 32)]
     17     public readonly struct Unexpected: ISum<bool, byte, byte[], char, string, DateTime, DateTimeOffset, decimal, double, float, Guid, I128, int, long, Unit, sbyte, short, TimeSpan, U128, uint, ulong, Unit, ushort, string>, IClone<Unexpected>, IPartialEq<Unexpected, Unexpected>, IInto<Unexpected>, IInto<string> {
     18 
     19         #region Type-level Constructors
     20         #endregion
     21 
     22         #region Instance Constructors
     23         public Unexpected() => throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");
     24         Unexpected(Unit _) => (Var, _bool, _byte, _bytes, _char, _chars, _dateTime, _dateTimeOffset, _decimal, _double, _float, _guid, _i128, _int, _long, _other, _sbyte, _short, _timeSpan, _u128, _uint, _ulong, _ushort) = (default, default, default, default!, default, default!, default, default, default, default, default, default, default, default, default, default!, default, default, default, default, default, default, default);
     25         Unexpected(Tag kind) : this(new Std.Unit()) => Var = kind;
     26         Unexpected(bool val) : this(new Std.Unit()) => (Var, _bool) = (Tag.Bool, val);
     27         Unexpected(byte val) : this(new Std.Unit()) => (Var, _byte) = (Tag.Byte, val);
     28         Unexpected(byte[] val) : this(new Std.Unit()) => (Var, _bytes) = (Tag.Bytes, val);
     29         Unexpected(char val) : this(new Std.Unit()) => (Var, _char) = (Tag.Char, val);
     30         Unexpected(string val) : this(new Std.Unit()) => (Var, _chars) = (Tag.Chars, val);
     31         Unexpected(DateTime val) : this(new Std.Unit()) => (Var, _dateTime) = (Tag.DateTime, val);
     32         Unexpected(DateTimeOffset val) : this(new Std.Unit()) => (Var, _dateTimeOffset) = (Tag.DateTimeOffset, val);
     33         Unexpected(decimal val) : this(new Std.Unit()) => (Var, _decimal) = (Tag.Decimal, val);
     34         Unexpected(double val) : this(new Std.Unit()) => (Var, _double) = (Tag.Double, val);
     35         Unexpected(float val) : this(new Std.Unit()) => (Var, _float) = (Tag.Float, val);
     36         Unexpected(Guid val) : this(new Std.Unit()) => (Var, _guid) = (Tag.Guid, val);
     37         Unexpected(I128 val) : this(new Std.Unit()) => (Var, _i128) = (Tag.I128, val);
     38         Unexpected(int val) : this(new Std.Unit()) => (Var, _int) = (Tag.Int, val);
     39         Unexpected(long val) : this(new Std.Unit()) => (Var, _long) = (Tag.Long, val);
     40         Unexpected(sbyte val) : this(new Std.Unit()) => (Var, _sbyte) = (Tag.Sbyte, val);
     41         Unexpected(short val) : this(new Std.Unit()) => (Var, _short) = (Tag.Short, val);
     42         Unexpected(TimeSpan val) : this(new Std.Unit()) => (Var, _timeSpan) = (Tag.TimeSpan, val);
     43         Unexpected(U128 val) : this(new Std.Unit()) => (Var, _u128) = (Tag.U128, val);
     44         Unexpected(uint val) : this(new Std.Unit()) => (Var, _uint) = (Tag.Uint, val);
     45         Unexpected(ulong val) : this(new Std.Unit()) => (Var, _ulong) = (Tag.Ulong, val);
     46         Unexpected(ushort val) : this(new Std.Unit()) => (Var, _ushort) = (Tag.Ushort, val);
     47         Unexpected(string val, Unit _) : this(new Std.Unit()) => (Var, _other) = (Tag.Other, val);
     48         #endregion
     49 
     50         #region Type-level Fields
     51         #endregion
     52 
     53         #region Instance Fields
     54         [FieldOffset(0)] readonly bool _bool;
     55         [FieldOffset(0)] readonly byte _byte;
     56         [FieldOffset(0)] readonly char _char;
     57         [FieldOffset(0)] readonly DateTime _dateTime;
     58         [FieldOffset(0)] readonly DateTimeOffset _dateTimeOffset;
     59         [FieldOffset(0)] readonly decimal _decimal;
     60         [FieldOffset(0)] readonly double _double;
     61         [FieldOffset(0)] readonly float _float;
     62         [FieldOffset(0)] readonly Guid _guid;
     63         [FieldOffset(0)] readonly I128 _i128;
     64         [FieldOffset(0)] readonly int _int;
     65         [FieldOffset(0)] readonly long _long;
     66         [FieldOffset(0)] readonly sbyte _sbyte;
     67         [FieldOffset(0)] readonly short _short;
     68         [FieldOffset(0)] readonly TimeSpan _timeSpan;
     69         [FieldOffset(0)] readonly U128 _u128;
     70         [FieldOffset(0)] readonly uint _uint;
     71         [FieldOffset(0)] readonly ulong _ulong;
     72         [FieldOffset(0)] readonly ushort _ushort;
     73         [FieldOffset(16)] readonly byte[] _bytes;
     74         [FieldOffset(16)] readonly string _chars;
     75         [FieldOffset(16)] readonly string _other;
     76         [FieldOffset(24)] public readonly Tag Var;
     77         #endregion
     78 
     79         #region Type-level Properties
     80         #endregion
     81 
     82         #region Instance Properties
     83         public readonly Var24 Variant => (Var24)Var;
     84         public readonly bool Variant0 => IntoBool();
     85         public readonly byte Variant1 => IntoByte();
     86         public readonly byte[] Variant2 => IntoBytes();
     87         public readonly char Variant3 => IntoChar();
     88         public readonly string Variant4 => IntoChars();
     89         public readonly DateTime Variant5 => IntoDateTime();
     90         public readonly DateTimeOffset Variant6 => IntoDateTimeOffset();
     91         public readonly decimal Variant7 => IntoDecimal();
     92         public readonly double Variant8 => IntoDouble();
     93         public readonly float Variant9 => IntoFloat();
     94         public readonly Guid Variant10 => IntoGuid();
     95         public readonly I128 Variant11 => IntoI128();
     96         public readonly int Variant12 => IntoInt();
     97         public readonly long Variant13 => IntoLong();
     98         public readonly Unit Variant14 => IntoMaybe();
     99         public readonly sbyte Variant15 => IntoSbyte();
    100         public readonly short Variant16 => IntoShort();
    101         public readonly TimeSpan Variant17 => IntoTimeSpan();
    102         public readonly U128 Variant18 => IntoU128();
    103         public readonly uint Variant19 => IntoUint();
    104         public readonly ulong Variant20 => IntoUlong();
    105         public readonly Unit Variant21 => IntoUnit();
    106         public readonly ushort Variant22 => IntoUshort();
    107         public readonly string Variant23 => IntoOther();
    108         #endregion
    109 
    110         #region Type-level Functions
    111         public static Unexpected Bool(bool val) => new(val);
    112         public static Unexpected Byte(byte val) => new(val);
    113         public static Unexpected Bytes(byte[] val) => new(val);
    114         public static Unexpected Char(char val) => new(val);
    115         public static Unexpected Chars(string val) => new(val);
    116         public static Unexpected DateTime(DateTime val) => new(val);
    117         public static Unexpected DateTimeOffset(DateTimeOffset val) => new(val);
    118         public static Unexpected Decimal(decimal val) => new(val);
    119         public static Unexpected Double(double val) => new(val);
    120         public static Unexpected Float(float val) => new(val);
    121         public static Unexpected Guid(Guid val) => new(val);
    122         public static Unexpected I128(I128 val) => new(val);
    123         public static Unexpected Int(int val) => new(val);
    124         public static Unexpected Long(long val) => new(val);
    125         public static Unexpected Maybe() => new(Tag.Maybe);
    126         public static Unexpected Sbyte(sbyte val) => new(val);
    127         public static Unexpected Short(short val) => new(val);
    128         public static Unexpected TimeSpan(TimeSpan val) => new(val);
    129         public static Unexpected U128(U128 val) => new(val);
    130         public static Unexpected Uint(uint val) => new(val);
    131         public static Unexpected Ulong(ulong val) => new(val);
    132         public static Unexpected Unit() => new(Tag.Unit);
    133         public static Unexpected Ushort(ushort val) => new(val);
    134         public static Unexpected Other(string val) => new(val, new Std.Unit());
    135         #endregion
    136 
    137         #region Instance Functions
    138         public readonly Unexpected Clone() {
    139 
    140             if (Var == Tag.Bytes) {
    141                 var bytes = new byte[_bytes.Length];
    142                 Array.Copy(_bytes, 0, bytes, 0, bytes.Length);
    143                 return new(bytes);
    144             } else {
    145                 return this;
    146             }
    147         }
    148         public override readonly bool Equals(object? _) => false;
    149         public override readonly int GetHashCode() => 0;
    150         public readonly Unexpected Into() => this;
    151         public readonly string IntoString() => ToString();
    152         readonly string IInto<string>.Into() => IntoString();
    153         public readonly bool IntoBool() => Var == Tag.Bool ? _bool : throw new InvalidOperationException($"The Unexpected variant {Var.ToString()} is not Bool!");
    154         public readonly byte IntoByte() => Var == Tag.Byte ? _byte : throw new InvalidOperationException($"The Unexpected variant {Var.ToString()} is not Byte!");
    155         public readonly byte[] IntoBytes() => Var == Tag.Bytes ? _bytes : throw new InvalidOperationException($"The Unexpected variant {Var.ToString()} is not Bytes!");
    156         public readonly char IntoChar() => Var == Tag.Char ? _char : throw new InvalidOperationException($"The Unexpected variant {Var.ToString()} is not Char!");
    157         public readonly string IntoChars() => Var == Tag.Chars ? _chars : throw new InvalidOperationException($"The Unexpected variant {Var.ToString()} is not Chars!");
    158         public readonly DateTime IntoDateTime() => Var == Tag.DateTime ? _dateTime : throw new InvalidOperationException($"The Unexpected variant {Var.ToString()} is not DateTime!");
    159         public readonly DateTimeOffset IntoDateTimeOffset() => Var == Tag.DateTimeOffset ? _dateTimeOffset : throw new InvalidOperationException($"The Unexpected variant {Var.ToString()} is not DateTimeOffset!");
    160         public readonly decimal IntoDecimal() => Var == Tag.Decimal ? _decimal : throw new InvalidOperationException($"The Unexpected variant {Var.ToString()} is not Decimal!");
    161         public readonly double IntoDouble() => Var == Tag.Double ? _double : throw new InvalidOperationException($"The Unexpected variant {Var.ToString()} is not Double!");
    162         public readonly float IntoFloat() => Var == Tag.Float ? _float : throw new InvalidOperationException($"The Unexpected variant {Var.ToString()} is not Float!");
    163         public readonly Guid IntoGuid() => Var == Tag.Guid ? _guid : throw new InvalidOperationException($"The Unexpected variant {Var.ToString()} is not Guid!");
    164         public readonly I128 IntoI128() => Var == Tag.I128 ? _i128 : throw new InvalidOperationException($"The Unexpected variant {Var.ToString()} is not I128!");
    165         public readonly int IntoInt() => Var == Tag.Int ? _int : throw new InvalidOperationException($"The Unexpected variant {Var.ToString()} is not Int!");
    166         public readonly long IntoLong() => Var == Tag.Long ? _long : throw new InvalidOperationException($"The Unexpected variant {Var.ToString()} is not Long!");
    167         public readonly Unit IntoMaybe() => Var == Tag.Maybe ? new Std.Unit() : throw new InvalidOperationException($"The Unexpected variant {Var.ToString()} is not Maybe!");
    168         public readonly sbyte IntoSbyte() => Var == Tag.Sbyte ? _sbyte : throw new InvalidOperationException($"The Unexpected variant {Var.ToString()} is not Sbyte!");
    169         public readonly short IntoShort() => Var == Tag.Short ? _short : throw new InvalidOperationException($"The Unexpected variant {Var.ToString()} is not Short!");
    170         public readonly TimeSpan IntoTimeSpan() => Var == Tag.TimeSpan ? _timeSpan : throw new InvalidOperationException($"The Unexpected variant {Var.ToString()} is not TimeSpan!");
    171         public readonly U128 IntoU128() => Var == Tag.U128 ? _u128 : throw new InvalidOperationException($"The Unexpected variant {Var.ToString()} is not U128!");
    172         public readonly uint IntoUint() => Var == Tag.Uint ? _uint : throw new InvalidOperationException($"The Unexpected variant {Var.ToString()} is not Uint!");
    173         public readonly ulong IntoUlong() => Var == Tag.Ulong ? _ulong : throw new InvalidOperationException($"The Unexpected variant {Var.ToString()} is not Ulong!");
    174         public readonly Unit IntoUnit() => Var == Tag.Unit ? new Std.Unit() : throw new InvalidOperationException($"The Unexpected variant {Var.ToString()} is not Unit!");
    175         public readonly ushort IntoUshort() => Var == Tag.Ushort ? _ushort : throw new InvalidOperationException($"The Unexpected variant {Var.ToString()} is not Ushort!");
    176         public readonly string IntoOther() => Var == Tag.Other ? _other : throw new InvalidOperationException($"The Unexpected variant {Var.ToString()} is not Other!");
    177         public override readonly string ToString() => $@"{Var.ToString()}({Var switch {
    178             Tag.Bool =>_bool.ToString(),
    179             Tag.Byte => _byte.ToString(),
    180             Tag.Bytes => _bytes.AsSpan().UpperHex(),
    181             Tag.Char => _char.ToString(),
    182             Tag.Chars => _chars,
    183             Tag.DateTime => _dateTime.ToString(),
    184             Tag.DateTimeOffset => _dateTimeOffset.ToString(),
    185             Tag.Decimal => _decimal.ToString(),
    186             Tag.Double => _double.ToString(),
    187             Tag.Float => _float.ToString(),
    188             Tag.Guid => _guid.ToString(),
    189             Tag.I128 => _i128.IntoString(),
    190             Tag.Int => _int.ToString(),
    191             Tag.Long => _long.ToString(),
    192             Tag.Maybe => string.Empty,
    193             Tag.Sbyte => _sbyte.ToString(),
    194             Tag.Short => _short.ToString(),
    195             Tag.TimeSpan => _timeSpan.ToString(),
    196             Tag.U128 => _u128.IntoString(),
    197             Tag.Uint => _uint.ToString(),
    198             Tag.Ulong => _ulong.ToString(),
    199             Tag.Unit => "()",
    200             Tag.Ushort => _ushort.ToString(),
    201             Tag.Other => _other,
    202             _ => throw new InvalidOperationException($"The Unexpected variant {Var.ToString()} is invalid!"),
    203         }
    204 })";
    205         readonly Result<Unexpected, Bottom> ITryInto<Unexpected, Bottom>.TryInto() => new(this);
    206         readonly Result<string, Bottom> ITryInto<string, Bottom>.TryInto() => new(ToString());
    207         #endregion
    208 
    209         #region Operators
    210         public static bool operator !=(Unexpected val0, Unexpected val1) => !(val0 == val1);
    211         public static bool operator ==(Unexpected val0, Unexpected val1) => val0.Var == val1.Var && val0.Var switch {
    212             Tag.Bool => val0._bool == val1._bool,
    213             Tag.Byte => val0._byte == val1._byte,
    214             Tag.Bytes => val0._bytes.AsSpan().EqualsEquatable(val1._bytes.AsSpan()),
    215             Tag.Char => val0._char == val1._char,
    216             Tag.Chars => val0._chars == val1._chars,
    217             Tag.DateTime => val0._dateTime == val1._dateTime,
    218             Tag.DateTimeOffset => val0._dateTimeOffset == val1._dateTimeOffset,
    219             Tag.Decimal => val0._decimal == val1._decimal,
    220             Tag.Double => val0._double == val1._double,
    221             Tag.Float => val0._float == val1._float,
    222             Tag.Guid => val0._guid == val1._guid,
    223             Tag.I128 => val0._i128 == val1._i128,
    224             Tag.Int => val0._int == val1._int,
    225             Tag.Long => val0._long == val1._long,
    226             Tag.Maybe => true,
    227             Tag.Sbyte => val0._sbyte == val1._sbyte,
    228             Tag.Short => val0._short == val1._short,
    229             Tag.TimeSpan => val0._timeSpan == val1._timeSpan,
    230             Tag.U128 => val0._u128 == val1._u128,
    231             Tag.Uint => val0._uint == val1._uint,
    232             Tag.Ulong => val0._ulong == val1._ulong,
    233             Tag.Unit => true,
    234             Tag.Ushort => val0._ushort == val1._ushort,
    235             Tag.Other=> val0._other== val1._other,
    236             _ => throw new InvalidOperationException($"The Unexpected type {val0.Var.ToString()} is invalid."),
    237         };
    238         #endregion
    239 
    240         #region Types
    241         public enum Tag: ulong {
    242             Bool = ulong.MinValue,
    243             Byte = 1ul,
    244             Bytes = 2ul,
    245             Char = 3ul,
    246             Chars = 4ul,
    247             DateTime = 5ul,
    248             DateTimeOffset = 6ul,
    249             Decimal = 7ul,
    250             Double = 8ul,
    251             Float = 9ul,
    252             Guid = 10ul,
    253             I128 = 11ul,
    254             Int = 12ul,
    255             Long = 13ul,
    256             Maybe = 14ul,
    257             Sbyte = 15ul,
    258             Short = 16ul,
    259             TimeSpan = 17ul,
    260             U128 = 18ul,
    261             Uint = 19ul,
    262             Ulong = 20ul,
    263             Unit = 21ul,
    264             Ushort = 22ul,
    265             Other = 23ul,
    266         }
    267         #endregion
    268     }
    269     // This is a fairly large type and it will likely be used frequently as the error in a Result.
    270     // If this were a struct, the Result would be large. If it were the case the Result
    271     // would be local only, then it would be better if this were a struct; however it's likely that the Result will simply
    272     // be passed down the call stack making it important the copies are small so we make it a sealed class instead.
    273     [StructLayout(LayoutKind.Explicit, CharSet = CharSet.Unicode, Pack = 8, Size = 48)]
    274     public sealed class Error: ISum<IInto<string>, Prod<Unexpected, IInto<string>>, Prod<Unexpected, IInto<string>>, Prod<ulong, IInto<string>>, Prod<string, string[]>, Prod<string, string[]>, string, string>, IInto<Error>, IError {
    275 
    276         #region Type-level Constructors
    277         #endregion
    278 
    279         #region Instance Constructors
    280         Error() => (_unexp, _len, _variant_or_field, _expected, _msg_or_exp, Var) = (default, default, default!, default!, default!, default);
    281         Error(IInto<string> msg) : this() => (Var, _msg_or_exp) = (Tag.Custom, msg);
    282         Error(Tag kind, Unexpected unexp, IInto<string> exp) : this() => (Var, _msg_or_exp, _unexp) = (kind, exp, unexp);
    283         Error(ulong len, IInto<string> exp) : this() => (Var, _len, _msg_or_exp) = (Tag.InvalidLength, len, exp);
    284         Error(Tag kind, string variant_or_field, string[] expected) : this() => (Var, _variant_or_field, _expected) = (kind, variant_or_field, expected);
    285         Error(Tag kind, string field) : this() => (Var, _variant_or_field) = (kind, field);
    286         #endregion
    287 
    288         #region Type-level Fields
    289         #endregion
    290 
    291         #region Instance Fields
    292         [FieldOffset(0)] readonly Unexpected _unexp;
    293         [FieldOffset(0)] readonly ulong _len;
    294         [FieldOffset(16)] readonly string _variant_or_field;
    295         [FieldOffset(32)] readonly string[] _expected;
    296         [FieldOffset(32)] readonly IInto<string> _msg_or_exp;
    297         [FieldOffset(40)] public readonly Tag Var;
    298         #endregion
    299 
    300         #region Type-level Properties
    301         #endregion
    302 
    303         #region Instance Properties
    304         public Var8 Variant => (Var8)Var;
    305         public IInto<string> Variant0 => IntoCustom();
    306         public Prod<Unexpected, IInto<string>> Variant1 => IntoInvalidType();
    307         public Prod<Unexpected, IInto<string>> Variant2 => IntoInvalidValue();
    308         public Prod<ulong, IInto<string>> Variant3 => IntoInvalidLength();
    309         public Prod<string, string[]> Variant4 => IntoUnknownVariant();
    310         public Prod<string, string[]> Variant5 => IntoUnknownField();
    311         public string Variant6 => IntoMissingField();
    312         public string Variant7 => IntoDuplicateField();
    313         #endregion
    314 
    315         #region Type-level Functions
    316         public static Error Custom<T>(T msg) where T: notnull, IInto<string> => new(msg);
    317         public static Error InvalidType(Unexpected unexp, IInto<string> exp) => new(Tag.InvalidType, unexp, exp);
    318         public static Error InvalidValue(Unexpected unexp, IInto<string> exp) => new(Tag.InvalidValue, unexp, exp);
    319         public static Error InvalidLength(ulong len, IInto<string> exp) => new(len, exp);
    320         public static Error UnknownVariant(string variant, string[] expected) => new(Tag.UnknownVariant, variant, expected);
    321         public static Error UnknownField(string field, string[] expected) => new(Tag.UnknownField, field, expected);
    322         public static Error MissingField(string field) => new(Tag.MissingField, field);
    323         public static Error DuplicateField(string field) => new(Tag.DuplicateField, field);
    324         #endregion
    325 
    326         #region Instance Functions
    327         public sealed override bool Equals(object? _) => false;
    328         public sealed override int GetHashCode() => 0;
    329         public Error Into() => this;
    330         public string IntoString() => ToString();
    331         string IInto<string>.Into() => IntoString();
    332         public IInto<string> IntoCustom() => Var == Tag.Custom ? _msg_or_exp : throw new InvalidOperationException($"The Error variant {Var.ToString()} is not a Custom!");
    333         public Prod<Unexpected, IInto<string>> IntoInvalidType() => Var == Tag.InvalidType ? new(_unexp, _msg_or_exp) : throw new InvalidOperationException($"The Error variant {Var.ToString()} is not an InvalidType!");
    334         public Prod<Unexpected, IInto<string>> IntoInvalidValue() => Var == Tag.InvalidValue ? new(_unexp, _msg_or_exp) : throw new InvalidOperationException($"The Error variant {Var.ToString()} is not an InvalidValue!");
    335         public Prod<ulong, IInto<string>> IntoInvalidLength() => Var == Tag.InvalidLength ? new(_len, _msg_or_exp) : throw new InvalidOperationException($"The Error variant {Var.ToString()} is not an InvalidLength!");
    336         public Prod<string, string[]> IntoUnknownVariant() => Var == Tag.UnknownVariant ? new(_variant_or_field, _expected) : throw new InvalidOperationException($"The Error variant {Var.ToString()} is not an UnknownVariant!");
    337         public Prod<string, string[]> IntoUnknownField() => Var == Tag.UnknownField ? new(_variant_or_field, _expected) : throw new InvalidOperationException($"The Error variant {Var.ToString()} is not an UnknownField!");
    338         public string IntoMissingField() => Var == Tag.MissingField ? _variant_or_field : throw new InvalidOperationException($"The Error variant {Var.ToString()} is not a MissingField!");
    339         public string IntoDuplicateField() => Var == Tag.DuplicateField ? _variant_or_field : throw new InvalidOperationException($"The Error variant {Var.ToString()} is not a DuplicateField!");
    340         public Maybe<IError> Source() => Maybe<IError>.None();
    341         public Maybe<StackTrace> StackTrace() => Maybe<StackTrace>.None();
    342         public sealed override string ToString() => $@"{Var.ToString()}({Var switch {
    343             Tag.Custom => $"{_msg_or_exp.Into()}",
    344             Tag.InvalidType => $"{_unexp.IntoString()}, Expected({_msg_or_exp.Into()})",
    345             Tag.InvalidValue => $"{_unexp.IntoString()}, Expected({_msg_or_exp.Into()})",
    346             Tag.InvalidLength => $"Length: {_len.ToString()}, Expected({_msg_or_exp.Into()})",
    347             Tag.UnknownVariant => $"Variant: {_variant_or_field}, Expected([ {_expected.IntoString()} ])",
    348             Tag.UnknownField => $"Field: {_variant_or_field}, Expected([ {_expected.IntoString()} ])",
    349             Tag.MissingField => $"Field: {_variant_or_field}",
    350             Tag.DuplicateField => $"Field: {_variant_or_field}",
    351             _ => throw new InvalidOperationException($"The Error variant {Var.ToString()} is invalid!"),
    352         }
    353 })";
    354         Result<Error, Bottom> ITryInto<Error, Bottom>.TryInto() => new(this);
    355         Result<string, Bottom> ITryInto<string, Bottom>.TryInto() => new(ToString());
    356         #endregion
    357 
    358         #region Operators
    359         #endregion
    360 
    361         #region Types
    362         public enum Tag: ulong {
    363             Custom = ulong.MinValue,
    364             InvalidType = 1ul,
    365             InvalidValue = 2ul,
    366             InvalidLength = 3ul,
    367             UnknownVariant = 4ul,
    368             UnknownField = 5ul,
    369             MissingField = 6ul,
    370             DuplicateField = 7ul,
    371         }
    372         #endregion
    373     }
    374     public interface IDeserializable<TSelf> where TSelf: notnull, IDeserializable<TSelf> {
    375 
    376         #region Type-level Constructors
    377         #endregion
    378 
    379         #region Instance Constructors
    380         #endregion
    381 
    382         #region Type-level Fields
    383         #endregion
    384 
    385         #region Instance Fields
    386         #endregion
    387 
    388         #region Type-level Properties
    389         #endregion
    390 
    391         #region Instance Properties
    392         #endregion
    393 
    394         #region Type-level Functions
    395         public static abstract Result<TSelf, Error> Deserialize<TDes>(ref TDes des) where TDes: notnull, IDeserializer;
    396         #endregion
    397 
    398         #region Instance Functions
    399         #endregion
    400 
    401         #region Operators
    402         #endregion
    403 
    404         #region Types
    405         #endregion
    406     }
    407     public interface IDeserializer {
    408 
    409         #region Type-level Constructors
    410         #endregion
    411 
    412         #region Instance Constructors
    413         #endregion
    414 
    415         #region Type-level Fields
    416         #endregion
    417 
    418         #region Instance Fields
    419         #endregion
    420 
    421         #region Type-level Properties
    422         #endregion
    423 
    424         #region Instance Properties
    425         #endregion
    426 
    427         #region Type-level Functions
    428         #endregion
    429 
    430         #region Instance Functions
    431         public abstract uint Deserialize(Span<byte> bytes);
    432         public abstract Result<bool, Error> DeserializeBool();
    433         public abstract Result<byte, Error> DeserializeByte();
    434         public abstract Result<char, Error> DeserializeChar();
    435         public abstract uint DeserializeChars(Span<char> chars);
    436         public abstract Result<DateTime, Error> DeserializeDateTime();
    437         public abstract Result<DateTimeOffset, Error> DeserializeDateTimeOffset();
    438         public abstract Result<decimal, Error> DeserializeDecimal();
    439         public abstract Result<double, Error> DeserializeDouble();
    440         public abstract Result<float, Error> DeserializeFloat();
    441         public abstract Result<Guid, Error> DeserializeGuid();
    442         public abstract Result<I128, Error> DeserializeI128();
    443         public abstract Result<int, Error> DeserializeInt();
    444         public abstract Result<long, Error> DeserializeLong();
    445         public abstract Result<Maybe<TSome>, Error> DeserializeMaybe<TSome>() where TSome: notnull, IDeserializable<TSome>;
    446         public abstract Result<sbyte, Error> DeserializeSbyte();
    447         public abstract Result<short, Error> DeserializeShort();
    448         public abstract Result<TimeSpan, Error> DeserializeTimeSpan();
    449         public abstract Result<U128, Error> DeserializeU128();
    450         public abstract Result<uint, Error> DeserializeUint();
    451         public abstract Result<ulong, Error> DeserializeUlong();
    452         public abstract Result<Unit, Error> DeserializeUnit();
    453         public abstract Result<ushort, Error> DeserializeUshort();
    454         #endregion
    455 
    456         #region Operators
    457         #endregion
    458 
    459         #region Types
    460         #endregion
    461     }
    462     public static class Functions {
    463 
    464         #region Type-level Constructors
    465         #endregion
    466 
    467         #region Instance Constructors
    468         #endregion
    469 
    470         #region Type-level Fields
    471         #endregion
    472 
    473         #region Instance Fields
    474         #endregion
    475 
    476         #region Type-level Properties
    477         #endregion
    478 
    479         #region Instance Properties
    480         #endregion
    481 
    482         #region Type-level Functions
    483         internal static string IntoString(this string[] self) {
    484 
    485             if (self.Length == 0) { return string.Empty; };
    486             var sb = new StringBuilder(self.Length * 32);
    487             for (var i = 0; i < self.Length; i++) { sb = sb.Append($"{self[i]}, "); }
    488             return sb.Remove(sb.Length - 2, 2).ToString();
    489         }
    490         #endregion
    491 
    492         #region Instance Functions
    493         #endregion
    494 
    495         #region Operators
    496         #endregion
    497 
    498         #region Types
    499         #endregion
    500     }
    501     #endregion
    502 
    503     #region Namespaces
    504     #endregion
    505 }
    506 #endregion