Skip to content

Commit b30d896

Browse files
committed
Explain in comment why FixedSizeArray is unsafe
1 parent 85f48d3 commit b30d896

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/libcore/array.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,15 @@ use slice::{Iter, IterMut, SliceExt};
3535
///
3636
/// This trait can be used to implement other traits on fixed-size arrays
3737
/// without causing much metadata bloat.
38+
///
39+
/// The trait is marked unsafe in order to restrict implementors to fixed-size
40+
/// arrays. User of this trait can assume that implementors have the exact
41+
/// layout in memory of a fixed size array (for example, for unsafe
42+
/// initialization).
43+
///
44+
/// Note that the traits AsRef and AsMut provide similar methods for types that
45+
/// may not be fixed-size arrays. Implementors should prefer those traits
46+
/// instead.
3847
pub unsafe trait FixedSizeArray<T> {
3948
/// Converts the array to immutable slice
4049
fn as_slice(&self) -> &[T];

0 commit comments

Comments
 (0)