Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/sera-net/Sera.Union

Tagged union for c#
https://github.com/sera-net/Sera.Union

Last synced: 20 days ago
JSON representation

Tagged union for c#

Awesome Lists containing this project

README

        

# Sera.Union

[![.NET](https://github.com/sera-net/Sera.Union/actions/workflows/dotnet.yml/badge.svg)](https://github.com/sera-net/Sera.Union/actions/workflows/dotnet.yml)
![MIT](https://img.shields.io/github/license/sera-net/Sera.Union)

- Sera.Union
[![Nuget](https://img.shields.io/nuget/v/Sera.Union)](https://www.nuget.org/packages/Sera.Union/)
[![openupm](https://img.shields.io/npm/v/net.sera.union?label=openupm&registry_uri=https://package.openupm.com)](https://openupm.com/packages/net.sera.union/)
- Sera.Union.Utilities
[![Nuget](https://img.shields.io/nuget/v/Sera.Union.Utilities)](https://www.nuget.org/packages/Sera.Union.Utilities/)

Generate Tagged Union using source generator

- All unmanaged types will overlap
- All classes will overlap
- Other types will be tiled

## Example

```cs
[Union]
public readonly partial struct Union1
{
[UnionTemplate]
private interface Template
{
int A();
string B();
bool C();
(int a, int b) D();
void E();
List? F();
(int a, string b) G();
}
}
```

Generate output:

Union1.union.g.cs

```cs
//

#nullable enable

using Sera.TaggedUnion;

public readonly partial struct Union1
: global::Sera.TaggedUnion.ITaggedUnion
, global::System.IEquatable
, global::System.IComparable
#if NET7_0_OR_GREATER
, global::System.Numerics.IEqualityOperators
, global::System.Numerics.IComparisonOperators
#endif
{
private readonly __impl_ _impl;
private Union1(__impl_ _impl) { this._impl = _impl; }

public readonly Tags Tag
{
[global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
get => this._impl._tag;
}

public enum Tags : byte
{
A = 1,
B = 2,
C = 3,
D = 4,
E = 5,
F = 6,
G = 7,
}

[global::System.Runtime.CompilerServices.CompilerGenerated]
private struct __impl_
{
public __class_ _class_;
public __unmanaged_ _unmanaged_;
public (int a, string b) _0;
public readonly Tags _tag;

[global::System.Runtime.CompilerServices.CompilerGenerated]
[global::System.Runtime.InteropServices.StructLayout(global::System.Runtime.InteropServices.LayoutKind.Explicit)]
internal struct __class_
{
[global::System.Runtime.InteropServices.FieldOffset(0)]
public string _0;
[global::System.Runtime.InteropServices.FieldOffset(0)]
public List? _1;
}

[global::System.Runtime.CompilerServices.CompilerGenerated]
[global::System.Runtime.InteropServices.StructLayout(global::System.Runtime.InteropServices.LayoutKind.Explicit)]
internal struct __unmanaged_
{
[global::System.Runtime.InteropServices.FieldOffset(0)]
public int _0;
[global::System.Runtime.InteropServices.FieldOffset(0)]
public bool _1;
[global::System.Runtime.InteropServices.FieldOffset(0)]
public (int a, int b) _2;
}

public __impl_(Tags _tag)
{
this._class_ = default;
global::System.Runtime.CompilerServices.Unsafe.SkipInit(out this._unmanaged_);
this._0 = default!;
this._tag = _tag;
}
}

[global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
public static Union1 MakeA(int value)
{
var _impl = new __impl_(Tags.A);
_impl._unmanaged_._0 = value;
return new Union1(_impl);
}
[global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
public static Union1 MakeB(string value)
{
var _impl = new __impl_(Tags.B);
_impl._class_._0 = value;
return new Union1(_impl);
}
[global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
public static Union1 MakeC(bool value)
{
var _impl = new __impl_(Tags.C);
_impl._unmanaged_._1 = value;
return new Union1(_impl);
}
[global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
public static Union1 MakeD((int a, int b) value)
{
var _impl = new __impl_(Tags.D);
_impl._unmanaged_._2 = value;
return new Union1(_impl);
}
[global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
public static Union1 MakeE()
{
var _impl = new __impl_(Tags.E);
return new Union1(_impl);
}
[global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
public static Union1 MakeF(List? value)
{
var _impl = new __impl_(Tags.F);
_impl._class_._1 = value;
return new Union1(_impl);
}
[global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
public static Union1 MakeG((int a, string b) value)
{
var _impl = new __impl_(Tags.G);
_impl._0 = value;
return new Union1(_impl);
}

public readonly bool IsA
{
[global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
get => this._impl._tag == Tags.A;
}
public readonly bool IsB
{
[global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
get => this._impl._tag == Tags.B;
}
public readonly bool IsC
{
[global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
get => this._impl._tag == Tags.C;
}
public readonly bool IsD
{
[global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
get => this._impl._tag == Tags.D;
}
public readonly bool IsE
{
[global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
get => this._impl._tag == Tags.E;
}
public readonly bool IsF
{
[global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
get => this._impl._tag == Tags.F;
}
public readonly bool IsG
{
[global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
get => this._impl._tag == Tags.G;
}

public int A
{
[global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
get => !this.IsA ? default! : this._impl._unmanaged_._0!;
}
public string B
{
[global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
get => !this.IsB ? default! : this._impl._class_._0!;
}
public bool C
{
[global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
get => !this.IsC ? default! : this._impl._unmanaged_._1!;
}
public (int a, int b) D
{
[global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
get => !this.IsD ? default! : this._impl._unmanaged_._2!;
}
public List? F
{
[global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
get => !this.IsF ? default! : this._impl._class_._1!;
}
public (int a, string b) G
{
[global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
get => !this.IsG ? default! : this._impl._0!;
}

[global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
public readonly bool Equals(Union1 other) => this.Tag != other.Tag ? false : this.Tag switch
{
Tags.A => global::System.Collections.Generic.EqualityComparer.Default.Equals(this.A, other.A),
Tags.B => global::System.Collections.Generic.EqualityComparer.Default.Equals(this.B, other.B),
Tags.C => global::System.Collections.Generic.EqualityComparer.Default.Equals(this.C, other.C),
Tags.D => global::System.Collections.Generic.EqualityComparer<(int a, int b)>.Default.Equals(this.D, other.D),
Tags.F => global::System.Collections.Generic.EqualityComparer?>.Default.Equals(this.F, other.F),
Tags.G => global::System.Collections.Generic.EqualityComparer<(int a, string b)>.Default.Equals(this.G, other.G),
_ => true,
};

[global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
public readonly override int GetHashCode() => this.Tag switch
{
Tags.A => global::System.HashCode.Combine(this.Tag, this.A),
Tags.B => global::System.HashCode.Combine(this.Tag, this.B),
Tags.C => global::System.HashCode.Combine(this.Tag, this.C),
Tags.D => global::System.HashCode.Combine(this.Tag, this.D),
Tags.F => global::System.HashCode.Combine(this.Tag, this.F),
Tags.G => global::System.HashCode.Combine(this.Tag, this.G),
_ => global::System.HashCode.Combine(this.Tag),
};

[global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
public readonly override bool Equals(object? obj) => obj is Union1 other && Equals(other);

[global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
public static bool operator ==(Union1 left, Union1 right) => Equals(left, right);
[global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
public static bool operator !=(Union1 left, Union1 right) => !Equals(left, right);

[global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
public readonly int CompareTo(Union1 other) => this.Tag != other.Tag ? Comparer.Default.Compare(this.Tag, other.Tag) : this.Tag switch
{
Tags.A => global::System.Collections.Generic.Comparer.Default.Compare(this.A, other.A),
Tags.B => global::System.Collections.Generic.Comparer.Default.Compare(this.B, other.B),
Tags.C => global::System.Collections.Generic.Comparer.Default.Compare(this.C, other.C),
Tags.D => global::System.Collections.Generic.Comparer<(int a, int b)>.Default.Compare(this.D, other.D),
Tags.F => global::System.Collections.Generic.Comparer?>.Default.Compare(this.F, other.F),
Tags.G => global::System.Collections.Generic.Comparer<(int a, string b)>.Default.Compare(this.G, other.G),
_ => 0,
};

[global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
public static bool operator <(Union1 left, Union1 right) => left.CompareTo(right) < 0;
[global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
public static bool operator >(Union1 left, Union1 right) => left.CompareTo(right) > 0;
[global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
public static bool operator <=(Union1 left, Union1 right) => left.CompareTo(right) <= 0;
[global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
public static bool operator >=(Union1 left, Union1 right) => left.CompareTo(right) >= 0;

[global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
public readonly override string ToString() => this.Tag switch
{
Tags.A => $"{nameof(Union1)}.{nameof(Tags.A)} {{ {this.A} }}",
Tags.B => $"{nameof(Union1)}.{nameof(Tags.B)} {{ {this.B} }}",
Tags.C => $"{nameof(Union1)}.{nameof(Tags.C)} {{ {this.C} }}",
Tags.D => $"{nameof(Union1)}.{nameof(Tags.D)} {{ {this.D} }}",
Tags.E => $"{nameof(Union1)}.{nameof(Tags.E)}",
Tags.F => $"{nameof(Union1)}.{nameof(Tags.F)} {{ {this.F} }}",
Tags.G => $"{nameof(Union1)}.{nameof(Tags.G)} {{ {this.G} }}",
_ => nameof(Union1),
};
}
```

#### How to use

```cs
var u = Union1.MakeA(123);

if (u is { Tag: Union1.Tags.A, A: var a }) { }

if (u is { IsA: true, A: var a }) { }

if (u.IsA)
{
var a = u.A;
}
```

---

### Support generics

**Generics will not overlap**

```cs
[Union]
public partial struct Option
{
[UnionTemplate]
private interface Template
{
T Some();
void None();
}
}

[Union]
public partial struct Result
{
[UnionTemplate]
private interface Template
{
T Ok();
E Err();
}
}
```

Generate output:

Option[T].union.g.cs

```cs
//

#nullable enable

using Sera.TaggedUnion;

public partial struct Option
: global::Sera.TaggedUnion.ITaggedUnion
, global::System.IEquatable>
, global::System.IComparable>
#if NET7_0_OR_GREATER
, global::System.Numerics.IEqualityOperators, Option, bool>
, global::System.Numerics.IComparisonOperators, Option, bool>
#endif
{
private __impl_ _impl;
private Option(__impl_ _impl) { this._impl = _impl; }

public readonly Tags Tag
{
[global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
get => this._impl._tag;
}

public enum Tags : byte
{
Some = 1,
None = 2,
}

[global::System.Runtime.CompilerServices.CompilerGenerated]
private struct __impl_
{
public T _0;
public readonly Tags _tag;

public __impl_(Tags _tag)
{
this._0 = default!;
this._tag = _tag;
}
}

[global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
public static Option MakeSome(T value)
{
var _impl = new __impl_(Tags.Some);
_impl._0 = value;
return new Option(_impl);
}
[global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
public static Option MakeNone()
{
var _impl = new __impl_(Tags.None);
return new Option(_impl);
}

public readonly bool IsSome
{
[global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
get => this._impl._tag == Tags.Some;
}
public readonly bool IsNone
{
[global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
get => this._impl._tag == Tags.None;
}

public T Some
{
[global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
readonly get => !this.IsSome ? default! : this._impl._0!;
[global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
set { if (this.IsSome) { this._impl._0 = value; } }
}

[global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
public readonly bool Equals(Option other) => this.Tag != other.Tag ? false : this.Tag switch
{
Tags.Some => global::System.Collections.Generic.EqualityComparer.Default.Equals(this.Some, other.Some),
_ => true,
};

[global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
public readonly override int GetHashCode() => this.Tag switch
{
Tags.Some => global::System.HashCode.Combine(this.Tag, this.Some),
_ => global::System.HashCode.Combine(this.Tag),
};

[global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
public readonly override bool Equals(object? obj) => obj is Option other && Equals(other);

[global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
public static bool operator ==(Option left, Option right) => Equals(left, right);
[global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
public static bool operator !=(Option left, Option right) => !Equals(left, right);

[global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
public readonly int CompareTo(Option other) => this.Tag != other.Tag ? Comparer.Default.Compare(this.Tag, other.Tag) : this.Tag switch
{
Tags.Some => global::System.Collections.Generic.Comparer.Default.Compare(this.Some, other.Some),
_ => 0,
};

[global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
public static bool operator <(Option left, Option right) => left.CompareTo(right) < 0;
[global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
public static bool operator >(Option left, Option right) => left.CompareTo(right) > 0;
[global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
public static bool operator <=(Option left, Option right) => left.CompareTo(right) <= 0;
[global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
public static bool operator >=(Option left, Option right) => left.CompareTo(right) >= 0;

[global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
public readonly override string ToString() => this.Tag switch
{
Tags.Some => $"{nameof(Option)}.{nameof(Tags.Some)} {{ {this.Some} }}",
Tags.None => $"{nameof(Option)}.{nameof(Tags.None)}",
_ => nameof(Option),
};
}

```


Result[T,E].union.g.cs

```cs
//

#nullable enable

using Sera.TaggedUnion;

public partial struct Result
: global::Sera.TaggedUnion.ITaggedUnion
, global::System.IEquatable>
, global::System.IComparable>
#if NET7_0_OR_GREATER
, global::System.Numerics.IEqualityOperators, Result, bool>
, global::System.Numerics.IComparisonOperators, Result, bool>
#endif
{
private __impl_ _impl;
private Result(__impl_ _impl) { this._impl = _impl; }

public readonly Tags Tag
{
[global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
get => this._impl._tag;
}

public enum Tags : byte
{
Ok = 1,
Err = 2,
}

[global::System.Runtime.CompilerServices.CompilerGenerated]
private struct __impl_
{
public T _0;
public E _1;
public readonly Tags _tag;

public __impl_(Tags _tag)
{
this._0 = default!;
this._1 = default!;
this._tag = _tag;
}
}

[global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
public static Result MakeOk(T value)
{
var _impl = new __impl_(Tags.Ok);
_impl._0 = value;
return new Result(_impl);
}
[global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
public static Result MakeErr(E value)
{
var _impl = new __impl_(Tags.Err);
_impl._1 = value;
return new Result(_impl);
}

public readonly bool IsOk
{
[global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
get => this._impl._tag == Tags.Ok;
}
public readonly bool IsErr
{
[global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
get => this._impl._tag == Tags.Err;
}

public T Ok
{
[global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
readonly get => !this.IsOk ? default! : this._impl._0!;
[global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
set { if (this.IsOk) { this._impl._0 = value; } }
}
public E Err
{
[global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
readonly get => !this.IsErr ? default! : this._impl._1!;
[global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
set { if (this.IsErr) { this._impl._1 = value; } }
}

[global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
public readonly bool Equals(Result other) => this.Tag != other.Tag ? false : this.Tag switch
{
Tags.Ok => global::System.Collections.Generic.EqualityComparer.Default.Equals(this.Ok, other.Ok),
Tags.Err => global::System.Collections.Generic.EqualityComparer.Default.Equals(this.Err, other.Err),
_ => true,
};

[global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
public readonly override int GetHashCode() => this.Tag switch
{
Tags.Ok => global::System.HashCode.Combine(this.Tag, this.Ok),
Tags.Err => global::System.HashCode.Combine(this.Tag, this.Err),
_ => global::System.HashCode.Combine(this.Tag),
};

[global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
public readonly override bool Equals(object? obj) => obj is Result other && Equals(other);

[global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
public static bool operator ==(Result left, Result right) => Equals(left, right);
[global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
public static bool operator !=(Result left, Result right) => !Equals(left, right);

[global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
public readonly int CompareTo(Result other) => this.Tag != other.Tag ? Comparer.Default.Compare(this.Tag, other.Tag) : this.Tag switch
{
Tags.Ok => global::System.Collections.Generic.Comparer.Default.Compare(this.Ok, other.Ok),
Tags.Err => global::System.Collections.Generic.Comparer.Default.Compare(this.Err, other.Err),
_ => 0,
};

[global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
public static bool operator <(Result left, Result right) => left.CompareTo(right) < 0;
[global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
public static bool operator >(Result left, Result right) => left.CompareTo(right) > 0;
[global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
public static bool operator <=(Result left, Result right) => left.CompareTo(right) <= 0;
[global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
public static bool operator >=(Result left, Result right) => left.CompareTo(right) >= 0;

[global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
public readonly override string ToString() => this.Tag switch
{
Tags.Ok => $"{nameof(Result)}.{nameof(Tags.Ok)} {{ {this.Ok} }}",
Tags.Err => $"{nameof(Result)}.{nameof(Tags.Err)} {{ {this.Err} }}",
_ => nameof(Result),
};
}

```