summary refs log blame commit diff stats
path: root/src/error.rs
blob: 74ba2fdc8d198a2873aba37eb602c5fbfc093282 (plain) (tree)









































                                                                                
// Copyright (c) 2021 Soni L.
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
// Documentation and comments licensed under CC BY-SA 4.0.

//! Built-in error traits.
//!
//! Iosonism uses a trait-based approach because that's just far more flexible.

use ::std::error::Error as StdError;

use crate::strcursor::StringReader;

/// Built-in `StringReader` errors.
pub trait ReadError<'a, C: StringReader<'a>>: Sized + StdError {
    /// Creates an error that indicates an invalid integer was found.
    fn invalid_integer(context: &C, from: &str) -> Self;
    /// Creates an error that indicates an integer was expected.
    fn expected_integer(context: &C) -> Self;
    /// Creates an error that indicates an invalid float was found.
    fn invalid_float(context: &C, from: &str) -> Self;
    /// Creates an error that indicates a float was expected.
    fn expected_float(context: &C) -> Self;
    /// Creates an error that indicates an invalid bool was found.
    fn invalid_bool(context: &C, from: &str) -> Self;
    /// Creates an error that indicates a bool was expected.
    fn expected_bool(context: &C) -> Self;
    /// Creates an error that indicates the start of a quote was expected.
    fn expected_start_of_quote(context: &C) -> Self;
    /// Creates an error that indicates the end of a quote was expected.
    fn expected_end_of_quote(context: &C) -> Self;
    /// Creates an error that indicates an invalid escape was found.
    fn invalid_escape(context: &C, from: &str) -> Self;
    /// Creates an error that indicates a symbol was expected.
    fn expected_symbol(context: &C, from: &str) -> Self;
}

/// Built-in errors for `IntegerArgumentType` and `FloatArgumentType`.
pub trait RangeError<'a, C: StringReader<'a>, T, R>: Sized + StdError {
    /// Creates an error that indicates a value was outside the required bounds.
    fn value_not_in_range(context: &C, from: &T, range: &R) -> Self;
}