Added a table to the database.

This commit is contained in:
2022-08-06 12:03:47 -04:00
parent ac869f8188
commit 07fc00fa93
2 changed files with 135 additions and 11 deletions

View File

@ -5,6 +5,24 @@ pub enum MTTError {
Generic(Generic),
}
impl MTTError {
pub fn new<S>(detail: S) -> Self
where
S: Into<String>,
{
Generic::new(detail).into()
}
pub fn add_source<E>(&mut self, source: E)
where
E: Into<MTTError>,
{
match self {
MTTError::Generic(err) => err.add_source(source),
}
}
}
impl Error for MTTError {
fn source(&self) -> Option<&(dyn Error + 'static)> {
match self {
@ -34,9 +52,12 @@ pub struct Generic {
}
impl Generic {
fn new(detail: &str) -> Self {
fn new<S>(detail: S) -> Self
where
S: Into<String>,
{
Self {
detail: detail.to_string(),
detail: detail.into(),
source: None,
}
}
@ -65,11 +86,58 @@ impl fmt::Display for Generic {
}
#[cfg(test)]
mod generics {
mod mtterror {
use super::*;
#[test]
fn new_error() {
fn create_with_str() {
let detail = "Something";
let err = MTTError::new(detail);
assert!(
err.to_string() == detail,
"\n\nGot: {}\nWant: {}\n\n",
err.to_string(),
detail
);
assert!(
err.source().is_none(),
"Error source should initialoze to None."
);
}
#[test]
fn create_with_string() {
let detail = "massive".to_string();
let err = MTTError::new(detail.clone());
assert!(
err.to_string() == detail,
"\n\nGot: {}\nWant: {}\n\n",
err.to_string(),
detail
);
}
#[test]
fn with_source() {
let mut err = MTTError::new("the error");
let detail = "This is the cause";
let src = MTTError::new(detail);
err.add_source(src);
assert!(
err.source().unwrap().to_string() == detail,
"/n/nGot: {}\nWant: {}\n\n",
err.source().unwrap().to_string(),
detail
);
}
}
#[cfg(test)]
mod generic {
use super::*;
#[test]
fn create_with_str() {
let detail = "new error";
let err = Generic::new(detail);
assert!(
@ -92,7 +160,19 @@ mod generics {
}
#[test]
fn error_with_source() {
fn create_with_string() {
let detail = "some error".to_string();
let err = Generic::new(detail.clone());
assert!(
err.to_string() == detail,
"\n\nGot: {}\nWant: {}\n\n",
err.to_string(),
detail
);
}
#[test]
fn with_source() {
let par_detail = "parent error";
let cld_detail = "child error";
let par_err = Generic::new(par_detail);