{"id":17166528,"url":"https://github.com/willcrichton/simple-bind","last_synced_at":"2025-04-13T15:13:47.887Z","repository":{"id":57667392,"uuid":"126902316","full_name":"willcrichton/simple-bind","owner":"willcrichton","description":"One-line non-exhaustive binds in Rust","archived":false,"fork":false,"pushed_at":"2018-05-13T03:55:48.000Z","size":23,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-11T19:09:03.101Z","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":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/willcrichton.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":"2018-03-26T23:35:47.000Z","updated_at":"2018-05-13T03:55:49.000Z","dependencies_parsed_at":"2022-09-02T14:22:37.559Z","dependency_job_id":null,"html_url":"https://github.com/willcrichton/simple-bind","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/willcrichton%2Fsimple-bind","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/willcrichton%2Fsimple-bind/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/willcrichton%2Fsimple-bind/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/willcrichton%2Fsimple-bind/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/willcrichton","download_url":"https://codeload.github.com/willcrichton/simple-bind/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248732488,"owners_count":21152852,"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-14T23:05:57.192Z","updated_at":"2025-04-13T15:13:47.870Z","avatar_url":"https://github.com/willcrichton.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# simple-bind: one-line non-exhaustive binds in Rust\n[![Build Status](https://travis-ci.org/willcrichton/simple-bind.svg?branch=master)](https://travis-ci.org/willcrichton/simple-bind)\n[![](https://img.shields.io/crates/v/simple-bind.svg)](https://crates.io/crates/simple-bind)\n[![](https://docs.rs/simple-bind/badge.svg)](https://docs.rs/simple-bind/)\n\n**Nightly-only crate.**\n\n```rust\n// Here's a brief example that demonstrates how simple-bind works.\n\n#![feature(proc_macro, pattern_parentheses, stmt_expr_attributes)]\nextern crate simple_bind;\nuse simple_bind::bind;\n\nfn main() {\n  enum A { Foo(i32), Bar };\n\n  // Let's say you have a variant of an enum.\n  let x = A::Foo(10);\n\n  // Previously, if you knew `x` was `Foo` and just wanted to access the inside,\n  // you had to do either:\n  let y = match x { A::Foo(y) =\u003e y, _ =\u003e unreachable!() };\n  // or...\n  let y = if let A::Foo(y) = x { y } else { unreachable!() };\n\n  // With simple-bind, you can instead do:\n  bind!{let A::Foo(y) = x;}\n\n  // No more nested match/if statements!\n  assert_eq!(y, 10);\n}\n```\n\n## Setup\n\nUse of this crate uses the unstable `proc_macro` API, so it requires nightly and a few feature gates.\n\nEnable nightly on your repository:\n```\nrustup override set nightly\n```\n\nAdd this line to your `cargo.toml`:\n```toml\n[dependencies]\nsimple-bind = \"0.1.5\"\n```\n\nTo your main module file (`lib.rs` or `main.rs`), add:\n```rust\n#![feature(proc_macro, pattern_parentheses, stmt_expr_attributes)]\nextern crate simple_bind;\n```\n\nThen wherever you want to use the macro, use normal imports (i.e. not `#[macro_use]`):\n```rust\nuse simple_bind::bind;\n```\n\n## Examples\n\n```rust\nfn main() {\n  enum B { Quux(i32) };\n  enum A { Foo(i32), Bar{y: i32}, Baz(B) };\n\n  // Simple binds\n  bind!{let A::Foo(x) = A::Foo(10);}\n\n  // Struct binds\n  let s = A::Bar{y: 1};\n  bind!{let A::Bar{y} = s;}\n\n  // Nested binds\n  bind!{let A::Baz(B::Quux(x)) = A::Baz(B::Quux(10));}\n\n  // Reference binds\n  let mut s = A::Foo(10);\n  bind!{let \u0026mut A::Foo(ref mut y) = \u0026mut s;}\n  *y = 3;\n}\n```\n\n## Issues\n\nThis implementation just covers cases I've run in to, and is not exhaustive to all possible binds. If you find a problem, feel free to submit an issue or a PR!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwillcrichton%2Fsimple-bind","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwillcrichton%2Fsimple-bind","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwillcrichton%2Fsimple-bind/lists"}