| 4856 | // --- Rust impl block extraction --- |
| 4857 | |
| 4858 | static void extract_rust_impl(CBMExtractCtx *ctx, TSNode node, const CBMLangSpec *spec) { |
| 4859 | CBMArena *a = ctx->arena; |
| 4860 | |
| 4861 | TSNode type_node = ts_node_child_by_field_name(node, TS_FIELD("type")); |
| 4862 | if (ts_node_is_null(type_node)) { |
| 4863 | return; |
| 4864 | } |
| 4865 | |
| 4866 | char *type_name = cbm_node_text(a, type_node, ctx->source); |
| 4867 | if (!type_name || !type_name[0]) { |
| 4868 | return; |
| 4869 | } |
| 4870 | /* Strip generic args from the implementing type: `Buffer<T>` → `Buffer`, |
| 4871 | * `Wrapper<T>` → `Wrapper`. The struct identity is the base name. */ |
| 4872 | { |
| 4873 | char *lt = strchr(type_name, '<'); |
| 4874 | if (lt) { |
| 4875 | *lt = '\0'; |
| 4876 | } |
| 4877 | } |
| 4878 | |
| 4879 | const char *type_qn = cbm_fqn_compute(a, ctx->project, ctx->rel_path, type_name); |
| 4880 | |
| 4881 | // Check for "impl Trait for Struct" pattern |
| 4882 | const char *impl_trait = NULL; |
| 4883 | TSNode trait_node = ts_node_child_by_field_name(node, TS_FIELD("trait")); |
| 4884 | if (!ts_node_is_null(trait_node)) { |
| 4885 | char *trait_name = cbm_node_text(a, trait_node, ctx->source); |
| 4886 | /* Strip generic args from the trait: `From<Feet>` → `From`, |
| 4887 | * `Index<usize>` → `Index`, `AsRef<str>` → `AsRef`. Qualified paths |
| 4888 | * like `io::Write` / `fmt::Display` have no `<` and are preserved. */ |
| 4889 | if (trait_name) { |
| 4890 | char *lt = strchr(trait_name, '<'); |
| 4891 | if (lt) { |
| 4892 | *lt = '\0'; |
| 4893 | } |
| 4894 | } |
| 4895 | if (trait_name && trait_name[0]) { |
| 4896 | CBMImplTrait it = {0}; |
| 4897 | it.trait_name = trait_name; |
| 4898 | it.struct_name = type_name; |
| 4899 | it.struct_qn = type_qn; |
| 4900 | cbm_impltrait_push(&ctx->result->impl_traits, a, it); |
| 4901 | impl_trait = trait_name; |
| 4902 | } |
| 4903 | } |
| 4904 | |
| 4905 | // Extract methods inside impl body |
| 4906 | TSNode body = ts_node_child_by_field_name(node, TS_FIELD("body")); |
| 4907 | if (ts_node_is_null(body)) { |
| 4908 | return; |
| 4909 | } |
| 4910 | |
| 4911 | uint32_t count = ts_node_child_count(body); |
| 4912 | for (uint32_t i = 0; i < count; i++) { |
| 4913 | TSNode child = ts_node_child(body, i); |
| 4914 | if (ts_node_is_null(child)) { |
| 4915 | continue; |
no test coverage detected