fn write_struct()

in src/bindgen/language_backend/cython.rs [161:222]


    fn write_struct<W: Write>(&mut self, out: &mut SourceWriter<W>, s: &Struct) {
        let condition = s.cfg.to_condition(self.config);
        condition.write_before(self.config, out);

        self.write_documentation(out, &s.documentation);

        out.write(self.config.style.cython_def());

        // Cython extern declarations don't manage layouts, layouts are defined entierly by the
        // corresponding C code. So this `packed` is only for documentation, and missing
        // `aligned(n)` is also not a problem.
        if let Some(align) = s.alignment {
            match align {
                ReprAlign::Packed => out.write("packed "),
                ReprAlign::Align(_) => {} // Not supported
            }
        }

        out.write("struct");

        if s.annotations.must_use(self.config) {
            if let Some(ref anno) = &self.config.structure.must_use {
                write!(out, " {}", anno);
            }
        }

        if let Some(note) = s
            .annotations
            .deprecated_note(self.config, DeprecatedNoteKind::Struct)
        {
            write!(out, " {}", note);
        }

        write!(out, " {}", s.export_name());

        out.open_brace();

        // Emit the pre_body section, if relevant
        if let Some(body) = &self.config.export.pre_body(&s.path) {
            out.write_raw_block(body);
            out.new_line();
        }

        out.write_vertical_source_list(self, &s.fields, ListType::Cap(";"), Self::write_field);
        if s.fields.is_empty() {
            out.write("pass");
        }

        // Emit the post_body section, if relevant
        if let Some(body) = &self.config.export.post_body(&s.path) {
            out.new_line();
            out.write_raw_block(body);
        }
        out.close_brace(true);

        for constant in &s.associated_constants {
            out.new_line();
            constant.write(self.config, self, out, Some(s));
        }

        condition.write_after(self.config, out);
    }