mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-26 19:48:01 +02:00
Added '->' support to nullables and Result<T>
This commit is contained in:
parent
e4cac2ca24
commit
36a8c2c6ae
5 changed files with 93 additions and 8 deletions
|
@ -27,6 +27,22 @@ namespace System
|
|||
}
|
||||
}
|
||||
|
||||
public ref T ValueRef
|
||||
{
|
||||
[Inline]
|
||||
get mut
|
||||
{
|
||||
switch (this)
|
||||
{
|
||||
case .Ok(var ref val): return ref val;
|
||||
case .Err:
|
||||
{
|
||||
Internal.FatalError("Unhandled error in result", 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Inline]
|
||||
public static implicit operator Result<T>(T value)
|
||||
{
|
||||
|
@ -39,6 +55,19 @@ namespace System
|
|||
return result.Unwrap();
|
||||
}
|
||||
|
||||
[Inline]
|
||||
public static mut T operator->(ref Result<T> result)
|
||||
{
|
||||
switch (result)
|
||||
{
|
||||
case .Ok(var mut val): return mut val;
|
||||
case .Err:
|
||||
{
|
||||
Internal.FatalError("Unhandled error in result", 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Inline]
|
||||
public void IgnoreError()
|
||||
{
|
||||
|
@ -116,9 +145,9 @@ namespace System
|
|||
switch (this)
|
||||
{
|
||||
case .Ok(var val): return val;
|
||||
case .Err(var err):
|
||||
case .Err:
|
||||
{
|
||||
Internal.FatalError(scope String()..AppendF("Unhandled error in result:\n {}", err), 2);
|
||||
Internal.FatalError("Unhandled error in result", 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -131,16 +160,47 @@ namespace System
|
|||
}
|
||||
}
|
||||
|
||||
public ref T ValueRef
|
||||
{
|
||||
[Inline]
|
||||
get mut
|
||||
{
|
||||
switch (this)
|
||||
{
|
||||
case .Ok(var ref val): return ref val;
|
||||
case .Err:
|
||||
{
|
||||
Internal.FatalError("Unhandled error in result", 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Inline]
|
||||
public static implicit operator Result<T, TErr>(T value)
|
||||
{
|
||||
return .Ok(value);
|
||||
}
|
||||
|
||||
[Inline]
|
||||
public static implicit operator T(Result<T, TErr> result)
|
||||
{
|
||||
return result.Unwrap();
|
||||
}
|
||||
|
||||
[Inline]
|
||||
public static mut T operator->(ref Result<T, TErr> result)
|
||||
{
|
||||
switch (result)
|
||||
{
|
||||
case .Ok(var mut val): return mut val;
|
||||
case .Err:
|
||||
{
|
||||
Internal.FatalError("Unhandled error in result", 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void IgnoreError()
|
||||
{
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue