fn write_bits(out: &mut [u8], pos: &BitWindow, value: u8) {
    debug_assert!(pos.bit < 8);
    debug_assert!(pos.count <= 8);
    debug_assert!(pos.count > 0);

    if (pos.bit + pos.count) <= 8 {
        // Bits to be written to fit in a single byte
        debug_assert_eq!(out[pos.byte as usize] | PAD_LEFT[pos.bit as usize], 255);
        let pad_left = out[pos.byte as usize] | PAD_RIGHT[(8 - pos.bit) as usize];
        let shifted = value << (8 - pos.bit - pos.count) | PAD_LEFT[pos.bit as usize];
        let pad_right = PAD_RIGHT[(8 - pos.count - pos.bit) as usize];
        out[pos.byte as usize] = (pad_left & shifted) | pad_right;
    } else {
        // Bits to be written to span two bytes
        debug_assert_eq!(out[pos.byte as usize] | PAD_LEFT[pos.bit as usize], 255);
        let split = 8 - pos.bit;
        let pad_left = out[pos.byte as usize] | PAD_RIGHT[split as usize];
        let shifted = (value >> (pos.count - split)) | PAD_LEFT[pos.bit as usize];
        out[pos.byte as usize] = pad_left & shifted;

        let rem = 8 - (pos.count - split);
        out[(pos.byte + 1) as usize] = (value << rem) | PAD_RIGHT[rem as usize];
    }
}
/// Write bits from `value` to the `out` slice
///
/// Write the least significant `pos.count` bits from `value` to the position specified by
/// `(pos.byte, pos.bit)`. Writes may span multiple bytes. `out` is expected to be long enough
/// to write these bits; this is ensured by `HuffmanEncoder::ensure_free_space()`, which is
/// always called prior to calling this function.
///
/// The bits to be written to are expected to be set to 1 when calling this function. Similarly,
/// this function maintains the invariant that unused bits in the output bytes are set to 1.


The bits to be written to are expected to be set to 1 when calling this function. Similarly,
this function maintains the invariant that unused bits in the output bytes are set to 1.
The bits to be written to are expected to be set to 1 when calling this function . Similarly this function maintains the invariant that unused bits in the output bytes are set to 1 .
fn write_bits(out: &mut [u8], pos: &BitWindow, value: u8) {
    debug_assert!(pos.bit < 8);
    debug_assert!(pos.count <= 8);
    debug_assert!(pos.count > 0);
    if (pos.bit + pos.count) <= 8 {
        // Bits to be written to fit in a single byte
        debug_assert_eq!(out[pos.byte as usize] | PAD_LEFT[pos.bit as usize], 255);
        let pad_left = out[pos.byte as usize] | PAD_RIGHT[(8 - pos.bit) as usize];
        let shifted = value << (8 - pos.bit - pos.count) | PAD_LEFT[pos.bit as usize];
        let pad_right = PAD_RIGHT[(8 - pos.count - pos.bit) as usize];
        out[pos.byte as usize] = (pad_left & shifted) | pad_right;
    } else {
        // Bits to be written to span two bytes
        debug_assert_eq!(out[pos.byte as usize] | PAD_LEFT[pos.bit as usize], 255);
        let split = 8 - pos.bit;
        let pad_left = out[pos.byte as usize] | PAD_RIGHT[split as usize];
        let shifted = (value >> (pos.count - split)) | PAD_LEFT[pos.bit as usize];
        out[pos.byte as usize] = pad_left & shifted;
        let rem = 8 - (pos.count - split);
        out[(pos.byte + 1) as usize] = (value << rem) | PAD_RIGHT[rem as usize];
    }
}
fn write_bits ( out : & mut [ u8 ] , pos : & BitWindow , value : u8 ) { debug_assert ! ( pos bit 8 ) ; debug_assert ! ( pos count 8 ) ; debug_assert ! ( pos count 0 ) ; if ( pos . bit + pos . count ) <= 8 { // Bits to be written to fit in a single byte debug_assert_eq ! ( out [ pos byte as usize ] PAD_LEFT [ pos bit as usize ] 255 ) ; let pad_left = out [ pos . byte as usize ] | PAD_RIGHT [ ( 8 - pos . bit ) as usize ] ; let shifted = value << ( 8 - pos . bit - pos . count ) | PAD_LEFT [ pos . bit as usize ] ; let pad_right = PAD_RIGHT [ ( 8 - pos . count - pos . bit ) as usize ] ; out [ pos . byte as usize ] = ( pad_left & shifted ) | pad_right ; } else { // Bits to be written to span two bytes debug_assert_eq ! ( out [ pos byte as usize ] PAD_LEFT [ pos bit as usize ] 255 ) ; let split = 8 - pos . bit ; let pad_left = out [ pos . byte as usize ] | PAD_RIGHT [ split as usize ] ; let shifted = ( value >> ( pos . count - split ) ) | PAD_LEFT [ pos . bit as usize ] ; out [ pos . byte as usize ] = pad_left & shifted ; let rem = 8 - ( pos . count - split ) ; out [ ( pos . byte + 1 ) as usize ] = ( value << rem ) | PAD_RIGHT [ rem as usize ] ; } }
Write bits from `value` to the `out` slice
Write the least significant `pos.count` bits from `value` to the position specified by
`(pos.byte, pos.bit)`.
Write bits from ` value ` to the ` out ` slice Write the least significant ` pos . count ` bits from ` value ` to the position specified by ` ( pos . byte pos . bit ) ` .
out
&mut [u8]
pos
&BitWindow
value
u8