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

Suggestion: const fn to create an ArrayVec with the len, capping if it exceeds the maximum #181

Open
Andrepuel opened this issue May 11, 2023 · 0 comments

Comments

@Andrepuel
Copy link

I think it is easier to explain using code:

impl<A: Array> ArrayVec<A> {
  #[inline]
  #[must_use]
  pub const fn from_array_len_capped(data: A, len: u16) -> Self{
    let len = if len as usize <= A::CAPACITY {
      len
    } else {
      A::CAPACITY as u16
    };
    Self { data, len: len as u16 }
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant