use std::cell::RefCell; use std::error::Error as StdError; use std::fmt; use std::rc::Rc; use crate::spec::Spec; #[derive(Clone)] pub struct SpecErr { pub spec: Rc>>, pub msg: String } impl fmt::Display for SpecErr { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.write_fmt(format_args!("spec")) } } #[derive(Clone)] pub enum ErrKind { MissArg(SpecErr), MissSpec(String), BadContext(String), UnknownOpt(String), Collision(String) } impl StdError for ErrKind {} impl fmt::Display for ErrKind { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match &*self { ErrKind::MissArg(s) => { f.write_fmt(format_args!("Missing argument ({})", s)) } ErrKind::MissSpec(s) => { f.write_fmt(format_args!("Missing argspec; {}", s)) } ErrKind::BadContext(s) => { f.write_fmt(format_args!("Bad context; {}", s)) } ErrKind::UnknownOpt(s) => { f.write_fmt(format_args!("Unknown option; {}", s)) } ErrKind::Collision(s) => { f.write_fmt(format_args!("Colliding options; {}", s)) } } } } impl fmt::Debug for ErrKind { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match &*self { ErrKind::MissArg(s) => { f.write_fmt(format_args!("Missing argument ({})", s)) } ErrKind::MissSpec(s) => { f.write_fmt(format_args!("Missing argspec; {}", s)) } ErrKind::BadContext(s) => { f.write_fmt(format_args!("Bad context; {}", s)) } ErrKind::UnknownOpt(s) => { f.write_fmt(format_args!("Unknown option; {}", s)) } ErrKind::Collision(s) => { f.write_fmt(format_args!("Colliding options; {}", s)) } } } } // vim: set ft=rust et sw=2 ts=2 sts=2 cinoptions=2 tw=79 :