1 /* 2 * Copyright (C) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 //! Error codes definitions. 17 18 /// Error codes. 19 #[repr(i32)] 20 pub enum FusionErrorCode { 21 /// Operation failed. 22 Fail, 23 /// Invalid input parameter(s). 24 InvalidParam, 25 } 26 27 impl From<FusionErrorCode> for i32 { from(value: FusionErrorCode) -> Self28 fn from(value: FusionErrorCode) -> Self 29 { 30 match value { 31 FusionErrorCode::Fail => { -1i32 }, 32 FusionErrorCode::InvalidParam => { -2i32 }, 33 } 34 } 35 } 36 37 impl TryFrom<i32> for FusionErrorCode { 38 type Error = FusionErrorCode; 39 try_from(value: i32) -> Result<Self, Self::Error>40 fn try_from(value: i32) -> Result<Self, Self::Error> { 41 match value { 42 _ if i32::from(FusionErrorCode::Fail) == value => { Ok(FusionErrorCode::Fail) }, 43 _ if i32::from(FusionErrorCode::InvalidParam) == value => { Ok(FusionErrorCode::InvalidParam) }, 44 _ => { Err(FusionErrorCode::Fail) }, 45 } 46 } 47 } 48 49 /// IPC specific Result, error is i32 type 50 pub type FusionResult<T> = std::result::Result<T, i32>; 51