/* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use std::fmt::Display; use error_support::{handle_error, ErrorHandling, GetErrorHandling}; #[derive(Debug, thiserror::Error)] struct Error {} impl Display for Error { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "Internal Error!") } } #[derive(Debug, thiserror::Error)] struct ExternalError {} impl Display for ExternalError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "External Error!") } } impl GetErrorHandling for Error { type ExternalError = ExternalError; fn get_error_handling(&self) -> error_support::ErrorHandling { ErrorHandling::convert(ExternalError {}) } } #[handle_error(Error)] fn func() -> ::std::result::Result { Err(Error{}) } #[handle_error(Error)] fn func2() -> Result { Err(Error{}) } type MyResult = std::result::Result; #[handle_error(Error)] fn func3() -> MyResult { Err(Error{}) } type FullyAliasedResult = std::result::Result; #[handle_error(Error)] fn func4() -> FullyAliasedResult { Err(Error{}) } mod submodule { #[super::handle_error(super::Error)] pub(super) fn func() -> ::std::result::Result { Err(super::Error{}) } } fn main() { // We verify that all functions now return Result let _: Vec = vec![ func().unwrap_err(), func2().unwrap_err(), func3().unwrap_err(), func4().unwrap_err(), submodule::func().unwrap_err(), ]; }