Skip to content

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

@Andrepuel

Description

@Andrepuel

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 }
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions