fn write_set_fn(o: &mut BufWriter<File>, s: &Struct, m: &Member, impl_type_param: &str,
        impl_type_param_block: &str, structs: &HashMap<String, Struct>, is_for_builder: bool)
        -> io::Result<()> {
    let t = INDENT;
    // Skip excluded members and "...Count" members that have associated
    // pointer members (stuff that gets merged into a slice).
    if member_is_excluded(&m.orig_name) { return Ok(()); }
    // Skip "Count" members that are associated with a pointer field.
    if m.is_ptr_count { return Ok(()); }
    // // Skip setters on structs that are only returned from API calls and not
    // // use to create or set anything.
    // if !is_for_builder && s.returnedonly { return Ok(()); }

    // Signature and all kinds of other stuff:
    let sig = MemberSig::new(m, s, structs, impl_type_param);

    let unsafe_str = if sig.unsafe_to_set || m.is_fn_ptr_type { " unsafe" } else { "" };
    let set_pre = if is_for_builder { "" } else { "set_" };
    let self_arg_pre = if is_for_builder { "mut" } else { "&mut" };

    // Function signature:
    write!(o, "{t}pub{} fn {}{}<{}>({} self, {}: {})",
        unsafe_str, set_pre, sig.fn_name, sig.set_fn_type_params, self_arg_pre, sig.fn_name, sig.arg_type,
        /*s.voodoo_name, type_params, sig.where_clause,*/ t=t)?;
    if is_for_builder {
        write!(o, " -> {}Builder{}", s.voodoo_name, impl_type_param_block, /*sig.where_clause*/)?;
    }
    if !sig.where_clause.is_empty() {
        write!(o, "\n{t}{t}{t}{}", sig.where_clause, t=t)?;
    }
    writeln!(o, " {{")?;

    let set_counts = |o: &mut BufWriter<File>, extra_indent: &str| -> io::Result<()> {
        if let Some(ref count_orig_name) = m.ptr_count_member_orig_name {
            if count_orig_name == "codeSize" {
                writeln!(o, "{t}{t}{x}self.raw.{c} = {f}.len() * 4;", c=count_orig_name,
                    f=sig.fn_name, t=t, x=extra_indent)?;
            } else {
                writeln!(o, "{t}{t}{x}assert!(self.raw.{c} == 0 || self.raw.{c} == {f}.len() as _, \n\
                    {t}{t}{t}{x}\"count inconsistency found when specifying `{s}::{f}`.\");",
                    c=count_orig_name, f=sig.fn_name, s=s.voodoo_name, t=t, x=extra_indent)?;
                writeln!(o, "{t}{t}{x}self.raw.{c} = {f}.len() as _;", c=count_orig_name, f=sig.fn_name,
                    t=t, x=extra_indent)?;
            }
        }
        Ok(())
    };

    // if s.special_field(&m.voodoo_name).is_some() {
    //     write!(o, "{t}{t}self.{} = Some({}", m.voodoo_name, sig.fn_name, t=t)?;
    //     if sig.arg_is_slice {
    //         if m.is_handle_type {
    //             write!(o, ".iter().map(|h| h.handle()).collect()")?;
    //         } else if sig.arg_is_struct {
    //             write!(o, ".iter().map(|h| h.raw).collect()")?;
    //         }
    //     } else if sig.convert_arg {
    //         write!(o, ".into()")?;
    //     }
    //     writeln!(o, ");")?;
    //     writeln!(o, "{t}{t}{{", t=t)?;
    //     writeln!(o, "{t}{t}{t}let {} = self.{}.as_ref().unwrap();", m.voodoo_name, sig.fn_name, t=t)?;
    //     writeln!(o, "{t}{t}{t}self.raw.{} = {}.as_ptr();",
    //         m.orig_name, m.voodoo_name, t=t)?;
    //     set_counts(o, t)?;
    //     writeln!(o, "{t}{t}}}", t=t)?;
    // } else {
    set_counts(o, "")?;
    write!(o, "{t}{t}self.raw.{} = ", m.orig_name, t=t)?;
    if sig.arg_is_struct {
        if m.is_ptr {
            if sig.arg_is_slice && sig.arg_is_repr_c {
                if m.is_const {
                    write!(o, "{}.as_ptr() as *const ", sig.fn_name)?;
                    write!(o, "{}{}", ORIG_PRE, m.orig_type)?;
                } else {
                    write!(o, "{}.as_mut_ptr() as *mut ", sig.fn_name)?;
                    write!(o, "{}{}", ORIG_PRE, m.orig_type)?;
                }
            } else {
                write!(o, "{}.as_raw()", sig.fn_name)?;
            }
        } else {
            if let Some(ref len) = m.array_len {
                if sig.arg_is_repr_c {

                }
                match len.parse::<usize>() {
                    Ok(len) => {
                        // Numeric length:
                        write!(o, "[")?;
                        for idx in 0..len {
                            write!(o, "{}[{}].raw, ", sig.fn_name, idx)?;
                        }
                        write!(o, "]")?;
                    },
                    Err(_) => {
                        // Constant (macro) length:
                        if sig.arg_is_repr_c {
                            write!(o, "unsafe {{ *(&{} as *const [{}; {}{}] as *const _) }}",
                                sig.fn_name, m.voodoo_type, ORIG_PRE, len)?
                        }
                    },
                }
            } else {
                write!(o, "{}.raw", sig.fn_name)?;
            }
        }
    } else {
        if m.is_handle_type {
            if sig.arg_is_slice {
                // assert!(s.special_fields.contains_key(&m.voodoo_name),
                //     "\"{}\" is lacking a special field for {{ {}: {} }}",
                //     s.voodoo_name, sig.fn_name, sig.arg_type);
                write!(o, "{}.as_ptr() as *const {}{}", sig.fn_name, ORIG_PRE, m.orig_type)?;
            } else {
                if m.is_ptr {
                    write!(o, "&")?;
                }
                // write!(o, "{}.handle()", sig.fn_name)?;
                write!(o, "{}.handle().0", sig.fn_name)?;
            }
        } else if m.voodoo_type.as_str() == "bool" {
            write!(o, "{} as u32", sig.fn_name)?;
        } else if sig.convert_to_bits {
            write!(o, "{}.bits()", sig.fn_name)?;
        } else if sig.arg_is_slice {
            if m.is_const {
                write!(o, "{}.as_ptr() as *const {} as *const _", sig.fn_name, m.voodoo_type)?;
            } else {
                write!(o, "{}.as_mut_ptr() as *mut {} as *mut _", sig.fn_name, m.voodoo_type)?;
            }
        } else if sig.convert_arg && !m.is_ptr {
            write!(o, "{}.into()", sig.fn_name)?;
            if sig.convert_arg_twice {
                write!(o, ".into()")?;
            }
        } else if m.voodoo_type == "PipelineStageFlags" && m.is_ptr {
            write!(o, "{} as *const PipelineStageFlags as *const _", sig.fn_name)?;
        } else if sig.arg_is_c_str {
            write!(o, "{}.as_ptr()", sig.fn_name)?;
        } else {
            write!(o, "{}", sig.fn_name)?;
        }
    }
    writeln!(o, ";")?;
    // }
    if is_for_builder {
        writeln!(o, "{t}{t}self", t=t)?;
    }

    write!(o, "{t}}}\n\n", t=t)?;

    Ok(())
}
/// Writes a setter function to the output buffer.
Writes a setter function to the output buffer.
Writes a setter function to the output buffer .
fn write_set_fn(o: &mut BufWriter<File>, s: &Struct, m: &Member, impl_type_param: &str,
        impl_type_param_block: &str, structs: &HashMap<String, Struct>, is_for_builder: bool)
        -> io::Result<()> {
    let t = INDENT;
    // Skip excluded members and "...Count" members that have associated
    // pointer members (stuff that gets merged into a slice).
    if member_is_excluded(&m.orig_name) { return Ok(()); }
    // Skip "Count" members that are associated with a pointer field.
    if m.is_ptr_count { return Ok(()); }
    // // Skip setters on structs that are only returned from API calls and not
    // // use to create or set anything.
    // if !is_for_builder && s.returnedonly { return Ok(()); }
    // Signature and all kinds of other stuff:
    let sig = MemberSig::new(m, s, structs, impl_type_param);
    let unsafe_str = if sig.unsafe_to_set || m.is_fn_ptr_type { " unsafe" } else { "" };
    let set_pre = if is_for_builder { "" } else { "set_" };
    let self_arg_pre = if is_for_builder { "mut" } else { "&mut" };
    // Function signature:
    write!(o, "{t}pub{} fn {}{}<{}>({} self, {}: {})",
        unsafe_str, set_pre, sig.fn_name, sig.set_fn_type_params, self_arg_pre, sig.fn_name, sig.arg_type,
        /*s.voodoo_name, type_params, sig.where_clause,*/ t=t)?;
    if is_for_builder {
        write!(o, " -> {}Builder{}", s.voodoo_name, impl_type_param_block, /*sig.where_clause*/)?;
    }
    if !sig.where_clause.is_empty() {
        write!(o, "\n{t}{t}{t}{}", sig.where_clause, t=t)?;
    }
    writeln!(o, " {{")?;
    let set_counts = |o: &mut BufWriter<File>, extra_indent: &str| -> io::Result<()> {
        if let Some(ref count_orig_name) = m.ptr_count_member_orig_name {
            if count_orig_name == "codeSize" {
                writeln!(o, "{t}{t}{x}self.raw.{c} = {f}.len() * 4;", c=count_orig_name,
                    f=sig.fn_name, t=t, x=extra_indent)?;
            } else {
                writeln!(o, "{t}{t}{x}assert!(self.raw.{c} == 0 || self.raw.{c} == {f}.len() as _, \n\
                    {t}{t}{t}{x}\"count inconsistency found when specifying `{s}::{f}`.\");",
                    c=count_orig_name, f=sig.fn_name, s=s.voodoo_name, t=t, x=extra_indent)?;
                writeln!(o, "{t}{t}{x}self.raw.{c} = {f}.len() as _;", c=count_orig_name, f=sig.fn_name,
                    t=t, x=extra_indent)?;
            }
        }
        Ok(())
    };
    // if s.special_field(&m.voodoo_name).is_some() {
    //     write!(o, "{t}{t}self.{} = Some({}", m.voodoo_name, sig.fn_name, t=t)?;
    //     if sig.arg_is_slice {
    //         if m.is_handle_type {
    //             write!(o, ".iter().map(|h| h.handle()).collect()")?;
    //         } else if sig.arg_is_struct {
    //             write!(o, ".iter().map(|h| h.raw).collect()")?;
    //         }
    //     } else if sig.convert_arg {
    //         write!(o, ".into()")?;
    //     }
    //     writeln!(o, ");")?;
    //     writeln!(o, "{t}{t}{{", t=t)?;
    //     writeln!(o, "{t}{t}{t}let {} = self.{}.as_ref().unwrap();", m.voodoo_name, sig.fn_name, t=t)?;
    //     writeln!(o, "{t}{t}{t}self.raw.{} = {}.as_ptr();",
    //         m.orig_name, m.voodoo_name, t=t)?;
    //     set_counts(o, t)?;
    //     writeln!(o, "{t}{t}}}", t=t)?;
    // } else {
    set_counts(o, "")?;
    write!(o, "{t}{t}self.raw.{} = ", m.orig_name, t=t)?;
    if sig.arg_is_struct {
        if m.is_ptr {
            if sig.arg_is_slice && sig.arg_is_repr_c {
                if m.is_const {
                    write!(o, "{}.as_ptr() as *const ", sig.fn_name)?;
                    write!(o, "{}{}", ORIG_PRE, m.orig_type)?;
                } else {
                    write!(o, "{}.as_mut_ptr() as *mut ", sig.fn_name)?;
                    write!(o, "{}{}", ORIG_PRE, m.orig_type)?;
                }
            } else {
                write!(o, "{}.as_raw()", sig.fn_name)?;
            }
        } else {
            if let Some(ref len) = m.array_len {
                if sig.arg_is_repr_c {
                }
                match len.parse::<usize>() {
                    Ok(len) => {
                        // Numeric length:
                        write!(o, "[")?;
                        for idx in 0..len {
                            write!(o, "{}[{}].raw, ", sig.fn_name, idx)?;
                        }
                        write!(o, "]")?;
                    },
                    Err(_) => {
                        // Constant (macro) length:
                        if sig.arg_is_repr_c {
                            write!(o, "unsafe {{ *(&{} as *const [{}; {}{}] as *const _) }}",
                                sig.fn_name, m.voodoo_type, ORIG_PRE, len)?
                        }
                    },
                }
            } else {
                write!(o, "{}.raw", sig.fn_name)?;
            }
        }
    } else {
        if m.is_handle_type {
            if sig.arg_is_slice {
                // assert!(s.special_fields.contains_key(&m.voodoo_name),
                //     "\"{}\" is lacking a special field for {{ {}: {} }}",
                //     s.voodoo_name, sig.fn_name, sig.arg_type);
                write!(o, "{}.as_ptr() as *const {}{}", sig.fn_name, ORIG_PRE, m.orig_type)?;
            } else {
                if m.is_ptr {
                    write!(o, "&")?;
                }
                // write!(o, "{}.handle()", sig.fn_name)?;
                write!(o, "{}.handle().0", sig.fn_name)?;
            }
        } else if m.voodoo_type.as_str() == "bool" {
            write!(o, "{} as u32", sig.fn_name)?;
        } else if sig.convert_to_bits {
            write!(o, "{}.bits()", sig.fn_name)?;
        } else if sig.arg_is_slice {
            if m.is_const {
                write!(o, "{}.as_ptr() as *const {} as *const _", sig.fn_name, m.voodoo_type)?;
            } else {
                write!(o, "{}.as_mut_ptr() as *mut {} as *mut _", sig.fn_name, m.voodoo_type)?;
            }
        } else if sig.convert_arg && !m.is_ptr {
            write!(o, "{}.into()", sig.fn_name)?;
            if sig.convert_arg_twice {
                write!(o, ".into()")?;
            }
        } else if m.voodoo_type == "PipelineStageFlags" && m.is_ptr {
            write!(o, "{} as *const PipelineStageFlags as *const _", sig.fn_name)?;
        } else if sig.arg_is_c_str {
            write!(o, "{}.as_ptr()", sig.fn_name)?;
        } else {
            write!(o, "{}", sig.fn_name)?;
        }
    }
    writeln!(o, ";")?;
    // }
    if is_for_builder {
        writeln!(o, "{t}{t}self", t=t)?;
    }
    write!(o, "{t}}}\n\n", t=t)?;
    Ok(())
}
fn write_set_fn ( o : & mut BufWriter < File > , s : & Struct , m : & Member , impl_type_param : & str , impl_type_param_block : & str , structs : & HashMap < String , Struct > , is_for_builder : bool ) -> io :: Result < ( ) > { let t = INDENT ; // Skip excluded members and "...Count" members that have associated // pointer members (stuff that gets merged into a slice). if member_is_excluded ( & m . orig_name ) { return Ok ( ( ) ) ; } // Skip "Count" members that are associated with a pointer field. if m . is_ptr_count { return Ok ( ( ) ) ; } // // Skip setters on structs that are only returned from API calls and not // // use to create or set anything. // if !is_for_builder && s.returnedonly { return Ok(()); } // Signature and all kinds of other stuff: let sig = MemberSig :: new ( m , s , structs , impl_type_param ) ; let unsafe_str = if sig . unsafe_to_set || m . is_fn_ptr_type { " " } else { " " } ; let set_pre = if is_for_builder { " " } else { " " } ; let self_arg_pre = if is_for_builder { " " } else { " " } ; // Function signature: write ! ( o " " unsafe_str set_pre sig fn_name sig set_fn_type_params self_arg_pre sig fn_name sig arg_type /*s.voodoo_name, type_params, sig.where_clause,*/ t t ) ? ; if is_for_builder { write ! ( o " " s voodoo_name impl_type_param_block /*sig.where_clause*/ ) ? ; } if ! sig . where_clause . is_empty ( ) { write ! ( o " \n " sig where_clause t t ) ? ; } writeln ! ( o " " ) ? ; let set_counts = | o : & mut BufWriter < File > , extra_indent : & str | -> io :: Result < ( ) > { if let Some ( ref count_orig_name ) = m . ptr_count_member_orig_name { if count_orig_name == " " { writeln ! ( o " " c count_orig_name f sig fn_name t t x extra_indent ) ? ; } else { writeln ! ( o " \n \
 \" \" " c count_orig_name f sig fn_name s s voodoo_name t t x extra_indent ) ? ; writeln ! ( o " " c count_orig_name f sig fn_name t t x extra_indent ) ? ; } } Ok ( ( ) ) } ; // if s.special_field(&m.voodoo_name).is_some() { //     write!(o, "{t}{t}self.{} = Some({}", m.voodoo_name, sig.fn_name, t=t)?; //     if sig.arg_is_slice { //         if m.is_handle_type { //             write!(o, ".iter().map(|h| h.handle()).collect()")?; //         } else if sig.arg_is_struct { //             write!(o, ".iter().map(|h| h.raw).collect()")?; //         } //     } else if sig.convert_arg { //         write!(o, ".into()")?; //     } //     writeln!(o, ");")?; //     writeln!(o, "{t}{t}{{", t=t)?; //     writeln!(o, "{t}{t}{t}let {} = self.{}.as_ref().unwrap();", m.voodoo_name, sig.fn_name, t=t)?; //     writeln!(o, "{t}{t}{t}self.raw.{} = {}.as_ptr();", //         m.orig_name, m.voodoo_name, t=t)?; //     set_counts(o, t)?; //     writeln!(o, "{t}{t}}}", t=t)?; // } else { set_counts ( o , " " ) ? ; write ! ( o " " m orig_name t t ) ? ; if sig . arg_is_struct { if m . is_ptr { if sig . arg_is_slice && sig . arg_is_repr_c { if m . is_const { write ! ( o " " sig fn_name ) ? ; write ! ( o " " ORIG_PRE m orig_type ) ? ; } else { write ! ( o " " sig fn_name ) ? ; write ! ( o " " ORIG_PRE m orig_type ) ? ; } } else { write ! ( o " " sig fn_name ) ? ; } } else { if let Some ( ref len ) = m . array_len { if sig . arg_is_repr_c { } match len . parse :: < usize > ( ) { Ok ( len ) => { // Numeric length: write ! ( o " " ) ? ; for idx in 0 .. len { write ! ( o " " sig fn_name idx ) ? ; } write ! ( o " " ) ? ; } , Err ( _ ) => { // Constant (macro) length: if sig . arg_is_repr_c { write ! ( o " " sig fn_name m voodoo_type ORIG_PRE len ) ? } } , } } else { write ! ( o " " sig fn_name ) ? ; } } } else { if m . is_handle_type { if sig . arg_is_slice { // assert!(s.special_fields.contains_key(&m.voodoo_name), //     "\"{}\" is lacking a special field for {{ {}: {} }}", //     s.voodoo_name, sig.fn_name, sig.arg_type); write ! ( o " " sig fn_name ORIG_PRE m orig_type ) ? ; } else { if m . is_ptr { write ! ( o " " ) ? ; } // write!(o, "{}.handle()", sig.fn_name)?; write ! ( o " " sig fn_name ) ? ; } } else if m . voodoo_type . as_str ( ) == " " { write ! ( o " " sig fn_name ) ? ; } else if sig . convert_to_bits { write ! ( o " " sig fn_name ) ? ; } else if sig . arg_is_slice { if m . is_const { write ! ( o " " sig fn_name m voodoo_type ) ? ; } else { write ! ( o " " sig fn_name m voodoo_type ) ? ; } } else if sig . convert_arg && ! m . is_ptr { write ! ( o " " sig fn_name ) ? ; if sig . convert_arg_twice { write ! ( o " " ) ? ; } } else if m . voodoo_type == " " && m . is_ptr { write ! ( o " " sig fn_name ) ? ; } else if sig . arg_is_c_str { write ! ( o " " sig fn_name ) ? ; } else { write ! ( o " " sig fn_name ) ? ; } } writeln ! ( o " " ) ? ; // } if is_for_builder { writeln ! ( o " " t t ) ? ; } write ! ( o " \n \n " t t ) ? ; Ok ( ( ) ) }
Writes a setter function to the output buffer.
Writes a setter function to the output buffer .
o
&mut BufWriter<File>
s
&Struct
m
&Member
impl_type_param
&str
impl_type_param_block
&str
structs
&HashMap<String, Struct>
is_for_builder
bool
o
&mut BufWriter<File>
s
&Struct
m
&Member
impl_type_param
&str
impl_type_param_block
&str
structs
&HashMap<String, Struct>
is_for_builder
bool