fit_adapter.h 871 B

1234567891011121314151617181920212223
  1. // Copyright 2019 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef FUCHSIA_WEB_COMMON_TEST_FIT_ADAPTER_H_
  5. #define FUCHSIA_WEB_COMMON_TEST_FIT_ADAPTER_H_
  6. #include <lib/fit/function.h>
  7. #include "base/bind.h"
  8. #include "base/callback_helpers.h"
  9. // Adapts a base::OnceCallback<> to a fit::function<>, to allow //base callbacks
  10. // to be used directly as FIDL result callbacks.
  11. template <typename ReturnType, typename... ArgumentTypes>
  12. fit::function<ReturnType(ArgumentTypes...)> CallbackToFitFunction(
  13. base::OnceCallback<ReturnType(ArgumentTypes...)> callback) {
  14. return [callback = std::move(callback)](ArgumentTypes... args) mutable {
  15. std::move(callback).Run(std::forward<ArgumentTypes>(args)...);
  16. };
  17. }
  18. #endif // FUCHSIA_WEB_COMMON_TEST_FIT_ADAPTER_H_