pub fn as_mut_ptr(&mut self) -> *mut T {
        // We shadow the slice method of the same name to avoid going through
        // `deref_mut`, which creates an intermediate reference.
        let ptr = self.buf.ptr();
        unsafe {
            assume(!ptr.is_null());
        }
        ptr
    }
Forces the length of the vector to `new_len`.

This is a low-level operation that maintains none of the normal
invariants of the type. Normally changing the length of a vector
is done using one of the safe operations instead, such as
[`truncate`], [`resize`], [`extend`], or [`clear`].

[`truncate`]: Vec::truncate
[`resize`]: Vec::resize
[`extend`]: Extend::extend
[`clear`]: Vec::clear

# Safety

- `new_len` must be less than or equal to [`capacity()`].
- The elements at `old_len..new_len` must be initialized.

[`capacity()`]: Vec::capacity

# Examples

This method can be useful for situations in which the vector
is serving as a buffer for other code, particularly over FFI:

```no_run
# #![allow(dead_code)]
# // This is just a minimal skeleton for the doc example;
# // don't use this as a starting point for a real library.
# pub struct StreamWrapper { strm: *mut std::ffi::c_void }
# const Z_OK: i32 = 0;
# extern "C" {
#     fn deflateGetDictionary(
#         strm: *mut std::ffi::c_void,
#         dictionary: *mut u8,
#         dictLength: *mut usize,
#     ) -> i32;
# }
# impl StreamWrapper {
pub fn get_dictionary(&self) -> Option<Vec<u8>> {
// Per the FFI method's docs, "32768 bytes is always enough".
let mut dict = Vec::with_capacity(32_768);
let mut dict_length = 0;
// SAFETY: When `deflateGetDictionary` returns `Z_OK`, it holds that:
// 1. `dict_length` elements were initialized.
// 2. `dict_length` <= the capacity (32_768)
// which makes `set_len` safe to call.
unsafe {
// Make the FFI call...
let r = deflateGetDictionary(self.strm, dict.as_mut_ptr(), &mut dict_length);
if r == Z_OK {
// ...and update the length to what was initialized.
dict.set_len(dict_length);
Some(dict)
} else {
None
}
}
}
benchmarks/haystacks/code/rust-library.rs