소스 검색

rust: Fix manual_slice_size_calculation lint.

See: https://rust-lang.github.io/rust-clippy/master/index.html#/manual_slice_size_calculation
Bruce Mitchener 1 년 전
부모
커밋
66739fd642
1개의 변경된 파일1개의 추가작업 그리고 1개의 파일을 삭제
  1. 1 1
      bindgen/gen_rust.py

+ 1 - 1
bindgen/gen_rust.py

@@ -766,7 +766,7 @@ def gen_helpers(inp):
     if inp['prefix'] in ['sg_', 'sdtx_', 'sshape_', 'sapp_']:
     if inp['prefix'] in ['sg_', 'sdtx_', 'sshape_', 'sapp_']:
         l("/// Helper function to cast a rust slice into a sokol Range")
         l("/// Helper function to cast a rust slice into a sokol Range")
         l(f"pub fn slice_as_range<T>(data: &[T]) -> {range_struct_name} {{")
         l(f"pub fn slice_as_range<T>(data: &[T]) -> {range_struct_name} {{")
-        l(f"    {range_struct_name} {{ size: data.len() * std::mem::size_of::<T>(), ptr: data.as_ptr() as *const _ }}")
+        l(f"    {range_struct_name} {{ size: std::mem::size_of_val(data), ptr: data.as_ptr() as *const _ }}")
         l("}")
         l("}")
         l("/// Helper function to cast a rust reference into a sokol Range")
         l("/// Helper function to cast a rust reference into a sokol Range")
         l(f"pub fn value_as_range<T>(value: &T) -> {range_struct_name} {{")
         l(f"pub fn value_as_range<T>(value: &T) -> {range_struct_name} {{")