values_glue.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. // Copyright 2021 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 BASE_RS_GLUE_VALUES_GLUE_H_
  5. #define BASE_RS_GLUE_VALUES_GLUE_H_
  6. #include <stddef.h>
  7. #include "base/base_export.h"
  8. #include "base/strings/string_piece_rust.h"
  9. #include "base/values.h"
  10. #include "third_party/rust/cxx/v1/crate/include/cxx.h"
  11. namespace base {
  12. namespace rs_glue {
  13. // This file has functions which are called from Rust code to populate
  14. // bits of a base::Value. The functions exist because Rust C++ FFI
  15. // is not yet always good enough to operate on a base::Value directly
  16. // without these intermediate layer. With future inprovements in interop,
  17. // they may disappear.
  18. // Storage space into which a `base::Value` can be constructed.
  19. using ValueSlot = absl::optional<base::Value>;
  20. // Function purposes explained in mod.rs in the same directory.
  21. BASE_EXPORT void ValueSetNoneKey(base::Value& v, rust::Str key);
  22. BASE_EXPORT void ValueSetBoolKey(base::Value& v, rust::Str key, bool value);
  23. BASE_EXPORT void ValueSetIntegerKey(base::Value& v, rust::Str key, int value);
  24. BASE_EXPORT void ValueSetDoubleKey(base::Value& v, rust::Str key, double value);
  25. BASE_EXPORT void ValueSetStringKey(base::Value& v,
  26. rust::Str key,
  27. rust::Str value);
  28. BASE_EXPORT base::Value& ValueSetDictKey(base::Value& v, rust::Str key);
  29. BASE_EXPORT base::Value& ValueSetListKey(base::Value& v, rust::Str key);
  30. BASE_EXPORT void ValueAppendNone(base::Value& v);
  31. BASE_EXPORT void ValueAppendString(base::Value& v, rust::Str value);
  32. BASE_EXPORT base::Value& ValueAppendDict(base::Value& v);
  33. BASE_EXPORT base::Value& ValueAppendList(base::Value& v);
  34. BASE_EXPORT void ValueReserveSize(base::Value& v, size_t len);
  35. BASE_EXPORT std::unique_ptr<ValueSlot> NewValueSlotForTesting();
  36. BASE_EXPORT rust::String DumpValueSlot(const ValueSlot& v);
  37. BASE_EXPORT void ConstructNoneValue(ValueSlot& v);
  38. BASE_EXPORT void ConstructBoolValue(ValueSlot& v, bool value);
  39. BASE_EXPORT void ConstructIntegerValue(ValueSlot& v, int value);
  40. BASE_EXPORT void ConstructDoubleValue(ValueSlot& v, double value);
  41. BASE_EXPORT void ConstructStringValue(ValueSlot& v, rust::Str value);
  42. BASE_EXPORT base::Value& ConstructDictValue(ValueSlot& v);
  43. BASE_EXPORT base::Value& ConstructListValue(ValueSlot& v);
  44. } // namespace rs_glue
  45. } // namespace base
  46. #endif // BASE_RS_GLUE_VALUES_GLUE_H_