xref: /aosp_15_r20/external/cronet/base/files/file_error_or.h (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright 2021 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef BASE_FILES_FILE_ERROR_OR_H_
6 #define BASE_FILES_FILE_ERROR_OR_H_
7 
8 #include "base/files/file.h"
9 #include "base/types/expected.h"
10 
11 namespace base {
12 
13 // Helper for methods which perform file system operations and which may fail.
14 // Objects of this type can take on EITHER a base::File::Error value OR a result
15 // value of the specified type. For example:
16 //
17 // base::FileErrorOr<int64_t> GetSize() {
18 //   if (failed_to_get_size)
19 //     return base::unexpected(base::File::Error::FILE_ERROR_FAILED);
20 //
21 //   return size;
22 // }
23 //
24 template <class ValueType>
25 using FileErrorOr = expected<ValueType, File::Error>;
26 
27 }  // namespace base
28 
29 #endif  // BASE_FILES_FILE_ERROR_OR_H_
30