Skip to content

Commit 73b8257

Browse files
committed
Add PackedSeqVecBase::from_raw_parts
1 parent b24f0d4 commit 73b8257

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

src/packed_seq.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1371,6 +1371,21 @@ where
13711371
}
13721372
}
13731373

1374+
impl<const B: usize> PackedSeqVecBase<B>
1375+
where
1376+
Bits<B>: SupportedBits,
1377+
{
1378+
/// Creates a `SeqVec` from a vector of packed bytes and a length in bp.
1379+
///
1380+
/// The vector should have at least 16 bytes of padding after `len`.
1381+
/// Otherwise, the vector will be resized to be padded with zeros.
1382+
pub fn from_raw_parts(mut seq: Vec<u8>, len: usize) -> Self {
1383+
assert!(len <= seq.len() * Self::C8);
1384+
seq.resize(len.div_ceil(Self::C8) + PADDING, 0);
1385+
Self { seq, len }
1386+
}
1387+
}
1388+
13741389
impl PackedSeqVecBase<1> {
13751390
pub fn with_len(n: usize) -> Self {
13761391
Self {

0 commit comments

Comments
 (0)