using System;
namespace MathInterpreter.Core;
///
/// Result object of scan operations
///
/// Type of the parsed value
public readonly ref struct ScanResult where T : struct
{
///
/// Creates a new scan result based on a successfully parsed value - if parsing failed an Exception
/// would have been thrown and this constructor would not be called
///
/// Parsed value
/// Number of characters (digits) of the parsed value
/// Remaining part of the expression after extracting and parsing the value
/// Thrown if an invalid argument is provided
public ScanResult(T value, int length, ReadOnlySpan remainingExpression)
{
if (length < 0)
{
throw new ArgumentOutOfRangeException(nameof(length), "Length must be non-negative");
}
Value = value;
Length = length;
RemainingExpression = remainingExpression;
}
///
/// Gets the parsed value
///
public T Value { get; }
///
/// Gets the number of characters (digits) of the parsed value
///
public int Length { get; }
///
/// Gets the remaining part of the expression after extracting and parsing the value
///
public ReadOnlySpan RemainingExpression { get; }
}