Bug 1890689 remove DynamicResampler::mSetBufferDuration r=pehrsons
[gecko.git] / mfbt / Try.h
bloba650a33ea2753d89d12c3cb213d711d59dbea9cd
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * vim: set ts=8 sts=2 et sw=2 tw=80:
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_Try_h
8 #define mozilla_Try_h
10 #include "mozilla/Result.h"
12 /**
13 * MOZ_TRY(expr) is the C++ equivalent of Rust's `try!(expr);`. First, it
14 * evaluates expr, which must produce a Result value. On success, it
15 * discards the result altogether. On error, it immediately returns an error
16 * Result from the enclosing function.
18 #define MOZ_TRY(expr) \
19 do { \
20 auto mozTryTempResult_ = ::mozilla::ToResult(expr); \
21 if (MOZ_UNLIKELY(mozTryTempResult_.isErr())) { \
22 return mozTryTempResult_.propagateErr(); \
23 } \
24 } while (0)
26 /**
27 * MOZ_TRY_VAR(target, expr) is the C++ equivalent of Rust's `target =
28 * try!(expr);`. First, it evaluates expr, which must produce a Result value. On
29 * success, the result's success value is assigned to target. On error,
30 * immediately returns the error result. |target| must be an lvalue.
32 #define MOZ_TRY_VAR(target, expr) \
33 do { \
34 auto mozTryVarTempResult_ = (expr); \
35 if (MOZ_UNLIKELY(mozTryVarTempResult_.isErr())) { \
36 return mozTryVarTempResult_.propagateErr(); \
37 } \
38 (target) = mozTryVarTempResult_.unwrap(); \
39 } while (0)
41 #endif // mozilla_Try_h