Skip to content

Commit

Permalink
0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
2A5F committed Nov 24, 2023
1 parent d3905b7 commit 9990158
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 20 deletions.
39 changes: 39 additions & 0 deletions ManualTesting/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,42 @@ private interface Template
//}

file struct FileStruct {}

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


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

[Union]
public partial struct Result<T, E>
{
[UnionTemplate]
private interface Template
{
T Ok();
E Err();
}
}
37 changes: 19 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,24 +79,26 @@ public readonly partial struct Union1
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)]
public struct __class_
internal struct __class_
{
[global::System.Runtime.InteropServices.FieldOffset(0)]
public string _0;
[global::System.Runtime.InteropServices.FieldOffset(0)]
public List<int>? _1;
}

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

public __impl_(Tags _tag)
Expand All @@ -112,7 +114,7 @@ public readonly partial struct Union1
public static Union1 MakeA(int value)
{
var _impl = new __impl_(Tags.A);
_impl._unmanaged_._0.Value = value;
_impl._unmanaged_._0 = value;
return new Union1(_impl);
}
[global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
Expand All @@ -126,14 +128,14 @@ public readonly partial struct Union1
public static Union1 MakeC(bool value)
{
var _impl = new __impl_(Tags.C);
_impl._unmanaged_._1.Value = value;
_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 = value;
_impl._unmanaged_._2 = value;
return new Union1(_impl);
}
[global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
Expand Down Expand Up @@ -196,32 +198,32 @@ public readonly partial struct Union1
public int A
{
[global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
get => !this.IsA ? default! : this._impl._unmanaged_._0.Value;
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;
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.Value;
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.Value;
get => !this.IsD ? default! : this._impl._unmanaged_._2!;
}
public List<int>? F
{
[global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
get => !this.IsF ? default! : this._impl._class_._1;
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;
get => !this.IsG ? default! : this._impl._0!;
}

[global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
Expand Down Expand Up @@ -351,7 +353,6 @@ Generate output:

using Sera.TaggedUnion;


public partial struct Option<T>
: global::Sera.TaggedUnion.ITaggedUnion
, global::System.IEquatable<Option<T>>
Expand Down Expand Up @@ -417,7 +418,7 @@ public partial struct Option<T>
public T Some
{
[global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
readonly get => !this.IsSome ? default! : this._impl._0;
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; } }
}
Expand Down Expand Up @@ -553,14 +554,14 @@ public partial struct Result<T, E>
public T Ok
{
[global::System.Runtime.CompilerServices.MethodImpl(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
readonly get => !this.IsOk ? default! : this._impl._0;
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;
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; } }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<IsRoslynComponent>true</IsRoslynComponent>
<Version>0.2.0</Version>
<Version>0.3.0</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion Sera.TaggedUnion/Sera.TaggedUnion.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<AssemblyName>Sera.Union</AssemblyName>
<RootNamespace>Sera.TaggedUnion</RootNamespace>
<Version>0.2.0</Version>
<Version>0.3.0</Version>
<Description>Tagged union for c#</Description>
<PackageProjectUrl>https://github.com/sera-net/Sera.Union</PackageProjectUrl>
<RepositoryUrl>https://github.com/sera-net/Sera.Union</RepositoryUrl>
Expand Down

0 comments on commit 9990158

Please sign in to comment.