File tree Expand file tree Collapse file tree 2 files changed +42
-0
lines changed Expand file tree Collapse file tree 2 files changed +42
-0
lines changed Original file line number Diff line number Diff line change @@ -1047,6 +1047,33 @@ impl<T: TransparentPtrType> IntoGlibPtr<*mut <T as GlibPtrDefault>::GlibType> fo
1047
1047
}
1048
1048
}
1049
1049
1050
+ impl < T : TransparentPtrType > From < super :: Slice < T > > for PtrSlice < T > {
1051
+ fn from ( value : super :: Slice < T > ) -> Self {
1052
+ let len = value. len ( ) ;
1053
+ let capacity = value. capacity ( ) ;
1054
+ unsafe {
1055
+ let ptr = value. into_raw ( ) ;
1056
+ let mut s = PtrSlice :: < T > {
1057
+ ptr : ptr:: NonNull :: new_unchecked ( ptr) ,
1058
+ len,
1059
+ capacity,
1060
+ } ;
1061
+
1062
+ // Reserve space for the `NULL`-terminator if needed
1063
+ if len == capacity {
1064
+ s. reserve ( 0 ) ;
1065
+ }
1066
+
1067
+ ptr:: write (
1068
+ s. ptr . as_ptr ( ) . add ( s. len ( ) ) ,
1069
+ Ptr :: from ( ptr:: null_mut :: < <T as GlibPtrDefault >:: GlibType > ( ) ) ,
1070
+ ) ;
1071
+
1072
+ s
1073
+ }
1074
+ }
1075
+ }
1076
+
1050
1077
// rustdoc-stripper-ignore-next
1051
1078
/// A trait to accept both <code>&[T]</code> or <code>PtrSlice<T></code> as an argument.
1052
1079
pub trait IntoPtrSlice < T : TransparentPtrType > {
Original file line number Diff line number Diff line change @@ -876,6 +876,21 @@ impl<T: TransparentType + 'static> IntoGlibPtr<*mut T::GlibType> for Slice<T> {
876
876
}
877
877
}
878
878
879
+ impl < T : TransparentPtrType > From < super :: PtrSlice < T > > for Slice < T > {
880
+ fn from ( value : super :: PtrSlice < T > ) -> Self {
881
+ let len = value. len ( ) ;
882
+ let capacity = value. capacity ( ) ;
883
+ unsafe {
884
+ let ptr = value. into_raw ( ) ;
885
+ Slice :: < T > {
886
+ ptr : ptr:: NonNull :: new_unchecked ( ptr) ,
887
+ len,
888
+ capacity,
889
+ }
890
+ }
891
+ }
892
+ }
893
+
879
894
#[ cfg( test) ]
880
895
mod test {
881
896
use super :: * ;
You can’t perform that action at this time.
0 commit comments