pub fn encode_codewords(
        ver: Version,
        ecl: QrCodeEcc,
        datacodewords: &[u8],
        mut msk: Option<Mask>,
    ) -> Self {
        // Initialize fields
        let size = usize::from(ver.value()) * 4 + 17;
        let mut result = Self {
            version: ver,
            size: size as i32,
            mask: Mask::new(0), // Dummy value
            errorcorrectionlevel: ecl,
            modules: vec![false; size * size], // Initially all light
            isfunction: vec![false; size * size],
        };

        // Compute ECC, draw modules
        result.draw_function_patterns();
        let allcodewords: Vec<u8> = result.add_ecc_and_interleave(datacodewords);
        result.draw_codewords(&allcodewords);

        // Do masking
        if msk.is_none() {
            // Automatically choose best mask
            let mut minpenalty = std::i32::MAX;
            for i in 0u8..8 {
                let i = Mask::new(i);
                result.apply_mask(i);
                result.draw_format_bits(i);
                let penalty: i32 = result.get_penalty_score();
                if penalty < minpenalty {
                    msk = Some(i);
                    minpenalty = penalty;
                }
                result.apply_mask(i); // Undoes the mask due to XOR
            }
        }
        let msk: Mask = msk.unwrap();
        result.mask = msk;
        result.apply_mask(msk); // Apply the final choice of mask
        result.draw_format_bits(msk); // Overwrite old format bits

        result.isfunction.clear();
        result.isfunction.shrink_to_fit();
        result
    }
/// Creates a new QR Code with the given version number,
/// error correction level, data codeword bytes, and mask number.
///
/// This is a low-level API that most users should not use directly.
/// A mid-level API is the `encode_segments()` function.
Creates a new QR Code with the given version number,
error correction level, data codeword bytes, and mask number.

This is a low-level API that most users should not use directly.
A mid-level API is the `encode_segments()` function.
Creates a new QR Code with the given version number error correction level data codeword bytes and mask number . This is a low - level API that most users should not use directly . A mid - level API is the ` encode_segments () ` function .
pub fn encode_codewords(
        ver: Version,
        ecl: QrCodeEcc,
        datacodewords: &[u8],
        mut msk: Option<Mask>,
    ) -> Self {
        // Initialize fields
        let size = usize::from(ver.value()) * 4 + 17;
        let mut result = Self {
            version: ver,
            size: size as i32,
            mask: Mask::new(0), // Dummy value
            errorcorrectionlevel: ecl,
            modules: vec![false; size * size], // Initially all light
            isfunction: vec![false; size * size],
        };
        // Compute ECC, draw modules
        result.draw_function_patterns();
        let allcodewords: Vec<u8> = result.add_ecc_and_interleave(datacodewords);
        result.draw_codewords(&allcodewords);
        // Do masking
        if msk.is_none() {
            // Automatically choose best mask
            let mut minpenalty = std::i32::MAX;
            for i in 0u8..8 {
                let i = Mask::new(i);
                result.apply_mask(i);
                result.draw_format_bits(i);
                let penalty: i32 = result.get_penalty_score();
                if penalty < minpenalty {
                    msk = Some(i);
                    minpenalty = penalty;
                }
                result.apply_mask(i); // Undoes the mask due to XOR
            }
        }
        let msk: Mask = msk.unwrap();
        result.mask = msk;
        result.apply_mask(msk); // Apply the final choice of mask
        result.draw_format_bits(msk); // Overwrite old format bits
        result.isfunction.clear();
        result.isfunction.shrink_to_fit();
        result
    }
pub fn encode_codewords ( ver : Version , ecl : QrCodeEcc , datacodewords : & [ u8 ] , mut msk : Option < Mask > , ) -> Self { // Initialize fields let size = usize :: from ( ver . value ( ) ) * 4 + 17 ; let mut result = Self { version : ver , size : size as i32 , mask : Mask :: new ( 0 ) , // Dummy value errorcorrectionlevel : ecl , modules : vec ! [ false size size ] , // Initially all light isfunction : vec ! [ false size size ] , } ; // Compute ECC, draw modules result . draw_function_patterns ( ) ; let allcodewords : Vec < u8 > = result . add_ecc_and_interleave ( datacodewords ) ; result . draw_codewords ( & allcodewords ) ; // Do masking if msk . is_none ( ) { // Automatically choose best mask let mut minpenalty = std :: i32 :: MAX ; for i in 0u8 .. 8 { let i = Mask :: new ( i ) ; result . apply_mask ( i ) ; result . draw_format_bits ( i ) ; let penalty : i32 = result . get_penalty_score ( ) ; if penalty < minpenalty { msk = Some ( i ) ; minpenalty = penalty ; } result . apply_mask ( i ) ; // Undoes the mask due to XOR } } let msk : Mask = msk . unwrap ( ) ; result . mask = msk ; result . apply_mask ( msk ) ; // Apply the final choice of mask result . draw_format_bits ( msk ) ; // Overwrite old format bits result . isfunction . clear ( ) ; result . isfunction . shrink_to_fit ( ) ; result }
Creates a new QR Code with the given version number,
error correction level, data codeword bytes, and mask number.
Creates a new QR Code with the given version number error correction level data codeword bytes and mask number .
ver
Version
ecl
QrCodeEcc
datacodewords
&[u8]
msk
Option<Mask>