{"id":15527541,"url":"https://github.com/elliotchance/reflect","last_synced_at":"2026-02-01T00:10:21.682Z","repository":{"id":48258986,"uuid":"386166388","full_name":"elliotchance/reflect","owner":"elliotchance","description":"🪞 Runtime reflection for V (vlang)","archived":false,"fork":false,"pushed_at":"2021-08-04T03:52:06.000Z","size":34,"stargazers_count":28,"open_issues_count":1,"forks_count":2,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-06-14T04:03:20.801Z","etag":null,"topics":["vlang","vlang-awesome","vlang-library","vlang-module"],"latest_commit_sha":null,"homepage":"","language":"V","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/elliotchance.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-07-15T04:47:52.000Z","updated_at":"2025-02-18T10:32:03.000Z","dependencies_parsed_at":"2022-08-30T08:00:18.540Z","dependency_job_id":null,"html_url":"https://github.com/elliotchance/reflect","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/elliotchance/reflect","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elliotchance%2Freflect","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elliotchance%2Freflect/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elliotchance%2Freflect/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elliotchance%2Freflect/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/elliotchance","download_url":"https://codeload.github.com/elliotchance/reflect/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elliotchance%2Freflect/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28961286,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-31T23:03:11.038Z","status":"ssl_error","status_checked_at":"2026-01-31T22:56:44.691Z","response_time":128,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["vlang","vlang-awesome","vlang-library","vlang-module"],"created_at":"2024-10-02T11:07:01.065Z","updated_at":"2026-02-01T00:10:21.668Z","avatar_url":"https://github.com/elliotchance.png","language":"V","funding_links":[],"categories":[],"sub_categories":[],"readme":"elliotchance.reflect\n====================\n\nRuntime reflection for [V](https://vlang.io).\n\nV does not carry runtime information about types. Although compile-time\nreflection is more performant it can be limiting in some cases that can't be\navoided.\n\n*IMPORTANT: This project is more to demonstrate that a lot of the runtime\nreflection functionality one might need can be done without technically using\nruntime types. This implementation relies on static code being generated from\ncompile-time reflection for known types going into the appropriate\nconstructors.*\n\n- [Installation](#installation)\n- [Values](#values)\n- [Types](#types)\n- [Arrays](#arrays)\n- [Maps](#maps)\n- [Structs](#structs)\n\nInstallation\n------------\n\n```bash\nv install elliotchance.reflect\n```\n\nValues\n------\n\nA `Value` can be created from any literal or simple value, for example:\n\n```v\nimport elliotchance.reflect\n\nfn main() {\n\tv := reflect.value_of(1.23)\n\n\tprintln(v.typ)         // \"f64\"\n\tprintln(v.get_f64())   // 1.23\n\tprintln(v.get_int())   // V panic: value must be int but is f64\n}\n```\n\nThis becomes especially useful when dealing with arrays of mixed types:\n\n```v\n// Only sum numbers.\nfn sum(items []reflect.Value) f64 {\n\tmut total := 0.0\n\n\tfor item in items {\n\t\tmatch item.typ.kind {\n\t\t\t.is_f64 { total += item.get_f64() }\n\t\t\t.is_int { total += item.get_int() }\n\t\t\telse { /* ignore */ }\n\t\t}\n\t}\n\n\treturn total\n}\n\nfn main() {\n\tv := [\n\t\treflect.value_of(1.23),\n\t\treflect.value_of(\"hello\"),\n\t\treflect.value_of(7),\n\t]\n\tprintln(sum(v)) // 8.23\n}\n```\n\nTypes\n-----\n\nAll `Values` have a `Type` which can be accessed on the `.typ` field.\n\n- `.kind`: one of the `Kind` values: `is_bool`, `is_string`, `is_i8`, `is_i16`,\n`is_int`, `is_i64`, `is_byte`, `is_u16`, `is_u32`, `is_u64`, `is_rune`,\n`is_f32`, `is_f64`.\n- `.elem`: Only applies for arrays, describes the element type.\n- `.str()`: The string representation that matches the compile-time type in V.\n\nArrays\n------\n\n```v\nimport elliotchance.reflect\n\nfn main() {\n\tv := reflect.array_of([5, 6, 7])\n\n\tprintln(v.typ)                      // \"[]int\"\n\tprintln(v.typ.kind)                 // \"array\"\n\tprintln(v.typ.elem.kind)            // \"int\"\n\tprintln(v.len())                    // 3\n\tprintln(v.cap())                    // 3\n\tprintln(v.get_index(1).get_int())   // 6\n\tprintln(v.get_index(5))             // V panic: array index 5 is out of bounds (len = 3)\n}\n```\n\nMaps\n----\n\n```v\nimport elliotchance.reflect\n\nfn main() {\n\tmut m := map[string]int{}\n\tm['a'] = 5\n\tm['b'] = 7\n\tm['c'] = 9\n\n\tv := reflect.map_of(m)\n\n\tprintln(v.typ)                                        // \"map[string]int\"\n\tprintln(v.typ.kind)                                   // \"map\"\n\tprintln(v.typ.key.kind)                               // \"string\"\n\tprintln(v.typ.elem.kind)                              // \"int\"\n\tprintln(v.len())                                      // 3\n\tprintln(v.keys())                                     // ['a', 'b', 'c']\n\tprintln(v.get_key(reflect.value_of('b')).get_int())   // 7\n\tprintln(v.get_key(reflect.value_of('d')))             // V panic: key not found: d\n\tprintln(v.get_key(reflect.value_of(123)))             // V panic: value must be string but is int\n}\n```\n\nStructs\n-------\n\n```v\nimport elliotchance.reflect\n\nstruct Foo {\n\ta int\n\tb f64\n\tc string\n}\n\nfn main() {\n\ts := Foo{123, 4.56, 'hello'}\n\tv := reflect.struct_of(\u0026s)\n\n\tprintln(v.typ)                    // \"main.Foo\"\n\tprintln(v.typ.kind)               // \"struct\"\n\tprintln(v.fields())               // ['a', 'b', 'c']\n\tprintln(v.field('b').typ)         // \"f64\"\n\tprintln(v.field('b').get_f64())   // 4.56\n\tprintln(v.field('d'))             // V panic: field not found: d\n\n\tv.field('b').set_string('hi')     // V panic: value must be f64 but is string\n\n\tv.field('c').set_string('hi')\n\tprintln(v.field('c').get_string()) // \"hi\"\n\tprintln(s.c)                       // \"hi\"\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felliotchance%2Freflect","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Felliotchance%2Freflect","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felliotchance%2Freflect/lists"}