CanonSharp/CanonSharp.Combinator/Results/FailedResultWithError.cs

23 lines
764 B
C#
Raw Normal View History

using CanonSharp.Combinator.Abstractions;
namespace CanonSharp.Combinator.Results;
/// <summary>
/// 错误类型的失败解析结果
/// </summary>
/// <typeparam name="TToken">输入流的类型</typeparam>
/// <typeparam name="TState">输入流的读取类型</typeparam>
/// <typeparam name="T">实际的结果类型</typeparam>
internal sealed class FailedResultWithError<TToken, TState, T>(TState state) : FailedResult<TToken, T>
where TState : IReadState<TToken, TState>
{
public override IReadState<TToken> State => state;
public override string Message => $"Unexpected state: {state}.";
public override FailedResult<TToken, TNext> Convert<TNext>()
{
return new FailedResultWithError<TToken, TState, TNext>(state);
}
}