diff --git a/Cargo.toml b/Cargo.toml index e7f0537..f2052db 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,6 +8,8 @@ exclude = [ "projects/.DS_Store", ] +[workspace.dependencies] + [profile.release] lto = true panic = "abort" diff --git a/projects/sub_projects/Cargo.toml b/projects/sub_projects/Cargo.toml index 04f25bc..9cf797a 100644 --- a/projects/sub_projects/Cargo.toml +++ b/projects/sub_projects/Cargo.toml @@ -4,9 +4,11 @@ publish = false version = "0.0.0" authors = ["Aster <192607617@qq.com>"] description = "..." -repository = "https://github.com/oovm/sub_projects" +categories = ["rust-patterns"] +homepage = "https://github.com/oovm/RustTemplate" +repository = "https://github.com/oovm/RustTemplate" documentation = "https://docs.rs/sub_projects" -readme = "Readme.md" +readme = "readme.md" license = "MPL-2.0" edition = "2021" exclude = ["package.json", "tests/**"] diff --git a/projects/sub_projects/src/errors.rs b/projects/sub_projects/src/errors.rs deleted file mode 100644 index 982023b..0000000 --- a/projects/sub_projects/src/errors.rs +++ /dev/null @@ -1,6 +0,0 @@ -#[derive(Debug, Copy, Clone)] -pub enum Error { - UnknownError -} - -pub type Result = std::result::Result; diff --git a/projects/sub_projects/src/errors/convert.rs b/projects/sub_projects/src/errors/convert.rs new file mode 100644 index 0000000..0042f45 --- /dev/null +++ b/projects/sub_projects/src/errors/convert.rs @@ -0,0 +1,9 @@ +use super::*; + +impl From for ExampleError { + fn from(value: ExampleErrorKind) -> Self { + Self { + kind: Box::new(value), + } + } +} \ No newline at end of file diff --git a/projects/sub_projects/src/errors/display.rs b/projects/sub_projects/src/errors/display.rs new file mode 100644 index 0000000..9fe264c --- /dev/null +++ b/projects/sub_projects/src/errors/display.rs @@ -0,0 +1,23 @@ +use super::*; + +impl Error for ExampleError {} + + +impl Debug for ExampleError { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + Debug::fmt(&self.kind, f) + } +} + +impl Display for ExampleError { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + Display::fmt(&self.kind, f) + } +} + + +impl Display for ExampleErrorKind { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + match self { ExampleErrorKind::UnknownError => { write!(f, "UnknownError") } } + } +} \ No newline at end of file diff --git a/projects/sub_projects/src/errors/mod.rs b/projects/sub_projects/src/errors/mod.rs new file mode 100644 index 0000000..3c864f9 --- /dev/null +++ b/projects/sub_projects/src/errors/mod.rs @@ -0,0 +1,24 @@ +use std::fmt::{Debug, Formatter}; +use std::error::Error; +use std::fmt::Display; + +mod display; +mod convert; + +/// The result type of this crate. +pub type Result = std::result::Result; + +/// A boxed error kind, wrapping an [ExampleErrorKind]. +#[derive(Clone)] +pub struct ExampleError { + kind: Box, +} + +/// The kind of [ExampleError]. +#[derive(Debug, Copy, Clone)] +pub enum ExampleErrorKind { + /// An unknown error. + UnknownError +} + + diff --git a/projects/sub_projects/src/lib.rs b/projects/sub_projects/src/lib.rs index 965d2c2..77909d1 100644 --- a/projects/sub_projects/src/lib.rs +++ b/projects/sub_projects/src/lib.rs @@ -6,4 +6,4 @@ mod errors; -pub use crate::errors::{Error, Result}; +pub use crate::errors::{ExampleErrorKind, Result, ExampleError};