mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-04-20 12:45:05 +00:00
Add impl_from! macro to shorten up error code
This commit is contained in:
@@ -58,29 +58,12 @@ pub enum BuildError {
|
||||
BinaryModelEncodeError(rbx_binary::EncodeError)
|
||||
}
|
||||
|
||||
impl From<ProjectLoadFuzzyError> for BuildError {
|
||||
fn from(error: ProjectLoadFuzzyError) -> BuildError {
|
||||
BuildError::ProjectLoadError(error)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<io::Error> for BuildError {
|
||||
fn from(error: io::Error) -> BuildError {
|
||||
BuildError::IoError(error)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<rbx_xml::EncodeError> for BuildError {
|
||||
fn from(error: rbx_xml::EncodeError) -> BuildError {
|
||||
BuildError::XmlModelEncodeError(error)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<rbx_binary::EncodeError> for BuildError {
|
||||
fn from(error: rbx_binary::EncodeError) -> BuildError {
|
||||
BuildError::BinaryModelEncodeError(error)
|
||||
}
|
||||
}
|
||||
impl_from!(BuildError {
|
||||
ProjectLoadFuzzyError => ProjectLoadError,
|
||||
io::Error => IoError,
|
||||
rbx_xml::EncodeError => XmlModelEncodeError,
|
||||
rbx_binary::EncodeError => BinaryModelEncodeError
|
||||
});
|
||||
|
||||
pub fn build(options: &BuildOptions) -> Result<(), BuildError> {
|
||||
let output_kind = options.output_kind
|
||||
|
||||
@@ -15,11 +15,9 @@ pub enum InitError {
|
||||
ProjectInitError(#[fail(cause)] ProjectInitError)
|
||||
}
|
||||
|
||||
impl From<ProjectInitError> for InitError {
|
||||
fn from(error: ProjectInitError) -> InitError {
|
||||
InitError::ProjectInitError(error)
|
||||
}
|
||||
}
|
||||
impl_from!(InitError {
|
||||
ProjectInitError => ProjectInitError,
|
||||
});
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct InitOptions<'a> {
|
||||
|
||||
@@ -26,11 +26,9 @@ pub enum ServeError {
|
||||
ProjectLoadError(#[fail(cause)] ProjectLoadFuzzyError),
|
||||
}
|
||||
|
||||
impl From<ProjectLoadFuzzyError> for ServeError {
|
||||
fn from(error: ProjectLoadFuzzyError) -> ServeError {
|
||||
ServeError::ProjectLoadError(error)
|
||||
}
|
||||
}
|
||||
impl_from!(ServeError {
|
||||
ProjectLoadFuzzyError => ProjectLoadError,
|
||||
});
|
||||
|
||||
pub fn serve(options: &ServeOptions) -> Result<(), ServeError> {
|
||||
info!("Looking for project at {}", options.fuzzy_project_path.display());
|
||||
|
||||
@@ -35,29 +35,12 @@ pub enum UploadError {
|
||||
XmlModelEncodeError(rbx_xml::EncodeError),
|
||||
}
|
||||
|
||||
impl From<ProjectLoadFuzzyError> for UploadError {
|
||||
fn from(error: ProjectLoadFuzzyError) -> UploadError {
|
||||
UploadError::ProjectLoadError(error)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<io::Error> for UploadError {
|
||||
fn from(error: io::Error) -> UploadError {
|
||||
UploadError::IoError(error)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<reqwest::Error> for UploadError {
|
||||
fn from(error: reqwest::Error) -> UploadError {
|
||||
UploadError::HttpError(error)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<rbx_xml::EncodeError> for UploadError {
|
||||
fn from(error: rbx_xml::EncodeError) -> UploadError {
|
||||
UploadError::XmlModelEncodeError(error)
|
||||
}
|
||||
}
|
||||
impl_from!(UploadError {
|
||||
ProjectLoadFuzzyError => ProjectLoadError,
|
||||
io::Error => IoError,
|
||||
reqwest::Error => HttpError,
|
||||
rbx_xml::EncodeError => XmlModelEncodeError,
|
||||
});
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct UploadOptions<'a> {
|
||||
|
||||
18
server/src/impl_from.rs
Normal file
18
server/src/impl_from.rs
Normal file
@@ -0,0 +1,18 @@
|
||||
/// Implements 'From' for a list of variants, intended for use with error enums
|
||||
/// that are wrapping a number of errors from other methods.
|
||||
#[macro_export]
|
||||
macro_rules! impl_from {
|
||||
(
|
||||
$enum_name: ident {
|
||||
$($error_type: ty => $variant_name: ident),* $(,)*
|
||||
}
|
||||
) => {
|
||||
$(
|
||||
impl From<$error_type> for $enum_name {
|
||||
fn from(error: $error_type) -> $enum_name {
|
||||
$enum_name::$variant_name(error)
|
||||
}
|
||||
}
|
||||
)*
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,8 @@
|
||||
// Macros
|
||||
#[macro_use]
|
||||
pub mod impl_from;
|
||||
|
||||
// Other modules
|
||||
pub mod commands;
|
||||
pub mod fs_watcher;
|
||||
pub mod imfs;
|
||||
|
||||
Reference in New Issue
Block a user