/// Writes the vtable length (in bytes) into the vtable. /// /// Note that callers already need to have computed this to initialize /// a VTableWriter. /// /// In debug mode, asserts that the length of the underlying data is equal /// to the provided value. #[inline(always)] pubfn write_vtable_byte_length(&mutself, n: VOffsetT) { let buf = &mutself.buf[..SIZE_VOFFSET]; // Safety: // Validated range above unsafe {
emplace_scalar::<VOffsetT>(buf, n);
}
debug_assert_eq!(n as usize, self.buf.len());
}
/// Writes an object length (in bytes) into the vtable. #[inline(always)] pubfn write_object_inline_size(&mutself, n: VOffsetT) { let buf = &mutself.buf[SIZE_VOFFSET..2 * SIZE_VOFFSET]; // Safety: // Validated range above unsafe {
emplace_scalar::<VOffsetT>(buf, n);
}
}
/// Writes an object field offset into the vtable. /// /// Note that this expects field offsets (which are like pointers), not /// field ids (which are like array indices). #[inline(always)] pubfn write_field_offset(&mutself, vtable_offset: VOffsetT, object_data_offset: VOffsetT) { let idx = vtable_offset as usize; let buf = &mutself.buf[idx..idx + SIZE_VOFFSET]; // Safety: // Validated range above unsafe {
emplace_scalar::<VOffsetT>(buf, object_data_offset);
}
}
/// Clears all data in this VTableWriter. Used to cleanly undo a /// vtable write. #[inline(always)] pubfn clear(&mutself) { // This is the closest thing to memset in Rust right now. let len = self.buf.len(); let p = self.buf.as_mut_ptr() as *mut u8;
// Safety: // p is byte aligned and of length `len` unsafe {
write_bytes(p, 0, len);
}
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.