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

Add support for generic-array crate #204

Merged
merged 1 commit into from
Jan 29, 2025

Conversation

Lohann
Copy link
Contributor

@Lohann Lohann commented Jan 29, 2025

In working in a no_std library and to create an ArrayVec where the length is provided by ArrayLength trait, and realized this was not possible. once is not possible to implement the trait Array for third-party crates, the only options are either generic-array add tinyvec as optional dependency and implement the needed trait, or vice-versa.

So this PR implements the trait Array for GenericArray. Combining both I can have trait defined length and the resizable array.

This adds support for generic trait-defined types and length, example:

use generic_array::{ArrayLength, GenericArray};
use tinyvec::{TinyVec, ArrayVec, Array};

pub type GenericArrayVec<T, N> = ArrayVec<GenericArray<T, N>>;
pub type GenericTinyVec<T, N> = TinyVec<GenericArray<T, N>>;

pub trait Config {
    type MaxSize: ArrayLength;
    type Value: Sized + Send + 'static;
}

pub struct Foo<T: Config> {
    pub values: GenericArrayVec<T::Value, T::MaxSize>;
}

@Lokathor Lokathor merged commit 9726c64 into Lokathor:main Jan 29, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants