magick_rust/result.rs
1/*
2 * Copyright 2021-2024 DCJanus
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16use std::fmt::{Debug, Display, Formatter};
17
18pub type Result<T> = std::result::Result<T, MagickError>;
19
20/// The crate's error type, wrapping an error message string.
21#[derive(Debug, Clone, PartialEq, Eq, Ord, PartialOrd, Hash)]
22pub struct MagickError(pub String);
23
24impl From<&'static str> for MagickError {
25 fn from(s: &'static str) -> Self {
26 MagickError(s.to_string())
27 }
28}
29
30impl Display for MagickError {
31 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
32 Display::fmt(&self.0, f)
33 }
34}
35
36impl std::error::Error for MagickError {}