[backend/core] Switch to Iceshrimp.Utils.Common for Result<T>
This commit is contained in:
parent
77936b710d
commit
905b7d173a
3 changed files with 2 additions and 84 deletions
|
@ -6,9 +6,9 @@ using Iceshrimp.Backend.Core.Database.Tables;
|
||||||
using Iceshrimp.Backend.Core.Extensions;
|
using Iceshrimp.Backend.Core.Extensions;
|
||||||
using Iceshrimp.Backend.Core.Federation.ActivityStreams.Types;
|
using Iceshrimp.Backend.Core.Federation.ActivityStreams.Types;
|
||||||
using Iceshrimp.Backend.Core.Federation.WebFinger;
|
using Iceshrimp.Backend.Core.Federation.WebFinger;
|
||||||
using Iceshrimp.Backend.Core.Helpers;
|
|
||||||
using Iceshrimp.Backend.Core.Middleware;
|
using Iceshrimp.Backend.Core.Middleware;
|
||||||
using Iceshrimp.Backend.Core.Services;
|
using Iceshrimp.Backend.Core.Services;
|
||||||
|
using Iceshrimp.Utils.Common;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
|
|
||||||
|
|
|
@ -1,83 +0,0 @@
|
||||||
using System.Diagnostics.CodeAnalysis;
|
|
||||||
|
|
||||||
namespace Iceshrimp.Backend.Core.Helpers;
|
|
||||||
|
|
||||||
public abstract record Result<TResult, TError>
|
|
||||||
where TResult : class
|
|
||||||
where TError : class
|
|
||||||
{
|
|
||||||
private Result() { }
|
|
||||||
|
|
||||||
public sealed record Success(TResult Result) : Result<TResult, TError>;
|
|
||||||
|
|
||||||
public sealed record Failure(TError Error) : Result<TResult, TError>;
|
|
||||||
|
|
||||||
public static implicit operator Result<TResult, TError>(TResult result) => new Success(result);
|
|
||||||
public static implicit operator Result<TResult, TError>(TError error) => new Failure(error);
|
|
||||||
|
|
||||||
public bool TryGetResult([NotNullWhen(true)] out TResult? result)
|
|
||||||
{
|
|
||||||
if (this is Success s)
|
|
||||||
{
|
|
||||||
result = s.Result;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
result = null;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool TryGetError([NotNullWhen(true)] out TError? error)
|
|
||||||
{
|
|
||||||
if (this is Failure f)
|
|
||||||
{
|
|
||||||
error = f.Error;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
error = null;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool IsSuccess => this is Success;
|
|
||||||
public bool IsFailure => this is Failure;
|
|
||||||
}
|
|
||||||
|
|
||||||
public abstract record Result<TResult> where TResult : class
|
|
||||||
{
|
|
||||||
private Result() { }
|
|
||||||
|
|
||||||
public sealed record Success(TResult Result) : Result<TResult>;
|
|
||||||
|
|
||||||
public sealed record Failure(Exception Error) : Result<TResult>;
|
|
||||||
|
|
||||||
public static implicit operator Result<TResult>(TResult result) => new Success(result);
|
|
||||||
public static implicit operator Result<TResult>(Exception error) => new Failure(error);
|
|
||||||
|
|
||||||
public bool TryGetResult([NotNullWhen(true)] out TResult? result)
|
|
||||||
{
|
|
||||||
if (this is Success s)
|
|
||||||
{
|
|
||||||
result = s.Result;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
result = null;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool TryGetError([NotNullWhen(true)] out Exception? error)
|
|
||||||
{
|
|
||||||
if (this is Failure f)
|
|
||||||
{
|
|
||||||
error = f.Error;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
error = null;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool IsSuccess => this is Success;
|
|
||||||
public bool IsFailure => this is Failure;
|
|
||||||
}
|
|
|
@ -54,6 +54,7 @@
|
||||||
<PackageReference Include="Iceshrimp.Assets.Branding" Version="1.0.1" />
|
<PackageReference Include="Iceshrimp.Assets.Branding" Version="1.0.1" />
|
||||||
<PackageReference Include="Iceshrimp.AssemblyUtils" Version="1.0.3" />
|
<PackageReference Include="Iceshrimp.AssemblyUtils" Version="1.0.3" />
|
||||||
<PackageReference Include="Iceshrimp.MfmSharp" Version="1.2.17" />
|
<PackageReference Include="Iceshrimp.MfmSharp" Version="1.2.17" />
|
||||||
|
<PackageReference Include="Iceshrimp.Utils.Common" Version="1.0.0" />
|
||||||
<PackageReference Include="Iceshrimp.MimeTypes" Version="1.0.1" />
|
<PackageReference Include="Iceshrimp.MimeTypes" Version="1.0.1" />
|
||||||
<PackageReference Include="Iceshrimp.WebPush" Version="2.1.0" />
|
<PackageReference Include="Iceshrimp.WebPush" Version="2.1.0" />
|
||||||
<PackageReference Include="NetVips" Version="3.0.0" />
|
<PackageReference Include="NetVips" Version="3.0.0" />
|
||||||
|
|
Loading…
Add table
Reference in a new issue