I am writing a Rust wrapper around a C library. The C library provides the following function:

```c
void lib_foo(const unsigned char *buf, uint32_t buf_len);

```

I have created the following `extern` wrapper:

```rust
fn lib_foo(buf: *const u8, buf_len: u32);

```

and the following high-level wrapper:

```rust
pub fn foo(buf: &[u8]) {
    unsafe { lib_foo(buf.as_ptr(), buf.len() as u32) }
}

```

However, the cast from `usize` (the type of `buf.len()`) to `u32` may cause the size to be truncated. What is the best way of dealing with this?