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