Skip to content

Commit c4eff01

Browse files
authored
Add basic AssocArraySize docs (#96)
Show how the trait can be used to accept const generic core arrays as parameters and convert to `Array`/`ArrayN`.
1 parent 91d28d5 commit c4eff01

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/traits.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,22 @@ pub unsafe trait ArraySize: Unsigned {
3636
+ IntoIterator<Item = T>;
3737
}
3838

39-
/// Associates an [`ArraySize`] with a given type.
39+
/// Associates an [`ArraySize`] with a given type. Can be used to write APIs which use `[T; N]`
40+
/// and convert to [`Array`] internally.
41+
///
42+
/// # Example
43+
///
44+
/// ```
45+
/// use hybrid_array::{ArrayN, AssocArraySize};
46+
///
47+
/// pub fn example<const N: usize>(bytes: &[u8; N])
48+
/// where
49+
/// [u8; N]: AssocArraySize + AsRef<ArrayN<u8, N>>
50+
/// {
51+
/// // _arrayn is ArrayN<u8, N>
52+
/// let _arrayn = bytes.as_ref();
53+
/// }
54+
/// ```
4055
pub trait AssocArraySize: Sized {
4156
/// Size of an array type, expressed as a [`typenum`]-based [`ArraySize`].
4257
type Size: ArraySize;

0 commit comments

Comments
 (0)