{"id":17994946,"url":"https://github.com/totalkrill/random_variant","last_synced_at":"2025-03-05T08:51:47.774Z","repository":{"id":53881672,"uuid":"521795524","full_name":"TotalKrill/random_variant","owner":"TotalKrill","description":null,"archived":false,"fork":false,"pushed_at":"2023-12-01T12:44:41.000Z","size":31,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-02T00:14:44.210Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/TotalKrill.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2022-08-05T22:58:08.000Z","updated_at":"2022-08-05T22:58:40.000Z","dependencies_parsed_at":"2024-10-29T20:20:16.898Z","dependency_job_id":null,"html_url":"https://github.com/TotalKrill/random_variant","commit_stats":{"total_commits":10,"total_committers":2,"mean_commits":5.0,"dds":"0.19999999999999996","last_synced_commit":"18326cb549fce75e93c4978f464eb9fb41067f46"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TotalKrill%2Frandom_variant","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TotalKrill%2Frandom_variant/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TotalKrill%2Frandom_variant/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TotalKrill%2Frandom_variant/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TotalKrill","download_url":"https://codeload.github.com/TotalKrill/random_variant/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241997287,"owners_count":20055113,"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-10-29T20:17:16.734Z","updated_at":"2025-03-05T08:51:47.766Z","avatar_url":"https://github.com/TotalKrill.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# RandomVariant\n\nTrait that returns a random variant of the given type, if you are creating a\nnew type to limit some values, instead of deriving the RandomVariant,\nimplement it manually to ensure only correct values are created\nUnless you also want to try the Result type\nUseful for hunting down unwraps or other assumptions in your code,\nThe benefit over the crate [EveryVariant](https://github.com/TotalKrill/every_variant) is that this can be limited to\nA much smaller set to test, where generting every variant quickly can grow to unmanageable\ntesting sets\n\n\n# Example\n\n``` rust\n    use serde::Serialize;\n    use std::net::IpAddr;\n\n    #[derive(RandomVariant, Serialize)]\n    enum Message {\n        Log(String),\n        ErrorCode(u32),\n        /// This tuple will fail to serialize if flattened in serde\n        Rebooting,\n    }\n\n    #[derive(RandomVariant, Serialize)]\n    struct LoggedMessage {\n        /// Fail to serialize, since flatteing enums is not supported\n        #[serde(flatten)]\n        t: Message,\n        add: IpAddr,\n    }\n    let mut rng = crate::rand::thread_rng();\n    \n    /// This allows us to limit the testing set to trying 100 randomized structs\n    for _i in 0..100 {\n        let v = LoggedMessage::random_variant(\u0026mut rng);\n        serde_json::to_string(\u0026v).unwrap();\n    }\n\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftotalkrill%2Frandom_variant","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftotalkrill%2Frandom_variant","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftotalkrill%2Frandom_variant/lists"}