Bug 1879449 [wpt PR 44489] - [wptrunner] Add `infrastructure/expected-fail/` test...
[gecko.git] / layout / style / RustCell.h
blob24f2ebc74dd2b7a69535f1e7eb276a4692acbc7e
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 /* an object with the same layout as a Rust std::cell::Cell<T> */
9 #ifndef mozilla_RustCell_h
10 #define mozilla_RustCell_h
12 namespace mozilla {
14 /**
15 * Object with the same layout as std::cell::Cell<T>.
17 * ServoBindings.toml defines a mapping so that generated bindings use a
18 * real std::cell::Cell<T>.
20 * Note that while the layout matches, this doesn't have the same ABI as a
21 * std::cell::Cell<T>, so values of this type can't be passed over FFI
22 * functions.
24 template <typename T>
25 class RustCell {
26 public:
27 RustCell() : mValue() {}
28 explicit RustCell(T aValue) : mValue(aValue) {}
30 T Get() const { return mValue; }
31 void Set(T aValue) { mValue = aValue; }
33 // That this API doesn't mirror the API of rust's Cell because all values in
34 // C++ effectively act like they're wrapped in Cell<...> already, so this type
35 // only exists for FFI purposes.
36 T* AsPtr() { return &mValue; }
37 const T* AsPtr() const { return &mValue; }
39 private:
40 T mValue;
43 } // namespace mozilla
45 #endif // mozilla_RustCell_h