Lines Matching +full:rust +full:- +full:src
1 {{#title rust::Slice<T> — Rust ♡ C++}}
2 # rust::Slice\<const T\>, rust::Slice\<T\>
4 - Rust `&[T]` is written `rust::Slice<const T>` in C++
5 - Rust `&mut [T]` is written `rust::Slice<T>` in C++
10 // rust/cxx.h
15 # namespace rust {
56 # T *operator->() const noexcept;
61 # iterator &operator--() noexcept;
62 # iterator operator--(int) noexcept;
65 # iterator &operator-=(ptrdiff_t) noexcept;
67 # iterator operator-(ptrdiff_t) const noexcept;
68 # ptrdiff_t operator-(const iterator &) const noexcept;
78 # } // namespace rust
83 T must not be an opaque Rust type or opaque C++ type. Support for opaque Rust
88 Only rust::Slice\<const T\> is copy-assignable, not rust::Slice\<T\>. (Both are
89 move-assignable.) You'll need to write std::move occasionally as a reminder that
90 accidentally exposing overlapping &mut \[T\] to Rust is UB.
95 reading from stdin, but it could be from anywhere), then calls into Rust to
96 pretty-print that JSON data into a std::string via the [serde_json] and
99 [serde_json]: https://github.com/serde-rs/json
100 [serde_transcode]: https://github.com/sfackler/serde-transcode
102 ```rust,noplayground
103 // src/main.rs
113 extern "Rust" {
114 fn prettify_json(input: &[u8], output: Pin<&mut CxxString>) -> Result<()>;
121 fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
125 fn flush(&mut self) -> io::Result<()> {
130 fn prettify_json(input: &[u8], output: Pin<&mut CxxString>) -> serde_json::Result<()> {
139 // src/main.cc
141 #include "example/src/main.rs.h"
151 rust::Slice<const uint8_t> slice{input.data(), input.size()};