• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2021 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef BASE_CONTAINERS_SPAN_RUST_H_
6 #define BASE_CONTAINERS_SPAN_RUST_H_
7 
8 #include <stdint.h>
9 
10 #include "base/containers/span.h"
11 #include "base/rust_buildflags.h"
12 #include "third_party/rust/cxx/v1/cxx.h"
13 
14 #if !BUILDFLAG(BUILD_RUST_BASE_CONVERSIONS)
15 #error "span_rust.h included without BUILD_RUST_BASE_CONVERSIONS"
16 #endif
17 
18 namespace base {
19 
20 // Create a Rust slice from a base::span.
SpanToRustSlice(span<const uint8_t> span)21 inline rust::Slice<const uint8_t> SpanToRustSlice(span<const uint8_t> span) {
22   return rust::Slice<const uint8_t>(span.data(), span.size());
23 }
24 
25 }  // namespace base
26 
27 #endif  // BASE_CONTAINERS_SPAN_RUST_H_
28