{"id":20248227,"url":"https://github.com/rodrigocfd/defer-lite","last_synced_at":"2025-04-10T22:22:29.934Z","repository":{"id":57617266,"uuid":"394491284","full_name":"rodrigocfd/defer-lite","owner":"rodrigocfd","description":"A lightweight high-performance implementation of Go's defer statement.","archived":false,"fork":false,"pushed_at":"2021-08-10T01:58:44.000Z","size":4,"stargazers_count":23,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-24T19:21:42.752Z","etag":null,"topics":["defer","rust"],"latest_commit_sha":null,"homepage":"https://crates.io/crates/defer-lite","language":"Rust","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/rodrigocfd.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}},"created_at":"2021-08-10T01:33:37.000Z","updated_at":"2025-02-09T04:44:30.000Z","dependencies_parsed_at":"2022-08-29T05:32:01.763Z","dependency_job_id":null,"html_url":"https://github.com/rodrigocfd/defer-lite","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rodrigocfd%2Fdefer-lite","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rodrigocfd%2Fdefer-lite/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rodrigocfd%2Fdefer-lite/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rodrigocfd%2Fdefer-lite/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rodrigocfd","download_url":"https://codeload.github.com/rodrigocfd/defer-lite/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248148246,"owners_count":21055548,"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":["defer","rust"],"created_at":"2024-11-14T09:47:13.484Z","updated_at":"2025-04-10T22:22:29.913Z","avatar_url":"https://github.com/rodrigocfd.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# defer-lite\r\n\r\n[![Crates.io](https://img.shields.io/crates/v/defer-lite.svg)](https://crates.io/crates/defer-lite)\r\n[![Docs.rs](https://docs.rs/defer-lite/badge.svg)](https://docs.rs/defer-lite)\r\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\r\n\r\nA Rust implementation of [Go's `defer` statement](https://tour.golang.org/flowcontrol/12) as the `defer!` macro, which executes a block of code when the surrounding scope ends.\r\n\r\nThis crate focuses on providing a lightweight, high-performance, `no_std` implementation of the `defer!` macro.\r\n\r\n## Usage\r\n\r\nAdd the dependency in your `Cargo.toml`:\r\n\r\n```toml\r\n[dependencies]\r\ndefer-lite = \"1.0.0\"\r\n```\r\n\r\n## Examples\r\n\r\nSimplest example:\r\n\r\n```rust\r\nuse defer_lite::defer; // import the defer! macro\r\n\r\nfn main() {\r\n    defer! { println!(\"Second\"); }\r\n    println!(\"First\");\r\n}\r\n```\r\n\r\nMultiple statements:\r\n\r\n```rust\r\nuse defer_lite::defer;\r\n\r\nfn main() {\r\n    defer! {\r\n        println!(\"Second\");\r\n        println!(\"Third\");\r\n    }\r\n    println!(\"First\");\r\n}\r\n```\r\n\r\nIn Go, the `defer` code runs when the function exits. In this Rust implementation, the code runs when the surrounding scope ends – this makes it possible to use `defer` inside loops:\r\n\r\n```rust\r\nuse defer_lite::defer;\r\n\r\nfn main() {\r\n    defer! { println!(\"End\"); }\r\n    println!(\"Before\");\r\n\r\n    for i in 0..2 {\r\n        defer! { println!(\"Defer {}\", i); }\r\n        println!(\"Loop {}\", i);\r\n    }\r\n\r\n    println!(\"After\");\r\n}\r\n```\r\n\r\n## License\r\n\r\nLicensed under [MIT license](https://opensource.org/licenses/MIT), see [LICENSE.md](LICENSE.md) for details.\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frodrigocfd%2Fdefer-lite","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frodrigocfd%2Fdefer-lite","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frodrigocfd%2Fdefer-lite/lists"}