AddrParseError.cs (5737B)
1 using Std.Clone; 2 using Std.Cmp; 3 using Std.Convert; 4 using Std.Error; 5 using Std.Hashing; 6 using Std.Maybe; 7 using Std.Result; 8 using System; 9 using System.Diagnostics; 10 using System.Runtime.InteropServices; 11 #region Namespaces 12 namespace Std.Net { 13 #region Types 14 [StructLayout(LayoutKind.Explicit, CharSet = CharSet.Unicode, Pack = 1, Size = 1)] 15 public readonly struct AddrParseError: ISum<AddrParseError.Tag, AddrParseError.Tag, AddrParseError.Tag>, IClone<AddrParseError>, IEquality<AddrParseError>, IError, IHashable, IInto<AddrParseError> { 16 17 #region Type-level Constructors 18 #endregion 19 20 #region Instance Constructors 21 public AddrParseError() => throw new InvalidOperationException("Parameterless constructor is not allowed to be called!"); 22 AddrParseError(Tag val) => Var = val; 23 #endregion 24 25 #region Type-level Fields 26 public static readonly AddrParseError InvalidLength = new(Tag.InvalidLength); 27 public static readonly AddrParseError InvalidCharacter = new(Tag.InvalidCharacter); 28 public static readonly AddrParseError InvalidFormat = new(Tag.InvalidFormat); 29 #endregion 30 31 #region Instance Fields 32 [FieldOffset(0)] public readonly Tag Var; 33 #endregion 34 35 #region Type-level Properties 36 #endregion 37 38 #region Instance Properties 39 public readonly Var3 Variant => (Var3)Var; 40 public readonly Tag Variant0 => Var == Tag.InvalidLength ? Var : throw new InvalidOperationException($"The AddrParseError variant, {Var.ToString()} is not InvalidLength!"); 41 public readonly Tag Variant1 => Var == Tag.InvalidCharacter ? Var : throw new InvalidOperationException($"The AddrParseError variant, {Var.ToString()} is not InvalidCharacter!"); 42 public readonly Tag Variant2 => Var == Tag.InvalidFormat ? Var : throw new InvalidOperationException($"The AddrParseError variant, {Var.ToString()} is not InvalidFormat!"); 43 #endregion 44 45 #region Type-level Functions 46 #endregion 47 48 #region Instance Functions 49 public readonly AddrParseError Clone() => this; 50 public readonly bool Equals(in AddrParseError other) => this == other; 51 public override readonly bool Equals(object? _) => false; 52 public override readonly int GetHashCode() => 0; 53 public readonly Unit Hash<THasher>(ref THasher hasher) where THasher: notnull, IHasher => hasher.WriteUnsafe(this); 54 public readonly AddrParseError Into() => this; 55 public readonly string IntoString() => ToString(); 56 readonly string IInto<string>.Into() => IntoString(); 57 public readonly Maybe<IError> Source() => Maybe<IError>.None(); 58 public readonly Maybe<StackTrace> StackTrace() => Maybe<StackTrace>.None(); 59 public override readonly string ToString() => $"AddrParseError({Var.ToString()})"; 60 readonly Result<AddrParseError, Bottom> ITryInto<AddrParseError, Bottom>.TryInto() => new(this); 61 readonly Result<string, Bottom> ITryInto<string, Bottom>.TryInto() => new(ToString()); 62 #endregion 63 64 #region Operators 65 public static bool operator !=(AddrParseError val0, AddrParseError val1) => val0.Var != val1.Var; 66 public static bool operator ==(AddrParseError val0, AddrParseError val1) => val0.Var == val1.Var; 67 #endregion 68 69 #region Types 70 public enum Tag: byte { 71 InvalidLength = byte.MinValue, 72 InvalidCharacter = 1, 73 InvalidFormat = 2, 74 } 75 #endregion 76 } 77 [StructLayout(LayoutKind.Explicit, CharSet = CharSet.Unicode, Pack = 1, Size = 1)] 78 public readonly struct IPVersionMismatchError: IClone<IPVersionMismatchError>, IEquality<IPVersionMismatchError>, IError, IHashable, IInto<IPVersionMismatchError> { 79 80 #region Type-level Constructors 81 #endregion 82 83 #region Instance Constructors 84 public IPVersionMismatchError(){} 85 #endregion 86 87 #region Type-level Fields 88 public static readonly IPVersionMismatchError IPVersionMismatch = new(); 89 #endregion 90 91 #region Instance Fields 92 #endregion 93 94 #region Type-level Properties 95 #endregion 96 97 #region Instance Properties 98 #endregion 99 100 #region Type-level Functions 101 #endregion 102 103 #region Instance Functions 104 public readonly IPVersionMismatchError Clone() => this; 105 public readonly bool Equals(in IPVersionMismatchError _) => true; 106 public override readonly bool Equals(object? _) => false; 107 public override readonly int GetHashCode() => 0; 108 public readonly Unit Hash<THasher>(ref THasher _) where THasher: notnull, IHasher => new Unit(); 109 public readonly IPVersionMismatchError Into() => this; 110 public readonly string IntoString() => ToString(); 111 readonly string IInto<string>.Into() => IntoString(); 112 public readonly Maybe<IError> Source() => Maybe<IError>.None(); 113 public readonly Maybe<StackTrace> StackTrace() => Maybe<StackTrace>.None(); 114 public override readonly string ToString() => "IPVersionMismatch"; 115 readonly Result<IPVersionMismatchError, Bottom> ITryInto<IPVersionMismatchError, Bottom>.TryInto() => new(this); 116 readonly Result<string, Bottom> ITryInto<string, Bottom>.TryInto() => new(ToString()); 117 #endregion 118 119 #region Operators 120 public static bool operator !=(IPVersionMismatchError _, IPVersionMismatchError _1) => false; 121 public static bool operator ==(IPVersionMismatchError _, IPVersionMismatchError _1) => true; 122 #endregion 123 124 #region Types 125 #endregion 126 } 127 #endregion 128 129 #region Namespaces 130 #endregion 131 } 132 #endregion