MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / extract_rust_impl

Function extract_rust_impl

internal/cbm/extract_defs.c:4870–4974  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 1

walk_defsFunction · 0.85

Calls 12

cbm_node_textFunction · 0.85
cbm_fqn_computeFunction · 0.85
cbm_impltrait_pushFunction · 0.85
cbm_kind_in_setFunction · 0.85
func_name_nodeFunction · 0.85
cbm_is_exportedFunction · 0.85
extract_param_typesFunction · 0.85
set_def_complexityFunction · 0.85
compute_fingerprintFunction · 0.85
cbm_defs_pushFunction · 0.85
cbm_arena_sprintfFunction · 0.70

Tested by

no test coverage detected