pub fn to_vec(self) -> Vec<u8> {
        let mut r = vec![];
        let mut stri = vec![];
        let mut strs = vec![];

        let mut i = 0;
        for (k, v) in self.strs.iter() {
            while i < *k as usize {
                write_str(&mut stri, &mut strs, None);
                i += 1;
            }
            write_str(&mut stri, &mut strs, v.as_str());
            i += 1;
        }

        // Magic number
        r.push(0x1e);
        r.push(0x2);
        write_short(
            &mut r,
            Some(self.names.iter().fold(0, |s, n| s + n.len() + 1) as i16),
        );
        write_short(
            &mut r,
            Some(self.bools.last().map(|(k, _)| *k as usize + 1).unwrap_or(0) as i16),
        );
        write_short(
            &mut r,
            Some(self.ints.last().map(|(k, _)| *k as usize + 1).unwrap_or(0) as i16),
        );
        write_short(&mut r, Some((stri.len() / 2) as i16));
        write_short(&mut r, Some(strs.len() as i16));

        let mut first = true;
        for name in self.names {
            if first {
                first = false
            } else {
                r.push(b'|')
            }
            r.extend(name.as_bytes());
        }
        r.push(0);

        i = 0;
        for (k, v) in self.bools {
            while i < k as usize {
                r.push(0xFF);
                i += 1;
            }
            r.push(v.as_bool().map(|v| *v as u8).unwrap_or(0xFF));
            i += 1;
        }

        if r.len() % 2 == 1 {
            r.push(0)
        }

        i = 0;
        for (k, v) in self.ints {
            while i < k as usize {
                write_int(&mut r, None);
                i += 1;
            }
            write_int(&mut r, v.as_int().copied());
            i += 1;
        }

        r.append(&mut stri);
        r.append(&mut strs);

        let mut ex_bools = vec![];
        let mut ex_nums = vec![];
        let mut ex_stri = vec![];
        let mut ex_strs = vec![];
        let mut ex_keyi = vec![];
        let mut ex_keys = vec![];
        for k in self.ex_bools {
            if let Some(v) = self.ex.get(&k) {
                if let Some(&v) = v.as_bool() {
                    ex_bools.push(v as u8);
                    write_str(&mut ex_keyi, &mut ex_keys, Some(&k))
                }
            }
        }
        for k in self.ex_nums {
            if let Some(v) = self.ex.get(&k) {
                if let Some(&v) = v.as_int() {
                    write_int(&mut ex_nums, Some(v));
                    write_str(&mut ex_keyi, &mut ex_keys, Some(&k))
                }
            }
        }
        for k in self.ex_strs {
            if let Some(v) = self.ex.get(&k) {
                if let Some(v) = v.as_str() {
                    write_str(&mut ex_stri, &mut ex_strs, Some(v));
                    write_str(&mut ex_keyi, &mut ex_keys, Some(&k))
                }
            }
        }
        if ex_keyi.len() > 0 {
            if r.len() % 2 == 1 {
                r.push(0)
            }

            write_short(&mut r, Some(ex_bools.len() as i16));
            write_short(&mut r, Some((ex_nums.len() / 4) as i16));
            write_short(&mut r, Some((ex_stri.len() / 2) as i16));
            write_short(&mut r, Some(((ex_stri.len() + ex_keyi.len()) / 2) as i16));
            write_short(&mut r, Some((ex_strs.len() + ex_keys.len()) as i16));

            r.extend(ex_bools);
            if r.len() % 2 == 1 {
                r.push(0)
            }
            r.extend(ex_nums);
            r.extend(ex_stri);
            r.extend(ex_keyi);
            r.extend(ex_strs);
            r.extend(ex_keys);
        }

        r
    }
/// Convert the terminfo struct back to the binary format of an
/// ncurses-compatible terminfo file.
///
/// This can be used to write a terminfo file as in the example [`above`](#).
Convert the terminfo struct back to the binary format of an
ncurses-compatible terminfo file.

