Skip to content

Commit 431dec1

Browse files
committed
Use Slice<T> for mutable slices
1 parent 5bef27d commit 431dec1

File tree

2 files changed

+0
-83
lines changed

2 files changed

+0
-83
lines changed

gen/src/builtin.rs

-35
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ pub struct Builtins<'a> {
88
pub rust_string: bool,
99
pub rust_str: bool,
1010
pub rust_slice: bool,
11-
pub rust_mut_slice: bool,
1211
pub rust_box: bool,
1312
pub rust_vec: bool,
1413
pub rust_fn: bool,
@@ -23,8 +22,6 @@ pub struct Builtins<'a> {
2322
pub rust_str_repr: bool,
2423
pub rust_slice_new: bool,
2524
pub rust_slice_repr: bool,
26-
pub rust_mut_slice_new: bool,
27-
pub rust_mut_slice_repr: bool,
2825
pub exception: bool,
2926
pub relocatable: bool,
3027
pub friend_impl: bool,
@@ -62,10 +59,6 @@ pub(super) fn write(out: &mut OutFile) {
6259
builtin.friend_impl = true;
6360
}
6461

65-
if builtin.rust_mut_slice {
66-
builtin.friend_impl = true;
67-
}
68-
6962
if builtin.rust_box {
7063
include.new = true;
7164
include.type_traits = true;
@@ -119,7 +112,6 @@ pub(super) fn write(out: &mut OutFile) {
119112
ifndef::write(out, builtin.rust_string, "CXXBRIDGE05_RUST_STRING");
120113
ifndef::write(out, builtin.rust_str, "CXXBRIDGE05_RUST_STR");
121114
ifndef::write(out, builtin.rust_slice, "CXXBRIDGE05_RUST_SLICE");
122-
ifndef::write(out, builtin.rust_mut_slice, "CXXBRIDGE05_RUST_MUT_SLICE");
123115
ifndef::write(out, builtin.rust_box, "CXXBRIDGE05_RUST_BOX");
124116
ifndef::write(out, builtin.unsafe_bitcopy, "CXXBRIDGE05_RUST_BITCOPY");
125117
ifndef::write(out, builtin.rust_vec, "CXXBRIDGE05_RUST_VEC");
@@ -214,33 +206,6 @@ pub(super) fn write(out: &mut OutFile) {
214206
writeln!(out, "}};");
215207
}
216208

217-
if builtin.rust_mut_slice_new || builtin.rust_mut_slice_repr {
218-
out.next_section();
219-
writeln!(out, "template <typename T>");
220-
writeln!(out, "class impl<MutSlice<T>> final {{");
221-
writeln!(out, "public:");
222-
if builtin.rust_mut_slice_new {
223-
writeln!(
224-
out,
225-
" static MutSlice<T> slice(repr::PtrLen repr) noexcept {{",
226-
);
227-
writeln!(
228-
out,
229-
" return {{static_cast<T *>(repr.ptr), repr.len}};",
230-
);
231-
writeln!(out, " }}");
232-
}
233-
if builtin.rust_mut_slice_repr {
234-
writeln!(
235-
out,
236-
" static repr::PtrLen repr(MutSlice<T> slice) noexcept {{",
237-
);
238-
writeln!(out, " return repr::PtrLen{{slice.ptr, slice.len}};");
239-
writeln!(out, " }}");
240-
}
241-
writeln!(out, "}};");
242-
}
243-
244209
if builtin.rust_error {
245210
out.next_section();
246211
writeln!(out, "template <>");

include/cxx.h

-48
Original file line numberDiff line numberDiff line change
@@ -116,30 +116,6 @@ class Slice final {
116116
};
117117
#endif // CXXBRIDGE05_RUST_SLICE
118118

119-
#ifndef CXXBRIDGE05_RUST_MUT_SLICE
120-
template <typename T>
121-
class MutSlice final {
122-
public:
123-
MutSlice() noexcept;
124-
MutSlice(T *, size_t count) noexcept;
125-
126-
MutSlice &operator=(const MutSlice<T> &) noexcept = default;
127-
128-
T *data() const noexcept;
129-
size_t size() const noexcept;
130-
size_t length() const noexcept;
131-
132-
~MutSlice() noexcept = default;
133-
134-
private:
135-
friend impl<MutSlice>;
136-
// Not necessarily ABI compatible with &mut [T]. Codegen will translate to
137-
// cxx::rust_mutsliceu8::RustMutSliceU8 which matches this layout.
138-
T *ptr;
139-
size_t len;
140-
};
141-
#endif // CXXBRIDGE05_RUST_MUT_SLICE
142-
143119
#ifndef CXXBRIDGE05_RUST_BOX
144120
template <typename T>
145121
class Box final {
@@ -406,30 +382,6 @@ size_t Slice<T>::length() const noexcept {
406382
}
407383
#endif // CXXBRIDGE05_RUST_SLICE
408384

409-
#ifndef CXXBRIDGE05_RUST_MUT_SLICE
410-
#define CXXBRIDGE05_RUST_MUT_SLICE
411-
template <typename T>
412-
MutSlice<T>::MutSlice() noexcept : ptr(reinterpret_cast<T *>(this)), len(0) {}
413-
414-
template <typename T>
415-
MutSlice<T>::MutSlice(T *s, size_t count) noexcept : ptr(s), len(count) {}
416-
417-
template <typename T>
418-
T *MutSlice<T>::data() const noexcept {
419-
return this->ptr;
420-
}
421-
422-
template <typename T>
423-
size_t MutSlice<T>::size() const noexcept {
424-
return this->len;
425-
}
426-
427-
template <typename T>
428-
size_t MutSlice<T>::length() const noexcept {
429-
return this->len;
430-
}
431-
#endif // CXXBRIDGE05_RUST_MUT_SLICE
432-
433385
#ifndef CXXBRIDGE05_RUST_BOX
434386
#define CXXBRIDGE05_RUST_BOX
435387
template <typename T>

0 commit comments

Comments
 (0)