Std

Mainly a port of Rust's std.
git clone https://git.philomathiclife.com/repos/Std
Log | Files | Refs | README

ParseIntError.cs (3645B)


      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 static Std.Result.Result<Std.Num.ParseIntError, Std.Bottom>;
      9 using System;
     10 using System.Diagnostics;
     11 using System.Runtime.InteropServices;
     12 #region Namespaces
     13 namespace Std.Num {
     14     #region Types
     15     [StructLayout(LayoutKind.Explicit, CharSet = CharSet.Unicode, Pack = 1, Size = 1)]
     16     public readonly struct ParseIntError: ISum<ParseIntError.Tag, ParseIntError.Tag, ParseIntError.Tag>, IClone<ParseIntError>, IEquality<ParseIntError>, IError, IHashable, IInto<ParseIntError> {
     17 
     18         #region Type-level Constructors
     19         #endregion
     20 
     21         #region Instance Constructors
     22         public ParseIntError() => throw new InvalidOperationException("Parameterless constructor is not allowed to be called!");
     23         ParseIntError(Tag val) => Var = val;
     24         #endregion
     25 
     26         #region Type-level Fields
     27         public static readonly ParseIntError InvalidLength = new(Tag.InvalidLength);
     28         public static readonly ParseIntError InvalidDigit = new(Tag.InvalidDigit);
     29         public static readonly ParseIntError OverflowOrUnderflow = new(Tag.OverflowOrUnderflow);
     30         #endregion
     31 
     32         #region Instance Fields
     33         [FieldOffset(0)] public readonly Tag Var;
     34         #endregion
     35 
     36         #region Type-level Properties
     37         #endregion
     38 
     39         #region Instance Properties
     40         public readonly Var3 Variant => (Var3)Var;
     41         public readonly Tag Variant0 => Var == Tag.InvalidLength ? Var : throw new InvalidOperationException($"The ParseIntError variant, {Var.ToString()} is not InvalidLength!");
     42         public readonly Tag Variant1 => Var == Tag.InvalidDigit ? Var : throw new InvalidOperationException($"The ParseIntError variant, {Var.ToString()} is not InvalidDigit!");
     43         public readonly Tag Variant2 => Var == Tag.OverflowOrUnderflow ? Var : throw new InvalidOperationException($"The ParseIntError variant, {Var.ToString()} is not OverflowOrUnderflow!");
     44         #endregion
     45 
     46         #region Type-level Functions
     47         #endregion
     48 
     49         #region Instance Functions
     50         public readonly ParseIntError Clone() => this;
     51         public readonly bool Equals(in ParseIntError other) => this == other;
     52         public override readonly bool Equals(object? _) => false;
     53         public override readonly int GetHashCode() => 0;
     54         public readonly Unit Hash<THasher>(ref THasher hasher) where THasher: notnull, IHasher => hasher.WriteUnsafe(this);
     55         public readonly ParseIntError Into() => this;
     56         public readonly string IntoString() => ToString();
     57         readonly string IInto<string>.Into() => IntoString();
     58         public readonly Maybe<IError> Source() => Maybe<IError>.None();
     59         public readonly Maybe<StackTrace> StackTrace() => Maybe<StackTrace>.None();
     60         public override readonly string ToString() => Var.ToString();
     61         readonly Result<ParseIntError, Bottom> ITryInto<ParseIntError, Bottom>.TryInto() => OK(this);
     62         readonly Result<string, Bottom> ITryInto<string, Bottom>.TryInto() => new(ToString());
     63         #endregion
     64 
     65         #region Operators
     66         public static bool operator !=(ParseIntError val0, ParseIntError val1) => val0.Var != val1.Var;
     67         public static bool operator ==(ParseIntError val0, ParseIntError val1) => val0.Var == val1.Var;
     68         #endregion
     69 
     70         #region Types
     71         public enum Tag: byte {
     72             InvalidLength = byte.MinValue,
     73             InvalidDigit = 1,
     74             OverflowOrUnderflow = 2,
     75         }
     76         #endregion
     77     }
     78     #endregion
     79 
     80     #region Namespaces
     81     #endregion
     82 }
     83 #endregion