This can be used to write a terminfo file as in the example [`above`](#).
Convert the terminfo struct back to the binary format of an ncurses - compatible terminfo file . This can be used to write a terminfo file as in the example [ ` above ` ] ( # ) .
pub fn to_vec(self) -> Vec<u8> {
        let mut r = vec![];
        let mut stri = vec![];
        let mut strs = vec![];
        let mut i = 0;
        for (k, v) in self.strs.iter() {
            while i < *k as usize {
                write_str(&mut stri, &mut strs, None);
                i += 1;
            }
            write_str(&mut stri, &mut strs, v.as_str());
            i += 1;
        }
        // Magic number
        r.push(0x1e);
        r.push(0x2);
        write_short(
            &mut r,
            Some(self.names.iter().fold(0, |s, n| s + n.len() + 1) as i16),
        );
        write_short(
            &mut r,
            Some(self.bools.last().map(|(k, _)| *k as usize + 1).unwrap_or(0) as i16),
        );
        write_short(
            &mut r,
            Some(self.ints.last().map(|(k, _)| *k as usize + 1).unwrap_or(0) as i16),
        );
        write_short(&mut r, Some((stri.len() / 2) as i16));
        write_short(&mut r, Some(strs.len() as i16));
        let mut first = true;
        for name in self.names {
            if first {
                first = false
            } else {
                r.push(b'|')
            }
            r.extend(name.as_bytes());
        }
        r.push(0);
        i = 0;
        for (k, v) in self.bools {
            while i < k as usize {
                r.push(0xFF);
                i += 1;
            }
            r.push(v.as_bool().map(|v| *v as u8).unwrap_or(0xFF));
            i += 1;
        }
        if r.len() % 2 == 1 {
            r.push(0)
        }
        i = 0;
        for (k, v) in self.ints {
            while i < k as usize {
                write_int(&mut r, None);
                i += 1;
            }
            write_int(&mut r, v.as_int().copied());
            i += 1;
        }
        r.append(&mut stri);
        r.append(&mut strs);
        let mut ex_bools = vec![];
        let mut ex_nums = vec![];
        let mut ex_stri = vec![];
        let mut ex_strs = vec![];
        let mut ex_keyi = vec![];
        let mut ex_keys = vec![];
        for k in self.ex_bools {
            if let Some(v) = self.ex.get(&k) {
                if let Some(&v) = v.as_bool() {
                    ex_bools.push(v as u8);
                    write_str(&mut ex_keyi, &mut ex_keys, Some(&k))
                }
            }
        }
        for k in self.ex_nums {
            if let Some(v) = self.ex.get(&k) {
                if let Some(&v) = v.as_int() {
                    write_int(&mut ex_nums, Some(v));
                    write_str(&mut ex_keyi, &mut ex_keys, Some(&k))
                }
            }
        }
        for k in self.ex_strs {
            if let Some(v) = self.ex.get(&k) {
                if let Some(v) = v.as_str() {
                    write_str(&mut ex_stri, &mut ex_strs, Some(v));
                    write_str(&mut ex_keyi, &mut ex_keys, Some(&k))
                }
            }
        }
        if ex_keyi.len() > 0 {
            if r.len() % 2 == 1 {
                r.push(0)
            }
            write_short(&mut r, Some(ex_bools.len() as i16));
            write_short(&mut r, Some((ex_nums.len() / 4) as i16));
            write_short(&mut r, Some((ex_stri.len() / 2) as i16));
            write_short(&mut r, Some(((ex_stri.len() + ex_keyi.len()) / 2) as i16));
            write_short(&mut r, Some((ex_strs.len() + ex_keys.len()) as i16));
            r.extend(ex_bools);
            if r.len() % 2 == 1 {
                r.push(0)
            }
            r.extend(ex_nums);
            r.extend(ex_stri);
            r.extend(ex_keyi);
            r.extend(ex_strs);
            r.extend(ex_keys);
        }
        r
    }
pub fn to_vec ( self ) -> Vec < u8 > { let mut r = vec ! [ ] ; let mut stri = vec ! [ ] ; let mut strs = vec ! [ ] ; let mut i = 0 ; for ( k , v ) in self . strs . iter ( ) { while i < * k as usize { write_str ( & mut stri , & mut strs , None ) ; i += 1 ; } write_str ( & mut stri , & mut strs , v . as_str ( ) ) ; i += 1 ; } // Magic number r . push ( 0x1e ) ; r . push ( 0x2 ) ; write_short ( & mut r , Some ( self . names . iter ( ) . fold ( 0 , | s , n | s + n . len ( ) + 1 ) as i16 ) , ) ; write_short ( & mut r , Some ( self . bools . last ( ) . map ( | ( k , _ ) | * k as usize + 1 ) . unwrap_or ( 0 ) as i16 ) , ) ; write_short ( & mut r , Some ( self . ints . last ( ) . map ( | ( k , _ ) | * k as usize + 1 ) . unwrap_or ( 0 ) as i16 ) , ) ; write_short ( & mut r , Some ( ( stri . len ( ) / 2 ) as i16 ) ) ; write_short ( & mut r , Some ( strs . len ( ) as i16 ) ) ; let mut first = true ; for name in self . names { if first { first = false } else { r . push ( b'|' ) } r . extend ( name . as_bytes ( ) ) ; } r . push ( 0 ) ; i = 0 ; for ( k , v ) in self . bools { while i < k as usize { r . push ( 0xFF ) ; i += 1 ; } r . push ( v . as_bool ( ) . map ( | v | * v as u8 ) . unwrap_or ( 0xFF ) ) ; i += 1 ; } if r . len ( ) % 2 == 1 { r . push ( 0 ) } i = 0 ; for ( k , v ) in self . ints { while i < k as usize { write_int ( & mut r , None ) ; i += 1 ; } write_int ( & mut r , v . as_int ( ) . copied ( ) ) ; i += 1 ; } r . append ( & mut stri ) ; r . append ( & mut strs ) ; let mut ex_bools = vec ! [ ] ; let mut ex_nums = vec ! [ ] ; let mut ex_stri = vec ! [ ] ; let mut ex_strs = vec ! [ ] ; let mut ex_keyi = vec ! [ ] ; let mut ex_keys = vec ! [ ] ; for k in self . ex_bools { if let Some ( v ) = self . ex . get ( & k ) { if let Some ( & v ) = v . as_bool ( ) { ex_bools . push ( v as u8 ) ; write_str ( & mut ex_keyi , & mut ex_keys , Some ( & k ) ) } } } for k in self . ex_nums { if let Some ( v ) = self . ex . get ( & k ) { if let Some ( & v ) = v . as_int ( ) { write_int ( & mut ex_nums , Some ( v ) ) ; write_str ( & mut ex_keyi , & mut ex_keys , Some ( & k ) ) } } } for k in self . ex_strs { if let Some ( v ) = self . ex . get ( & k ) { if let Some ( v ) = v . as_str ( ) { write_str ( & mut ex_stri , & mut ex_strs , Some ( v ) ) ; write_str ( & mut ex_keyi , & mut ex_keys , Some ( & k ) ) } } } if ex_keyi . len ( ) > 0 { if r . len ( ) % 2 == 1 { r . push ( 0 ) } write_short ( & mut r , Some ( ex_bools . len ( ) as i16 ) ) ; write_short ( & mut r , Some ( ( ex_nums . len ( ) / 4 ) as i16 ) ) ; write_short ( & mut r , Some ( ( ex_stri . len ( ) / 2 ) as i16 ) ) ; write_short ( & mut r , Some ( ( ( ex_stri . len ( ) + ex_keyi . len ( ) ) / 2 ) as i16 ) ) ; write_short ( & mut r , Some ( ( ex_strs . len ( ) + ex_keys . len ( ) ) as i16 ) ) ; r . extend ( ex_bools ) ; if r . len ( ) % 2 == 1 { r . push ( 0 ) } r . extend ( ex_nums ) ; r . extend ( ex_stri ) ; r . extend ( ex_keyi ) ; r . extend ( ex_strs ) ; r . extend ( ex_keys ) ; } r }
Convert the terminfo struct back to the binary format of an
ncurses-compatible terminfo file.
Convert the terminfo struct back to the binary format of an ncurses - compatible terminfo file .
self
self