mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-16 15:24:10 +02:00
Updated mintest Result
This commit is contained in:
parent
fb73967519
commit
78cdfd5d24
1 changed files with 27 additions and 29 deletions
|
@ -2,9 +2,10 @@ namespace System
|
|||
{
|
||||
enum Result<T> : IDisposable
|
||||
{
|
||||
case Ok(T _val);
|
||||
case Err(void _err);
|
||||
case Ok(T val);
|
||||
case Err(void err);
|
||||
|
||||
[Inline]
|
||||
T Unwrap()
|
||||
{
|
||||
switch (this)
|
||||
|
@ -17,6 +18,14 @@ namespace System
|
|||
}
|
||||
}
|
||||
|
||||
public T Value
|
||||
{
|
||||
get
|
||||
{
|
||||
return Unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
public static implicit operator Result<T>(T value)
|
||||
{
|
||||
return .Ok(value);
|
||||
|
@ -66,19 +75,19 @@ namespace System
|
|||
}
|
||||
|
||||
[SkipCall]
|
||||
public static void NoDispose<TVal>()
|
||||
static void NoDispose<TVal>()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public static void NoDispose<TVal>() where TVal : IDisposable
|
||||
static void NoDispose<TVal>() where TVal : IDisposable
|
||||
{
|
||||
Internal.FatalError("Result must be disposed", 1);
|
||||
}
|
||||
|
||||
public void ReturnValueDiscarded()
|
||||
{
|
||||
if (this case .Err)
|
||||
if (this case .Err(let err))
|
||||
Internal.FatalError("Unhandled error in result", 1);
|
||||
NoDispose<T>();
|
||||
}
|
||||
|
@ -93,18 +102,6 @@ namespace System
|
|||
}
|
||||
}
|
||||
|
||||
/*extension Result<T> where T : class
|
||||
{
|
||||
public static T operator?(Self val)
|
||||
{
|
||||
switch (val)
|
||||
{
|
||||
case .Ok(let inner): return inner;
|
||||
case .Err: return default;
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
enum Result<T, TErr> : IDisposable
|
||||
{
|
||||
case Ok(T val);
|
||||
|
@ -117,15 +114,19 @@ namespace System
|
|||
case .Ok(var val): return val;
|
||||
case .Err(var err):
|
||||
{
|
||||
String errStr = scope String();
|
||||
err.ToString(errStr);
|
||||
String showErr = scope String();
|
||||
showErr.ConcatInto("Unhandled error in result:\n ", errStr);
|
||||
Internal.FatalError(showErr, 2);
|
||||
Internal.FatalError("Unhandled error in result");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public T Value
|
||||
{
|
||||
get
|
||||
{
|
||||
return Unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
public static implicit operator Result<T, TErr>(T value)
|
||||
{
|
||||
return .Ok(value);
|
||||
|
@ -175,12 +176,12 @@ namespace System
|
|||
}
|
||||
|
||||
[SkipCall]
|
||||
public static void NoDispose<TVal>()
|
||||
static void NoDispose<TVal>()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public static void NoDispose<TVal>() where TVal : IDisposable
|
||||
static void NoDispose<TVal>() where TVal : IDisposable
|
||||
{
|
||||
Internal.FatalError("Result must be disposed", 1);
|
||||
}
|
||||
|
@ -189,13 +190,10 @@ namespace System
|
|||
{
|
||||
if (this case .Err(var err))
|
||||
{
|
||||
String errStr = scope String();
|
||||
err.ToString(errStr);
|
||||
String showErr = scope String();
|
||||
showErr.ConcatInto("Unhandled error in result:\n ", errStr);
|
||||
Internal.FatalError(showErr, 1);
|
||||
Internal.FatalError("Unhandled error in result");
|
||||
}
|
||||
NoDispose<T>();
|
||||
NoDispose<TErr>();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue