{"id":21177285,"url":"https://github.com/codechain-io/intertrait","last_synced_at":"2026-04-07T15:33:47.473Z","repository":{"id":47697988,"uuid":"244837836","full_name":"CodeChain-io/intertrait","owner":"CodeChain-io","description":"A library providing direct casting among trait objects implemented by a type","archived":false,"fork":false,"pushed_at":"2022-10-26T09:07:10.000Z","size":94,"stargazers_count":41,"open_issues_count":5,"forks_count":7,"subscribers_count":9,"default_branch":"master","last_synced_at":"2026-03-28T01:19:44.249Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/CodeChain-io.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE-APACHE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-03-04T07:43:42.000Z","updated_at":"2026-03-20T22:20:38.000Z","dependencies_parsed_at":"2022-09-07T08:22:47.755Z","dependency_job_id":null,"html_url":"https://github.com/CodeChain-io/intertrait","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/CodeChain-io/intertrait","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CodeChain-io%2Fintertrait","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CodeChain-io%2Fintertrait/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CodeChain-io%2Fintertrait/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CodeChain-io%2Fintertrait/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CodeChain-io","download_url":"https://codeload.github.com/CodeChain-io/intertrait/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CodeChain-io%2Fintertrait/sbom","scorecard":{"id":31247,"data":{"date":"2025-08-11","repo":{"name":"github.com/CodeChain-io/intertrait","commit":"d5d6dcb82ba1c5de2162eadd4dab31dfc9d01aa1"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3.4,"checks":[{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Token-Permissions","score":0,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Warn: no topLevel permission defined: .github/workflows/ci.yml:1","Info: no jobLevel write permissions found"],"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Code-Review","score":0,"reason":"Found 1/27 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Pinned-Dependencies","score":0,"reason":"dependency not pinned by hash detected -- score normalized to 0","details":["Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:17: update your workflow using https://app.stepsecurity.io/secureworkflow/CodeChain-io/intertrait/ci.yml/master?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/ci.yml:19: update your workflow using https://app.stepsecurity.io/secureworkflow/CodeChain-io/intertrait/ci.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:32: update your workflow using https://app.stepsecurity.io/secureworkflow/CodeChain-io/intertrait/ci.yml/master?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/ci.yml:34: update your workflow using https://app.stepsecurity.io/secureworkflow/CodeChain-io/intertrait/ci.yml/master?enable=pin","Info:   0 out of   2 GitHub-owned GitHubAction dependencies pinned","Info:   0 out of   2 third-party GitHubAction dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE-APACHE:0","Info: FSF or OSI recognized license: Apache License 2.0: LICENSE-APACHE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 5 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}}]},"last_synced_at":"2025-08-14T19:10:33.721Z","repository_id":47697988,"created_at":"2025-08-14T19:10:33.721Z","updated_at":"2025-08-14T19:10:33.721Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31518620,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-07T03:10:19.677Z","status":"ssl_error","status_checked_at":"2026-04-07T03:10:13.982Z","response_time":105,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5: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":[],"created_at":"2024-11-20T17:15:24.844Z","updated_at":"2026-04-07T15:33:47.455Z","avatar_url":"https://github.com/CodeChain-io.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Intertrait\n\n![Build Status](https://github.com/CodeChain-io/intertrait/workflows/ci/badge.svg)\n[![Latest Version](https://img.shields.io/crates/v/intertrait.svg)](https://crates.io/crates/intertrait)\n[![Rust Documentation](https://img.shields.io/badge/api-rustdoc-blue.svg)](https://docs.rs/intertrait)\n\nThis library provides direct casting among trait objects implemented by a type.\n\nIn Rust, a trait object for a sub-trait of [`std::any::Any`] can be downcast to a concrete type at runtime\nif the type is known. But no direct casting between two trait objects (i.e. without involving the concrete type\nof the backing value) is possible (even no coercion from a trait object for a trait to that for its super-trait yet).\n\nWith this crate, any trait object for a sub-trait of [`CastFrom`] can be cast directly to a trait object\nfor another trait implemented by the underlying type if the target traits are registered beforehand\nwith the macros provided by this crate.\n\n# Dependencies\nAdd the following two dependencies to your `Cargo.toml`:\n\n```toml\n[dependencies]\nintertrait = \"0.2\"\nlinkme = \"0.2\"\n```\n\nThe `linkme` dependency is required due to the use of `linkme` macro in the output of `intertrait` macros.\n\n# Usage\n\n```rust\nuse intertrait::*;\nuse intertrait::cast::*;\n\nstruct Data;\n\ntrait Source: CastFrom {}\n\ntrait Greet {\n    fn greet(\u0026self);\n}\n\n#[cast_to]\nimpl Greet for Data {\n    fn greet(\u0026self) {\n        println!(\"Hello\");\n    }\n}\n\nimpl Source for Data {}\n\nfn main() {\n    let data = Data;\n    let source: \u0026dyn Source = \u0026data;\n    let greet = source.cast::\u003cdyn Greet\u003e();\n    greet.unwrap().greet();\n}\n```\n\nTarget traits must be explicitly designated beforehand. There are three ways of doing it:\n\n### `#[cast_to]` to `impl` item\nThe trait implemented is designated as a target trait.\n\n```rust\nuse intertrait::*;\n\nstruct Data;\ntrait Greet { fn greet(\u0026self); }\n\n#[cast_to]\nimpl Greet for Data {\n    fn greet(\u0026self) {\n        println!(\"Hello\");\n    }\n}\n```\n\n### `#[cast_to(Trait)]` to type definition\nFor the type, the traits specified as arguments to the `#[cast_to(...)]` attribute are designated as target traits.\n\n```rust\nuse intertrait::*;\n\ntrait Greet { fn greet(\u0026self); }\n\nimpl Greet for Data {\n    fn greet(\u0026self) {\n        println!(\"Hello\");\n    }\n}\n\n#[cast_to(Greet, std::fmt::Debug)]\n#[derive(std::fmt::Debug)]\nstruct Data;\n```\n\n### `castable_to!(Type =\u003e Trait1, Trait2)`\nFor the type, the traits following `:` are designated as target traits.\n\n```rust\nuse intertrait::*;\n\n#[derive(std::fmt::Debug)]\nstruct Data;\ntrait Greet { fn greet(\u0026self); }\nimpl Greet for Data {\n    fn greet(\u0026self) {\n        println!(\"Hello\");\n    }\n}\n// Only in an item position due to the current limitation in the stable Rust.\n// https://github.com/rust-lang/rust/pull/68717\ncastable_to!(Data =\u003e Greet, std::fmt::Debug);\n\nfn main() {}\n```\n\n## `Arc` Support\n`std::sync::Arc` is unique in that it implements `downcast` method only on `dyn Any + Send + Sync + 'static'.\nTo use with `Arc`, the following steps should be taken:\n\n* Mark source traits with [`CastFromSync`] instead of [`CastFrom`]\n* Add `[sync]` flag to `#[cast_to]` and `castable_to!` as follows:\n  ```ignore\n  #[cast_to([sync])]\n  #[cast_to([sync] Trait1, Trait2)]\n  castable_to!(Type =\u003e [sync] Trait, Trait2);\n  ```\n\n# How it works\nFirst of all, [`CastFrom`] trait makes it possible to retrieve an object of [`std::any::Any`]\nfrom an object for a sub-trait of [`CastFrom`]. \n\nAnd the macros provided by `intertrait` generates trampoline functions for downcasting a trait object\nfor [`std::any::Any`] back to its concrete type and then creating a trait object for the target trait from it.\n\nThose trampoline functions are aggregated into a global registry\nusing [`linkme`](https://github.com/dtolnay/linkme/) crate, which involves no (generally discouraged)\nlife-before-main trick. The registry is keyed with a pair of [`TypeId`]s, which are those of the concrete type\nbacking a trait object for a sub-trait of [`CastFrom`] and the target trait (the actual implementation\nis a bit different here, but conceptually so).\n\nIn the course, it doesn't rely on any unstable Rust implementation details such as the layout of trait objects\nthat may be changed in the future.\n\n# Credits\n`intertrait` has taken much of its core ideas from the great [`traitcast`](https://github.com/bch29/traitcast) crate.\n\n# License\nLicensed under either of\n\n * Apache License, Version 2.0\n   ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)\n * MIT license\n   ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)\n\nat your option.\n\n## Contribution\nUnless you explicitly state otherwise, any contribution intentionally submitted\nfor inclusion in the work by you, as defined in the Apache-2.0 license, shall be\ndual licensed as above, without any additional terms or conditions.\n\n[`std::any::Any`]: https://doc.rust-lang.org/std/any/trait.Any.html\n[`TypeId`]: https://doc.rust-lang.org/std/any/struct.TypeId.html\n[`CastFrom`]: https://docs.rs/intertrait/*/intertrait/trait.CastFrom.html\n[`CastFromSync`]: https://docs.rs/intertrait/*/intertrait/trait.CastFromSync.html","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodechain-io%2Fintertrait","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcodechain-io%2Fintertrait","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodechain-io%2Fintertrait/lists"}