xbasic 0.3.2

A library that allows adding a scripting language onto your project with ease. This lets your users write their own arbitrary logic.
Documentation
use std::fmt;

/// Represents an error when defining a custom xBASIC function
#[derive(Debug, PartialEq)]
pub enum DefineFunctionError {
	NameInUse,
	FunctionLimitReached,
}

impl fmt::Display for DefineFunctionError {
	fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
		match self {
			DefineFunctionError::NameInUse => write!(f, "Function name is already in use"),
			DefineFunctionError::FunctionLimitReached => write!(
				f,
				"The maximum number of functions have already been defined"
			),
		}
	}
}

impl std::error::Error for DefineFunctionError {}

/// Represents an error when running some xBASIC code
#[derive(Debug, PartialEq)]
pub enum RunError {
	Scan,
	ResolveFunctions,
	Parse,
	Compile,
	Runtime,
}

impl fmt::Display for RunError {
	fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
		use RunError::*;
		match self {
			Scan => write!(f, "Could not scan code"),
			ResolveFunctions => write!(f, "Could not resolve functions"),
			Parse => write!(f, "Could not parse into tokens"),
			Compile => write!(f, "Could not compile tokens into bytecode"),
			Runtime => write!(f, "Could not execute bytecode"),
		}
	}
}

impl std::error::Error for RunError {}

/// Represents an error when calling an xBASIC function from Rust
#[derive(Debug, PartialEq)]
pub enum CallFunctionError {
	ArityMismatch,
	Runtime,
	NotFound,
}

impl fmt::Display for CallFunctionError {
	fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
		use CallFunctionError::*;
		match self {
			ArityMismatch => write!(f, "Provided the wrong number of arguments"),
			Runtime => write!(f, "Could not execute bytecode"),
			NotFound => write!(f, "Could not find function by name"),
		}
	}
}

impl std::error::Error for CallFunctionError {}