Skip to content

Commit

Permalink
Add "safety" comment
Browse files Browse the repository at this point in the history
  • Loading branch information
mgeier committed Apr 26, 2024
1 parent 08f761f commit 678e5a0
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions core/src/slice/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,16 @@ use crate::ub_checks;
/// ```
/// use std::slice;
///
/// /// # Safety
/// ///
/// /// If ptr is not NULL, it must be correctly aligned and
/// /// point to `len` initialized items of type `f32`.
/// unsafe extern "C" fn handle_slice(ptr: *const f32, len: usize) {
/// let data = if ptr.is_null() {
/// // `len` is assumed to be 0.
/// &[]
/// } else {
/// // SAFETY: see function docstring.
/// unsafe { slice::from_raw_parts(ptr, len) }
/// };
/// dbg!(data);
Expand Down

0 comments on commit 678e5a0

Please sign in to comment.