use rand::Rng;
use std::error;
use std::fmt;
#[derive(Debug, Clone)]
pub struct RequiredEventNotCompleted;
impl std::fmt::Display for RequiredEventNotCompleted {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "The required event has not been completed yet.")
}
}
impl error::Error for RequiredEventNotCompleted {}
impl From<&std::boxed::Box<dyn std::error::Error + 'static>> for RequiredEventNotCompleted {
fn from(_: &std::boxed::Box<dyn std::error::Error + 'static>) -> Self {
RequiredEventNotCompleted
}
}
#[derive(Debug, Clone)]
pub struct InvalidEvent;
impl std::fmt::Display for InvalidEvent {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let mut rng = rand::thread_rng();
let error_messages = [
"Perhaps you should try something else.",
"Maybe something else needs to be done first.",
"You can't do that.",
"I don't understand that.",
"I don't know how to do that.",
"I would do anything for love, but I won't do that.",
];
write!(
f,
"{}",
error_messages[rng.gen_range(0..error_messages.len())]
)
}
}
impl error::Error for InvalidEvent {}
impl From<&std::boxed::Box<dyn std::error::Error + 'static>> for InvalidEvent {
fn from(_: &std::boxed::Box<dyn std::error::Error + 'static>) -> Self {
InvalidEvent
}
}
#[derive(Debug, Clone)]
pub struct InvalidAction;
impl std::fmt::Display for InvalidAction {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "The action is not valid.")
}
}
impl error::Error for InvalidAction {}
impl From<&std::boxed::Box<dyn std::error::Error + 'static>> for InvalidAction {
fn from(_: &std::boxed::Box<dyn std::error::Error + 'static>) -> Self {
InvalidAction
}
}
#[derive(Debug, Clone)]
pub struct InvalidItem;
impl std::fmt::Display for InvalidItem {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "The item is invalid.")
}
}
impl error::Error for InvalidItem {}
impl From<&std::boxed::Box<dyn std::error::Error + 'static>> for InvalidItem {
fn from(_: &std::boxed::Box<dyn std::error::Error + 'static>) -> Self {
InvalidItem
}
}
#[derive(Debug, Clone)]
pub struct InvalidSubject;
impl std::fmt::Display for InvalidSubject {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "The subject is invalid.")
}
}
impl error::Error for InvalidSubject {}
impl From<&std::boxed::Box<dyn std::error::Error + 'static>> for InvalidSubject {
fn from(_: &std::boxed::Box<dyn std::error::Error + 'static>) -> Self {
InvalidSubject
}
}
#[derive(Debug, Clone)]
pub struct InvalidVerb;
impl std::fmt::Display for InvalidVerb {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "The verb is invalid.")
}
}
impl error::Error for InvalidVerb {}
impl From<&std::boxed::Box<dyn std::error::Error + 'static>> for InvalidVerb {
fn from(_: &std::boxed::Box<dyn std::error::Error + 'static>) -> Self {
InvalidVerb
}
}
#[derive(Debug, Clone)]
pub struct InvalidMovement;
impl std::fmt::Display for InvalidMovement {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "You can't go that way.")
}
}
impl error::Error for InvalidMovement {}
impl From<&std::boxed::Box<dyn std::error::Error + 'static>> for InvalidMovement {
fn from(_: &std::boxed::Box<dyn std::error::Error + 'static>) -> Self {
InvalidMovement
}
}
#[derive(Debug, Clone)]
pub struct InvalidDirection;
impl std::fmt::Display for InvalidDirection {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "You can't go that way.")
}
}
impl error::Error for InvalidDirection {}
impl From<&std::boxed::Box<dyn std::error::Error + 'static>> for InvalidDirection {
fn from(_: &std::boxed::Box<dyn std::error::Error + 'static>) -> Self {
InvalidDirection
}
}
#[derive(Debug, Clone)]
pub struct InvalidRoom;
impl std::fmt::Display for InvalidRoom {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "The room is invalid.")
}
}
impl error::Error for InvalidRoom {}
impl From<&std::boxed::Box<dyn std::error::Error + 'static>> for InvalidRoom {
fn from(_: &std::boxed::Box<dyn std::error::Error + 'static>) -> Self {
InvalidRoom
}
}
#[derive(Debug, Clone)]
pub struct InvalidVerbItemSubject;
impl std::fmt::Display for InvalidVerbItemSubject {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "Invalid combination of verb, item, and subject.")
}
}
impl error::Error for InvalidVerbItemSubject {}
impl From<&std::boxed::Box<dyn std::error::Error + 'static>> for InvalidVerbItemSubject {
fn from(_: &std::boxed::Box<dyn std::error::Error + 'static>) -> Self {
InvalidVerbItemSubject
}
}
#[derive(Debug, Clone)]
pub struct InvalidVerbSubject;
impl std::fmt::Display for InvalidVerbSubject {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "Invalid combination of verb and subject.")
}
}
impl error::Error for InvalidVerbSubject {}
impl From<&std::boxed::Box<dyn std::error::Error + 'static>> for InvalidVerbSubject {
fn from(_: &std::boxed::Box<dyn std::error::Error + 'static>) -> Self {
InvalidVerbSubject
}
}
#[derive(Debug, Clone)]
pub struct InvalidVerbItem;
impl std::fmt::Display for InvalidVerbItem {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "Invalid combination of verb and item.")
}
}
impl error::Error for InvalidVerbItem {}
impl From<&std::boxed::Box<dyn std::error::Error + 'static>> for InvalidVerbItem {
fn from(_: &std::boxed::Box<dyn std::error::Error + 'static>) -> Self {
InvalidVerbItem
}
}
#[derive(Debug, Clone)]
pub struct ParsingRoomText;
impl std::fmt::Display for ParsingRoomText {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "There was an error parsing the text for the room.")
}
}
impl error::Error for ParsingRoomText {}
impl From<&std::boxed::Box<dyn std::error::Error + 'static>> for ParsingRoomText {
fn from(_: &std::boxed::Box<dyn std::error::Error + 'static>) -> Self {
ParsingRoomText
}
}
#[derive(Debug, Clone)]
pub struct NoRoom;
impl std::fmt::Display for NoRoom {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "This room doesn't exist.")
}
}
impl error::Error for NoRoom {}
impl From<&std::boxed::Box<dyn std::error::Error + 'static>> for NoRoom {
fn from(_: &std::boxed::Box<dyn std::error::Error + 'static>) -> Self {
NoRoom
}
}
#[derive(Debug, Clone)]
pub struct CantPick;
impl std::fmt::Display for CantPick {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "You can't pick that up.")
}
}
impl error::Error for CantPick {}
impl From<&std::boxed::Box<dyn std::error::Error + 'static>> for CantPick {
fn from(_: &std::boxed::Box<dyn std::error::Error + 'static>) -> Self {
CantPick
}
}
#[derive(Debug, Clone)]
pub struct NoItem;
impl std::fmt::Display for NoItem {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "You're not carrying that.")
}
}
impl error::Error for NoItem {}
impl From<&std::boxed::Box<dyn std::error::Error + 'static>> for NoItem {
fn from(_: &std::boxed::Box<dyn std::error::Error + 'static>) -> Self {
NoItem
}
}
#[derive(Debug, Clone)]
pub struct ItemNotFound;
impl std::fmt::Display for ItemNotFound {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "The item can't be found.")
}
}
impl error::Error for ItemNotFound {}
impl From<&std::boxed::Box<dyn std::error::Error + 'static>> for ItemNotFound {
fn from(_: &std::boxed::Box<dyn std::error::Error + 'static>) -> Self {
ItemNotFound
}
}
#[derive(Debug, Clone)]
pub struct EmptyInput;
impl std::fmt::Display for EmptyInput {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "No input. Nothing to process.")
}
}
impl error::Error for EmptyInput {}
impl From<&std::boxed::Box<dyn std::error::Error + 'static>> for EmptyInput {
fn from(_: &std::boxed::Box<dyn std::error::Error + 'static>) -> Self {
EmptyInput
}
}
#[derive(Debug, Clone)]
pub struct InvalidNarrative;
impl std::fmt::Display for InvalidNarrative {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "The narrative is invalid.")
}
}
impl error::Error for InvalidNarrative {}
impl From<&std::boxed::Box<dyn std::error::Error + 'static>> for InvalidNarrative {
fn from(_: &std::boxed::Box<dyn std::error::Error + 'static>) -> Self {
InvalidNarrative
}
}