Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename AssociatedArraySize => AssocArraySize #40

Merged
merged 1 commit into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ use typenum::{Diff, Sum};
use zeroize::{Zeroize, ZeroizeOnDrop};

/// Type alias for [`Array`] which is const generic around a size `N`, ala `[T; N]`.
pub type ArrayN<T, const N: usize> = Array<T, <[T; N] as AssociatedArraySize>::Size>;
pub type ArrayN<T, const N: usize> = Array<T, <[T; N] as AssocArraySize>::Size>;

/// [`Array`] is a newtype for an inner `[T; N]` array where `N` is determined by a generic
/// [`ArraySize`] parameter, which is a marker trait for a numeric value determined by ZSTs that
Expand All @@ -134,25 +134,25 @@ pub type ArrayN<T, const N: usize> = Array<T, <[T; N] as AssociatedArraySize>::S
/// The [`AsRef`] trait can be used to convert from `&Array<T, U>` to `&[T; N]` and vice versa:
///
/// ```
/// use hybrid_array::{Array, ArraySize, AssociatedArraySize, ArrayN, consts::U3};
/// use hybrid_array::{Array, ArraySize, AssocArraySize, ArrayN, consts::U3};
///
/// pub fn get_third_item_hybrid_array<T, U: ArraySize>(arr_ref: &Array<T, U>) -> &T {
/// &arr_ref[2]
/// }
///
/// pub fn get_third_item_const_generic<T, const N: usize>(arr_ref: &[T; N]) -> &T
/// where
/// [T; N]: AssociatedArraySize + AsRef<ArrayN<T, N>>
/// [T; N]: AssocArraySize + AsRef<ArrayN<T, N>>
/// {
/// get_third_item_hybrid_array(arr_ref.as_ref())
/// }
///
/// assert_eq!(get_third_item_const_generic(&[1u8, 2, 3, 4]), &3);
/// ```
///
/// Note that the [`AssociatedArraySize`] trait can be used to determine the appropriate
/// Note that the [`AssocArraySize`] trait can be used to determine the appropriate
/// [`Array`] size for a given `[T; N]`, and the [`ArrayN`] trait (which internally uses
/// [`AssociatedArraySize`]) can be used to determine the specific [`Array`] type for a given
/// [`AssocArraySize`]) can be used to determine the specific [`Array`] type for a given
/// const generic size.
#[repr(transparent)]
pub struct Array<T, U: ArraySize>(pub U::ArrayType<T>);
Expand Down
4 changes: 2 additions & 2 deletions src/sizes.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Macros for defining various array sizes, and their associated invocations.

use super::{ArraySize, AssociatedArraySize};
use super::{ArraySize, AssocArraySize};

macro_rules! impl_array_size {
($($len:expr => $ty:ident),+) => {
Expand All @@ -9,7 +9,7 @@ macro_rules! impl_array_size {
type ArrayType<T> = [T; $len];
}

impl<T> AssociatedArraySize for [T; $len] {
impl<T> AssocArraySize for [T; $len] {
type Size = typenum::$ty;
}
)+
Expand Down
6 changes: 3 additions & 3 deletions src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub unsafe trait ArraySize: Unsigned {
///
/// This is always defined to be `[T; N]` where `N` is the same as
/// [`ArraySize::USIZE`][`typenum::Unsigned::USIZE`].
type ArrayType<T>: AssociatedArraySize<Size = Self>
type ArrayType<T>: AssocArraySize<Size = Self>
+ AsRef<[T]>
+ AsMut<[T]>
+ Borrow<[T]>
Expand All @@ -37,12 +37,12 @@ pub unsafe trait ArraySize: Unsigned {
}

/// Associates an [`ArraySize`] with a given type.
pub trait AssociatedArraySize: Sized {
pub trait AssocArraySize: Sized {
/// Size of an array type, expressed as a [`typenum`]-based [`ArraySize`].
type Size: ArraySize;
}

impl<T, U> AssociatedArraySize for Array<T, U>
impl<T, U> AssocArraySize for Array<T, U>
where
U: ArraySize,
{
Expand Down
Loading