span_rust.h 618 B

12345678910111213141516171819202122
  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_CONTAINERS_SPAN_RUST_H_
  5. #define BASE_CONTAINERS_SPAN_RUST_H_
  6. #include <stdint.h>
  7. #include "base/containers/span.h"
  8. #include "third_party/rust/cxx/v1/crate/include/cxx.h"
  9. namespace base {
  10. // Create a Rust slice from a base::span.
  11. inline rust::Slice<const uint8_t> SpanToRustSlice(span<const uint8_t> span) {
  12. return rust::Slice<const uint8_t>(span.data(), span.size());
  13. }
  14. } // namespace base
  15. #endif // BASE_CONTAINERS_SPAN_RUST_H_