1 /* 2 * Copyright (C) 2021 The Android Open Source Project 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 */ 16 #pragma once 17 18 #include <error/expected_utils.h> 19 #include <utils/Errors.h> 20 21 namespace android { 22 namespace error { 23 24 /** 25 * A convenience short-hand for base::expected, where the error type is a status_t. 26 */ 27 template <typename T> 28 using Result = base::expected<T, status_t>; 29 30 } // namespace error 31 } // namespace android 32 33 // Below are the implementations of errorIsOk and errorToString for status_t . 34 // This allows status_t to be used in conjunction with the expected_utils.h macros. 35 // Unfortuantely, since status_t is merely a typedef for int rather than a unique type, we have to 36 // overload these methods for any int, and do so in the global namespace for ADL to work. 37 errorIsOk(int status)38inline bool errorIsOk(int status) { 39 return status == android::OK; 40 } 41 errorToString(int status)42inline std::string errorToString(int status) { 43 return android::statusToString(status); 44 } 45