@@ -168,9 +168,10 @@ fn pick_includes_and_builtins(out: &mut OutFile, apis: &[Api]) {
168
168
Type :: CxxVector ( _) => out. include . vector = true ,
169
169
Type :: Fn ( _) => out. builtin . rust_fn = true ,
170
170
Type :: Slice ( _) => out. builtin . rust_slice = true ,
171
- Type :: SliceRefU8 ( _ ) => {
171
+ Type :: SliceRefU8 ( ty ) => {
172
172
out. include . cstdint = true ;
173
- out. builtin . rust_slice = true ;
173
+ out. builtin . rust_slice |= ty. mutability . is_none ( ) ;
174
+ out. builtin . rust_mut_slice |= ty. mutability . is_some ( ) ;
174
175
}
175
176
Type :: Ref ( _) | Type :: Void ( _) => { }
176
177
}
@@ -430,10 +431,14 @@ fn write_cxx_function_shim<'a>(out: &mut OutFile<'a>, efn: &'a ExternFn) {
430
431
out. builtin . rust_str_repr = true ;
431
432
write ! ( out, "::rust::impl<::rust::Str>::repr(" ) ;
432
433
}
433
- Some ( Type :: SliceRefU8 ( _ ) ) if !indirect_return => {
434
+ Some ( Type :: SliceRefU8 ( ty ) ) if !indirect_return && ty . mutability . is_none ( ) => {
434
435
out. builtin . rust_slice_repr = true ;
435
436
write ! ( out, "::rust::impl<::rust::Slice<uint8_t>>::repr(" )
436
437
}
438
+ Some ( Type :: SliceRefU8 ( _) ) if !indirect_return => {
439
+ out. builtin . rust_mut_slice_repr = true ;
440
+ write ! ( out, "::rust::impl<::rust::MutSlice<uint8_t>>::repr(" )
441
+ }
437
442
_ => { }
438
443
}
439
444
match & efn. receiver {
@@ -468,12 +473,19 @@ fn write_cxx_function_shim<'a>(out: &mut OutFile<'a>, efn: &'a ExternFn) {
468
473
out. builtin . unsafe_bitcopy = true ;
469
474
write_type ( out, & arg. ty ) ;
470
475
write ! ( out, "(::rust::unsafe_bitcopy, *{})" , arg. ident) ;
471
- } else if let Type :: SliceRefU8 ( _) = arg. ty {
472
- write ! (
473
- out,
474
- "::rust::Slice<uint8_t>(static_cast<const uint8_t *>({0}.ptr), {0}.len)" ,
475
- arg. ident,
476
- ) ;
476
+ } else if let Type :: SliceRefU8 ( ref ty) = arg. ty {
477
+ match ty. mutability {
478
+ None => write ! (
479
+ out,
480
+ "::rust::Slice<uint8_t>(static_cast<const uint8_t *>({0}.ptr), {0}.len)" ,
481
+ arg. ident,
482
+ ) ,
483
+ Some ( _) => write ! (
484
+ out,
485
+ "::rust::MutSlice<uint8_t>(static_cast<uint8_t *>({0}.ptr), {0}.len)" ,
486
+ arg. ident,
487
+ )
488
+ }
477
489
} else if out. types . needs_indirect_abi ( & arg. ty ) {
478
490
out. include . utility = true ;
479
491
write ! ( out, "::std::move(*{})" , arg. ident) ;
@@ -686,10 +698,14 @@ fn write_rust_function_shim_impl(
686
698
out. builtin . rust_str_new_unchecked = true ;
687
699
write ! ( out, "::rust::impl<::rust::Str>::new_unchecked(" ) ;
688
700
}
689
- Type :: SliceRefU8 ( _ ) => {
701
+ Type :: SliceRefU8 ( ty ) if ty . mutability . is_none ( ) => {
690
702
out. builtin . rust_slice_new = true ;
691
703
write ! ( out, "::rust::impl<::rust::Slice<uint8_t>>::slice(" ) ;
692
704
}
705
+ Type :: SliceRefU8 ( _) => {
706
+ out. builtin . rust_mut_slice_new = true ;
707
+ write ! ( out, "::rust::impl<::rust::MutSlice<uint8_t>>::slice(" ) ;
708
+ }
693
709
_ => { }
694
710
}
695
711
}
@@ -712,10 +728,14 @@ fn write_rust_function_shim_impl(
712
728
out. builtin . rust_str_repr = true ;
713
729
write ! ( out, "::rust::impl<::rust::Str>::repr(" ) ;
714
730
}
715
- Type :: SliceRefU8 ( _ ) => {
731
+ Type :: SliceRefU8 ( ty ) if ty . mutability . is_none ( ) => {
716
732
out. builtin . rust_slice_repr = true ;
717
733
write ! ( out, "::rust::impl<::rust::Slice<uint8_t>>::repr(" ) ;
718
734
}
735
+ Type :: SliceRefU8 ( _) => {
736
+ out. builtin . rust_mut_slice_repr = true ;
737
+ write ! ( out, "::rust::impl<::rust::MutSlice<uint8_t>>::repr(" ) ;
738
+ }
719
739
ty if out. types . needs_indirect_abi ( ty) => write ! ( out, "&" ) ,
720
740
_ => { }
721
741
}
@@ -884,9 +904,12 @@ fn write_type(out: &mut OutFile, ty: &Type) {
884
904
Type :: Str ( _) => {
885
905
write ! ( out, "::rust::Str" ) ;
886
906
}
887
- Type :: SliceRefU8 ( _ ) => {
907
+ Type :: SliceRefU8 ( ty ) if ty . mutability . is_none ( ) => {
888
908
write ! ( out, "::rust::Slice<uint8_t>" ) ;
889
909
}
910
+ Type :: SliceRefU8 ( _) => {
911
+ write ! ( out, "::rust::MutSlice<uint8_t>" ) ;
912
+ }
890
913
Type :: Fn ( f) => {
891
914
write ! ( out, "::rust::{}<" , if f. throws { "TryFn" } else { "Fn" } ) ;
892
915
match & f. ret {
0 commit comments