{"id":19007547,"url":"https://github.com/helgee/convertible.jl","last_synced_at":"2026-04-23T00:30:21.295Z","repository":{"id":149170462,"uuid":"83221753","full_name":"helgee/Convertible.jl","owner":"helgee","description":"Multi-step convert for Julia types","archived":false,"fork":false,"pushed_at":"2017-12-22T09:25:24.000Z","size":23,"stargazers_count":4,"open_issues_count":1,"forks_count":5,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-02-14T01:17:52.845Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Julia","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/helgee.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-02-26T16:04:36.000Z","updated_at":"2023-03-31T01:15:18.000Z","dependencies_parsed_at":"2023-09-03T02:45:22.493Z","dependency_job_id":null,"html_url":"https://github.com/helgee/Convertible.jl","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/helgee%2FConvertible.jl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/helgee%2FConvertible.jl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/helgee%2FConvertible.jl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/helgee%2FConvertible.jl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/helgee","download_url":"https://codeload.github.com/helgee/Convertible.jl/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240035475,"owners_count":19737601,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":[],"created_at":"2024-11-08T18:38:42.774Z","updated_at":"2026-04-23T00:30:21.198Z","avatar_url":"https://github.com/helgee.png","language":"Julia","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Convertible\n\n*Multi-step convert for Julia types.*\n\n[![Build Status][travis-badge]][travis-link] [![Coverage Status][coveralls-badge]][coveralls-link] [![codecov.io][codecov-badge]][codecov-link]\n\nThis package provides the `isconvertible` trait that can be applied to struct type definitions via the `@convertible` macro.\nTypes that share this trait can be easily converted into one another with a single call to `Base.convert` even though multiple intermediate conversions might be required.\n\n## Installation\n\nThe package can be installed through Julia's package manager:\n\n```julia\nPkg.add(\"Convertible\")\n```\n\n## Usage\n\nDefine convertible types:\n```julia\n# For Julia 0.5:\n# @convertible immutable/type A\n@convertible struct A\n    val::Int\nend\n\n@convertible struct B\n    val::Int\nend\n\n@convertible struct C\n    val::Int\nend\n\n@convertible struct D\n    val::Int\nend\n```\n\nDefine `Base.convert` methods:\n```julia\nBase.convert(::Type{B}, a::A) = B(a.val+1)\nBase.convert(::Type{D}, a::A) = D(a.val+1)\nBase.convert(::Type{C}, b::B) = C(b.val+1)\nBase.convert(::Type{A}, c::C) = A(c.val-2)\n```\n\nType `A` can now be converted to type `C` directly even though there is no direct `convert(::Type{C}, ::A)` available.\n```julia\njulia\u003e a = A(1)\njulia\u003e @convert convert(C, a)\nC(3)\n```\n\nInternally `Convertible.jl` will compute the shortest conversion path and emit a specialized method based on a generated function,\ne.g. `convert(C, convert(B, a))` in this case.\n\nAs shown above, you need to opt-in to the new `convert` behaviour by wrapping calls to convert with the `@convert` macro, e.g.:\n\n```julia\n@convert begin\n    b = convert(B, a)\n    c = convert(C, a)\n    a = convert(A, b)\n    d = convert(D, b)\nend\n```\n\n### Parametric Types\n\n`@convertible` can only be used on non-parametric types.\nIt can be applied to type aliases without parameters, though.\n\n```julia\ntype Param{T}\n    val::T\nend\n\n# The pre-v0.6 `typealias` keyword is not supported.\n@convertible const ParamFloat64 = Param{Float64}\n@convertible const ParamInt = Param{Int}\n@convertible const ParamUInt8 = Param{UInt8}\n\nBase.convert(::Type{ParamInt}, p::ParamFloat64) = Param{Int}(p.val)\nBase.convert(::Type{ParamUInt8}, p::ParamInt) = Param{UInt8}(p.val)\n```\n\n[travis-badge]: https://travis-ci.org/helgee/Convertible.jl.svg?branch=master\n[travis-link]: https://travis-ci.org/helgee/Convertible.jl\n[coveralls-badge]: https://coveralls.io/repos/helgee/Convertible.jl/badge.svg?branch=master\u0026service=github\n[coveralls-link]: https://coveralls.io/github/helgee/Convertible.jl?branch=master\n[codecov-badge]: http://codecov.io/github/helgee/Convertible.jl/coverage.svg?branch=master\n[codecov-link]: http://codecov.io/github/helgee/Convertible.jl?branch=master\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhelgee%2Fconvertible.jl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhelgee%2Fconvertible.jl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhelgee%2Fconvertible.jl/lists"}