Skip to content

Commit

Permalink
✨ Refactored gluer && Added error type && Updated example
Browse files Browse the repository at this point in the history
  • Loading branch information
nwrenger committed Aug 2, 2024
1 parent 6422bde commit ec0d205
Show file tree
Hide file tree
Showing 5 changed files with 287 additions and 274 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,10 @@ pub struct Hello<T: Serialize, S> {
#[metadata]
#[derive(Serialize, Deserialize, Default)]
struct Age {
// #[meta(into = String)]
#[meta(into = String)]
age: AgeInner,
}

#[metadata]
#[derive(Serialize, Deserialize, Default)]
struct AgeInner {
age: u8,
Expand Down
27 changes: 27 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
use std::fmt::Debug;

/// Result type containing the custom error enum
pub type Result<T> = std::result::Result<T, Error>;

/// Error type containing all error cases with extra metadata
pub enum Error {
/// An io operation failed
FileSystem(std::io::Error),
/// Parsing to Typescript failed
Ts(String),
}

impl Debug for Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Error::FileSystem(e) => write!(f, "FileSystem: {}", e),
Error::Ts(e) => write!(f, "Ts: {}", e),
}
}
}

impl From<std::io::Error> for Error {
fn from(e: std::io::Error) -> Self {
Error::FileSystem(e)
}
}
Loading

0 comments on commit ec0d205

Please sign in to comment.