Skip to main content

extract_rust_field_chunks

Function extract_rust_field_chunks 

Source
pub fn extract_rust_field_chunks(body: &str) -> Vec<(String, String)>
Expand description

Split a Rust struct body (the text between { and }, exclusive) into field chunks, preserving attributes, doc comments, and visibility modifiers.

Returns Vec<(field_name, raw_chunk_text)> in declaration order. The raw_chunk_text includes the field declaration line and its trailing comma; attributes/doc-comments that appear immediately before the field are included in that field’s chunk.

Chunk boundaries are determined by , at bracket depth 0, matching how Rust struct fields are separated. The > character is tracked conservatively: if depth goes negative it is reset to 0 (handles -> and comparison operators in default expressions, though those are rare in struct bodies).