smol-macros-0.1.1/.cargo_vcs_info.json0000644000000001360000000000100132670ustar { "git": { "sha1": "fd0ef52dac0cbbb8bfae7af4ed9879493f13e0b2" }, "path_in_vcs": "" }smol-macros-0.1.1/CHANGELOG.md000064400000000000000000000001351046102023000136670ustar 00000000000000# Version 0.1.1 - Bump `event-listener` to v5.1.0. (#3) # Version 0.1.0 - Initial release smol-macros-0.1.1/Cargo.lock0000644000000240650000000000100112510ustar # This file is automatically @generated by Cargo. # It is not intended for manual editing. version = 3 [[package]] name = "async-executor" version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4b0c4a4f319e45986f347ee47fef8bf5e81c9abc3f6f58dc2391439f30df65f0" dependencies = [ "async-lock 2.8.0", "async-task", "concurrent-queue", "fastrand", "futures-lite 1.13.0", "slab", ] [[package]] name = "async-io" version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "41ed9d5715c2d329bf1b4da8d60455b99b187f27ba726df2883799af9af60997" dependencies = [ "async-lock 3.1.2", "cfg-if", "concurrent-queue", "futures-io", "futures-lite 2.0.1", "parking", "polling", "rustix", "slab", "tracing", "waker-fn", "windows-sys", ] [[package]] name = "async-lock" version = "2.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "287272293e9d8c41773cec55e365490fe034813a2f172f502d6ddcf75b2f582b" dependencies = [ "event-listener 2.5.3", ] [[package]] name = "async-lock" version = "3.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dea8b3453dd7cc96711834b75400d671b73e3656975fa68d9f277163b7f7e316" dependencies = [ "event-listener 4.0.0", "event-listener-strategy", "pin-project-lite", ] [[package]] name = "async-task" version = "4.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b4eb2cdb97421e01129ccb49169d8279ed21e829929144f4a22a6e54ac549ca1" [[package]] name = "autocfg" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "bitflags" version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" [[package]] name = "cfg-if" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "concurrent-queue" version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f057a694a54f12365049b0958a1685bb52d567f5593b355fbf685838e873d400" dependencies = [ "crossbeam-utils", ] [[package]] name = "crossbeam-utils" version = "0.8.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5a22b2d63d4d1dc0b7f1b6b2747dd0088008a9be28b6ddf0b1e7d335e3037294" dependencies = [ "cfg-if", ] [[package]] name = "errno" version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f258a7194e7f7c2a7837a8913aeab7fd8c383457034fa20ce4dd3dcb813e8eb8" dependencies = [ "libc", "windows-sys", ] [[package]] name = "event-listener" version = "2.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0206175f82b8d6bf6652ff7d71a1e27fd2e4efde587fd368662814d6ec1d9ce0" [[package]] name = "event-listener" version = "4.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "770d968249b5d99410d61f5bf89057f3199a077a04d087092f58e7d10692baae" dependencies = [ "concurrent-queue", "parking", "pin-project-lite", ] [[package]] name = "event-listener" version = "5.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b7ad6fd685ce13acd6d9541a30f6db6567a7a24c9ffd4ba2955d29e3f22c8b27" dependencies = [ "concurrent-queue", "parking", "pin-project-lite", ] [[package]] name = "event-listener-strategy" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "958e4d70b6d5e81971bebec42271ec641e7ff4e170a6fa605f2b8a8b65cb97d3" dependencies = [ "event-listener 4.0.0", "pin-project-lite", ] [[package]] name = "fastrand" version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "25cbce373ec4653f1a01a31e8a5e5ec0c622dc27ff9c4e6606eefef5cbbed4a5" [[package]] name = "futures-core" version = "0.3.29" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eb1d22c66e66d9d72e1758f0bd7d4fd0bee04cad842ee34587d68c07e45d088c" [[package]] name = "futures-io" version = "0.3.29" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8bf34a163b5c4c52d0478a4d757da8fb65cabef42ba90515efee0f6f9fa45aaa" [[package]] name = "futures-lite" version = "1.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49a9d51ce47660b1e808d3c990b4709f2f415d928835a17dfd16991515c46bce" dependencies = [ "futures-core", "pin-project-lite", ] [[package]] name = "futures-lite" version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d3831c2651acb5177cbd83943f3d9c8912c5ad03c76afcc0e9511ba568ec5ebb" dependencies = [ "futures-core", "pin-project-lite", ] [[package]] name = "libc" version = "0.2.150" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "89d92a4743f9a61002fae18374ed11e7973f530cb3a3255fb354818118b2203c" [[package]] name = "linux-raw-sys" version = "0.4.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "969488b55f8ac402214f3f5fd243ebb7206cf82de60d3172994707a4bcc2b829" [[package]] name = "macro_rules_attribute" version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8a82271f7bc033d84bbca59a3ce3e4159938cb08a9c3aebbe54d215131518a13" dependencies = [ "macro_rules_attribute-proc_macro", "paste", ] [[package]] name = "macro_rules_attribute-proc_macro" version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b8dd856d451cc0da70e2ef2ce95a18e39a93b7558bedf10201ad28503f918568" [[package]] name = "parking" version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bb813b8af86854136c6922af0598d719255ecb2179515e6e7730d468f05c9cae" [[package]] name = "paste" version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c" [[package]] name = "pin-project-lite" version = "0.2.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8afb450f006bf6385ca15ef45d71d2288452bc3683ce2e2cacc0d18e4be60b58" [[package]] name = "polling" version = "3.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e53b6af1f60f36f8c2ac2aad5459d75a5a9b4be1e8cdd40264f315d78193e531" dependencies = [ "cfg-if", "concurrent-queue", "pin-project-lite", "rustix", "tracing", "windows-sys", ] [[package]] name = "rustix" version = "0.38.24" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ad981d6c340a49cdc40a1028d9c6084ec7e9fa33fcb839cab656a267071e234" dependencies = [ "bitflags", "errno", "libc", "linux-raw-sys", "windows-sys", ] [[package]] name = "slab" version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" dependencies = [ "autocfg", ] [[package]] name = "smol-macros" version = "0.1.1" dependencies = [ "async-executor", "async-io", "async-lock 3.1.2", "event-listener 5.1.0", "futures-lite 2.0.1", "macro_rules_attribute", "unsend", ] [[package]] name = "tracing" version = "0.1.40" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" dependencies = [ "pin-project-lite", "tracing-core", ] [[package]] name = "tracing-core" version = "0.1.32" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" [[package]] name = "unsend" version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a53ed0f41cab22aa8d4aee9d2357a1b21cb365537d7349066c76fcd67bc3121d" dependencies = [ "pin-project-lite", ] [[package]] name = "waker-fn" version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f3c4517f54858c779bbcbf228f4fca63d121bf85fbecb2dc578cdf4a39395690" [[package]] name = "windows-sys" version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" dependencies = [ "windows-targets", ] [[package]] name = "windows-targets" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" dependencies = [ "windows_aarch64_gnullvm", "windows_aarch64_msvc", "windows_i686_gnu", "windows_i686_msvc", "windows_x86_64_gnu", "windows_x86_64_gnullvm", "windows_x86_64_msvc", ] [[package]] name = "windows_aarch64_gnullvm" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" [[package]] name = "windows_aarch64_msvc" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" [[package]] name = "windows_i686_gnu" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" [[package]] name = "windows_i686_msvc" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" [[package]] name = "windows_x86_64_gnu" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" [[package]] name = "windows_x86_64_gnullvm" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" [[package]] name = "windows_x86_64_msvc" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" smol-macros-0.1.1/Cargo.toml0000644000000025620000000000100112720ustar # THIS FILE IS AUTOMATICALLY GENERATED BY CARGO # # When uploading crates to the registry Cargo will automatically # "normalize" Cargo.toml files for maximal compatibility # with all versions of Cargo and also rewrite `path` dependencies # to registry (e.g., crates.io) dependencies. # # If you are reading this file be aware that the original Cargo.toml # will likely look very different (and much more reasonable). # See Cargo.toml.orig for the original contents. [package] edition = "2021" rust-version = "1.63" name = "smol-macros" version = "0.1.1" authors = ["John Nunley "] exclude = ["/.*"] description = "Macros for setting up a smol runtime" readme = "README.md" keywords = [ "async", "await", "future", "io", "macro", ] categories = [ "asynchronous", "concurrency", "network-programming", ] license = "Apache-2.0 OR MIT" repository = "https://github.com/smol-rs/smol-macros" [dependencies.async-executor] version = "1.6.0" [dependencies.async-io] version = "2.2.0" [dependencies.async-lock] version = "3.1.2" [dependencies.event-listener] version = "5.1.0" [dependencies.futures-lite] version = "2.0.1" default-features = false [dev-dependencies.async-lock] version = "3.1.2" [dev-dependencies.macro_rules_attribute] version = "0.2.0" [dev-dependencies.unsend] version = "0.2.1" features = ["alloc"] default-features = false smol-macros-0.1.1/Cargo.toml.orig000064400000000000000000000013331046102023000147460ustar 00000000000000[package] name = "smol-macros" version = "0.1.1" edition = "2021" rust-version = "1.63" authors = ["John Nunley "] description = "Macros for setting up a smol runtime" license = "Apache-2.0 OR MIT" repository = "https://github.com/smol-rs/smol-macros" keywords = ["async", "await", "future", "io", "macro"] categories = ["asynchronous", "concurrency", "network-programming"] exclude = ["/.*"] [dependencies] async-executor = "1.6.0" async-io = "2.2.0" async-lock = "3.1.2" event-listener = "5.1.0" futures-lite = { version = "2.0.1", default-features = false } [dev-dependencies] async-lock = "3.1.2" macro_rules_attribute = "0.2.0" unsend = { version = "0.2.1", default-features = false, features = ["alloc"] } smol-macros-0.1.1/LICENSE-APACHE000064400000000000000000000251371046102023000140130ustar 00000000000000 Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. smol-macros-0.1.1/LICENSE-MIT000064400000000000000000000017771046102023000135270ustar 00000000000000Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. smol-macros-0.1.1/README.md000064400000000000000000000072011046102023000133360ustar 00000000000000# smol-macros [![Build](https://github.com/smol-rs/smol-macros/actions/workflows/ci.yml/badge.svg)]( https://github.com/smol-rs/smol-macros/actions) [![License](https://img.shields.io/badge/license-Apache--2.0_OR_MIT-blue.svg)]( https://github.com/smol-rs/smol-macros) [![Cargo](https://img.shields.io/crates/v/smol-macros.svg)]( https://crates.io/crates/smol-macros) [![Documentation](https://docs.rs/smol-macros/badge.svg)]( https://docs.rs/smol-macros) Macros for using `smol-rs`. One of the advantages of [`smol`] is that it lets you set up your own executor, optimized for your own use cases. However, quick scaffolding is important for many organizational use cases. Especially when sane defaults are appreciated, setting up your own executor is a waste of time. This crate provides macros for setting up an efficient [`smol`] runtime quickly and effectively. It provides sane defaults that are useful for most applications. ## Simple Executor Just have an `async` main function, using the [`main`] macro. ```rust use smol_macros::main; main! { async fn main() { println!("Hello, world!"); } } ``` This crate uses declarative macros rather than procedural macros, in order to avoid needing to use heavy macro dependencies. If you want to use the proc macro syntax, you can use the [`macro_rules_attribute::apply`] function to emulate it. The following is equivalent to the previous example. ```rust use macro_rules_attribute::apply; use smol_macros::main; #[apply(main!)] async fn main() { println!("Hello, world!"); } ``` ## Task-Based Executor This crate re-exports [`smol::Executor`]. If that is used as the first parameter in a function in [`main`], it will automatically create the executor. ```rust use macro_rules_attribute::apply; use smol_macros::{main, Executor}; #[apply(main!)] async fn main(ex: &Executor<'_>) { ex.spawn(async { println!("Hello world!"); }).await; } ``` If the thread-safe [`smol::Executor`] is used here, a thread pool will be spawned to run the executor on multiple threads. For the thread-unsafe [`smol::LocalExecutor`], no threads will be spawned. See documentation for the [`main`] function for more details. ## Tests Use the [`test`] macro to set up test cases that run self-contained executors. ```rust use macro_rules_attribute::apply; use smol_macros::{test, Executor}; #[apply(test!)] async fn do_test(ex: &Executor<'_>) { ex.spawn(async { assert_eq!(1 + 1, 2); }).await; } ``` [`smol`]: https://crates.io/crates/smol [`smol::Executor`]: https://docs.rs/smol/latest/smol/struct.Executor.html [`smol::LocalExecutor`]: https://docs.rs/smol/latest/smol/struct.LocalExecutor.html [`macro_rules_attribute::apply`]: https://docs.rs/macro_rules_attribute/latest/macro_rules_attribute/attr.apply.html ## MSRV Policy The Minimum Supported Rust Version (MSRV) of this crate is **1.63**. As a **tentative** policy, the MSRV will not advance past the [current Rust version provided by Debian Stable](https://packages.debian.org/stable/rust/rustc). At the time of writing, this version of Rust is *1.63*. However, the MSRV may be advanced further in the event of a major ecosystem shift or a security vulnerability. ## License Licensed under either of * Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) at your option. #### Contribution Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions. smol-macros-0.1.1/examples/local_executor.rs000064400000000000000000000010141046102023000172470ustar 00000000000000//! Set up a thread executor that is local. use macro_rules_attribute::apply; use smol_macros::{main, LocalExecutor}; use std::time::Duration; #[apply(main!)] async fn main(ex: &LocalExecutor<'_>) { let mut tasks = vec![]; for i in 0..16 { let task = ex.spawn(async move { println!("Task number {i}"); }); tasks.push(task); } async_io::Timer::after(Duration::from_secs(1)).await; // Wait for tasks to complete. for task in tasks { task.await; } } smol-macros-0.1.1/examples/main_as_attr.rs000064400000000000000000000003001046102023000166750ustar 00000000000000//! Use the `macro_rules_attribute` to use `main` as an attribute. use macro_rules_attribute::apply; use smol_macros::main; #[apply(main!)] async fn main() { println!("hello world!"); } smol-macros-0.1.1/examples/main_macro.rs000064400000000000000000000002101046102023000163410ustar 00000000000000//! Example of using the `main` macro. use smol_macros::main; main! { async fn main() { println!("hello world!"); } } smol-macros-0.1.1/examples/thread_executor.rs000064400000000000000000000010041046102023000174230ustar 00000000000000//! Set up a thread executor. use smol_macros::{main, Executor}; use std::time::Duration; main! { async fn main(ex: &Executor<'_>) { let mut tasks = vec![]; for i in 0..16 { let task = ex.spawn(async move { println!("Task number {i}"); }); tasks.push(task); } async_io::Timer::after(Duration::from_secs(1)).await; // Wait for tasks to complete. for task in tasks { task.await; } } } smol-macros-0.1.1/examples/thread_executor_arc.rs000064400000000000000000000010341046102023000202530ustar 00000000000000//! Set up a thread executor. use smol_macros::{main, Executor}; use std::sync::Arc; use std::time::Duration; main! { async fn main(ex: Arc>) { let mut tasks = vec![]; for i in 0..16 { let task = ex.spawn(async move { println!("Task number {i}"); }); tasks.push(task); } async_io::Timer::after(Duration::from_secs(1)).await; // Wait for tasks to complete. for task in tasks { task.await; } } } smol-macros-0.1.1/src/lib.rs000064400000000000000000000226211046102023000137650ustar 00000000000000//! Macros for using `smol-rs`. //! //! One of the advantages of [`smol`] is that it lets you set up your own executor, optimized for //! your own use cases. However, quick scaffolding is important for many organizational use cases. //! Especially when sane defaults are appreciated, setting up your own executor is a waste of //! time. //! //! This crate provides macros for setting up an efficient [`smol`] runtime quickly and //! effectively. It provides sane defaults that are useful for most applications. //! //! ## Simple Executor //! //! Just have an `async` main function, using the [`main`] macro. //! //! //! ``` //! use smol_macros::main; //! //! main! { //! async fn main() { //! println!("Hello, world!"); //! } //! } //! ``` //! //! This crate uses declarative macros rather than procedural macros, in order to avoid needing //! to use heavy macro dependencies. If you want to use the proc macro syntax, you can use the //! [`macro_rules_attribute::apply`] function to emulate it. //! //! The following is equivalent to the previous example. //! //! ``` //! use macro_rules_attribute::apply; //! use smol_macros::main; //! //! #[apply(main!)] //! async fn main() { //! println!("Hello, world!"); //! } //! ``` //! //! ## Task-Based Executor //! //! This crate re-exports [`smol::Executor`]. If that is used as the first parameter in a //! function in [`main`], it will automatically create the executor. //! //! ``` //! use macro_rules_attribute::apply; //! use smol_macros::{main, Executor}; //! //! #[apply(main!)] //! async fn main(ex: &Executor<'_>) { //! ex.spawn(async { println!("Hello world!"); }).await; //! } //! ``` //! //! If the thread-safe [`smol::Executor`] is used here, a thread pool will be spawned to run //! the executor on multiple threads. For the thread-unsafe [`smol::LocalExecutor`], no threads //! will be spawned. //! //! See documentation for the [`main`] function for more details. //! //! ## Tests //! //! Use the [`test`] macro to set up test cases that run self-contained executors. //! //! ``` //! use macro_rules_attribute::apply; //! use smol_macros::{test, Executor}; //! //! #[apply(test!)] //! async fn do_test(ex: &Executor<'_>) { //! ex.spawn(async { //! assert_eq!(1 + 1, 2); //! }).await; //! } //! ``` //! //! [`smol`]: https://crates.io/crates/smol //! [`smol::Executor`]: https://docs.rs/smol/latest/smol/struct.Executor.html //! [`smol::LocalExecutor`]: https://docs.rs/smol/latest/smol/struct.LocalExecutor.html //! [`macro_rules_attribute::apply`]: https://docs.rs/macro_rules_attribute/latest/macro_rules_attribute/attr.apply.html #![forbid(unsafe_code)] #[doc(no_inline)] pub use async_executor::{Executor, LocalExecutor}; /// Turn a main function into one that runs inside of a self-contained executor. /// /// The function created by this macro spawns an executor, spawns threads to run that executor /// on (if applicable), and then blocks the current thread on the future. /// /// ## Examples /// /// Like [`tokio::main`], this function is not limited to wrapping the program's entry point. /// In a mostly synchronous program, it can wrap a self-contained `async` function in its /// own executor. /// /// ``` /// use macro_rules_attribute::apply; /// use smol_macros::{main, Executor}; /// /// fn do_something_sync() -> u32 { /// 1 + 1 /// } /// /// #[apply(main!)] /// async fn do_something_async(ex: &Executor<'_>) -> u32 { /// ex.spawn(async { 1 + 1 }).await /// } /// /// fn main() { /// let x = do_something_sync(); /// let y = do_something_async(); /// assert_eq!(x + y, 4); /// } /// ``` /// /// The first parameter to the `main` function can be an executor. It can be one of the following: /// /// - Nothing. /// - `&`[`Executor`] /// - `&`[`LocalExecutor`] /// - `Arc<`[`Executor`]`>` /// - `Rc<`[`LocalExecutor`]`>` /// /// [`tokio::main`]: https://docs.rs/tokio/latest/tokio/attr.main.html /// [`Executor`]: https://docs.rs/smol/latest/smol/struct.Executor.html /// [`LocalExecutor`]: https://docs.rs/smol/latest/smol/struct.LocalExecutor.html #[macro_export] macro_rules! main { ( $(#[$attr:meta])* async fn $name:ident () $(-> $ret:ty)? $bl:block ) => { $(#[$attr])* fn $name () $(-> $ret)? { $crate::__private::block_on(async { $bl }) } }; ( $(#[$post_attr:meta])* async fn $name:ident ($ex:ident : & $exty:ty) $(-> $ret:ty)? $bl:block ) => { $(#[$post_attr])* fn $name () $(-> $ret)? { <$exty as $crate::__private::MainExecutor>::with_main(|ex| { $crate::__private::block_on(ex.run(async move { let $ex = ex; $bl })) }) } }; ( $(#[$post_attr:meta])* async fn $name:ident ($ex:ident : $exty:ty) $(-> $ret:ty)? $bl:block ) => { $crate::main! { $(#[$post_attr])* async fn $name(ex: &$exty) $(-> $ret)? { let $ex = ex.clone(); $bl } } } } /// Wrap a test in an asynchronous executor. /// /// This is equivalent to the [`main`] macro, but adds the `#[test]` attribute. /// /// ## Examples /// /// ``` /// use macro_rules_attribute::apply; /// use smol_macros::test; /// /// #[apply(test!)] /// async fn do_test() { /// assert_eq!(1 + 1, 2); /// } /// ``` #[macro_export] macro_rules! test { // Special case to get around bug in macro engine. ( $(#[$post_attr:meta])* async fn $name:ident ($exname:ident : & $exty:ty) $(-> $ret:ty)? $bl:block ) => { $crate::main! { $(#[$post_attr])* #[core::prelude::v1::test] async fn $name($exname: &$exty) $(-> $ret)? $bl } }; ( $(#[$post_attr:meta])* async fn $name:ident ($($pname:ident : $pty:ty),* $(,)?) $(-> $ret:ty)? $bl:block ) => { $crate::main! { $(#[$post_attr])* #[core::prelude::v1::test] async fn $name($($pname: $pty),*) $(-> $ret)? $bl } }; } #[doc(hidden)] pub mod __private { pub use async_io::block_on; pub use std::rc::Rc; use crate::{Executor, LocalExecutor}; use event_listener::Event; use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::Arc; use std::thread; /// Something that can be set up as an executor. #[doc(hidden)] pub trait MainExecutor: Sized { /// Create this type and pass it into `main`. fn with_main T>(f: F) -> T; } impl MainExecutor for Arc> { #[inline] fn with_main T>(f: F) -> T { let ex = Arc::new(Executor::new()); with_thread_pool(&ex, || f(&ex)) } } impl MainExecutor for Executor<'_> { #[inline] fn with_main T>(f: F) -> T { let ex = Executor::new(); with_thread_pool(&ex, || f(&ex)) } } impl MainExecutor for Rc> { #[inline] fn with_main T>(f: F) -> T { f(&Rc::new(LocalExecutor::new())) } } impl MainExecutor for LocalExecutor<'_> { fn with_main T>(f: F) -> T { f(&LocalExecutor::new()) } } /// Run a function that takes an `Executor` inside of a thread pool. #[inline] fn with_thread_pool(ex: &Executor<'_>, f: impl FnOnce() -> T) -> T { let stopper = WaitForStop::new(); // Create a thread for each CPU. thread::scope(|scope| { let num_threads = thread::available_parallelism().map_or(1, |num| num.get()); for i in 0..num_threads { let ex = &ex; let stopper = &stopper; thread::Builder::new() .name(format!("smol-macros-{i}")) .spawn_scoped(scope, || { block_on(ex.run(stopper.wait())); }) .expect("failed to spawn thread"); } let result = std::panic::catch_unwind(std::panic::AssertUnwindSafe(f)); stopper.stop(); match result { Ok(value) => value, Err(err) => std::panic::resume_unwind(err), } }) } /// Wait for the executor to stop. struct WaitForStop { /// Whether or not we need to stop. stopped: AtomicBool, /// Wait for the stop. events: Event, } impl WaitForStop { /// Create a new wait for stop. #[inline] fn new() -> Self { Self { stopped: AtomicBool::new(false), events: Event::new(), } } /// Wait for the event to stop. #[inline] async fn wait(&self) { loop { if self.stopped.load(Ordering::Relaxed) { return; } event_listener::listener!(&self.events => listener); if self.stopped.load(Ordering::Acquire) { return; } listener.await; } } /// Stop the waiter. #[inline] fn stop(&self) { self.stopped.store(true, Ordering::SeqCst); self.events.notify_additional(std::usize::MAX); } } } smol-macros-0.1.1/tests/macro_usages.rs000064400000000000000000000056741046102023000162530ustar 00000000000000//! Testing the test macros. use async_lock::Barrier; use futures_lite::prelude::*; use macro_rules_attribute::apply; use smol_macros::{test, Executor, LocalExecutor}; use std::rc::Rc; use std::sync::Arc; use std::time::Duration; test! { async fn basic_test() { println!("test 1"); } } #[apply(test!)] async fn with_attribute() { println!("test 2"); } #[apply(test!)] async fn with_executor(ex: &Executor<'static>) { let barrier = Arc::new(Barrier::new(2)); ex.spawn({ let barrier = barrier.clone(); async move { barrier.wait().await; } }) .detach(); barrier .wait() .or(async { async_io::Timer::after(Duration::from_secs(5)).await; panic!("timed out") }) .await; } #[apply(test!)] async fn with_executor_arc(ex: Arc>) { let barrier = Arc::new(Barrier::new(2)); ex.spawn({ let barrier = barrier.clone(); async move { barrier.wait().await; } }) .detach(); barrier .wait() .or(async { async_io::Timer::after(Duration::from_secs(5)).await; panic!("timed out") }) .await; } #[apply(test!)] async fn with_executor_arcref(ex: &Arc>) { let barrier = Arc::new(Barrier::new(2)); ex.spawn({ let barrier = barrier.clone(); async move { barrier.wait().await; } }) .detach(); barrier .wait() .or(async { async_io::Timer::after(Duration::from_secs(5)).await; panic!("timed out") }) .await; } #[apply(test!)] async fn with_local(ex: &LocalExecutor<'_>) { let barrier = Rc::new(unsend::lock::Barrier::new(2)); ex.spawn({ let barrier = barrier.clone(); async move { barrier.wait().await; } }) .detach(); barrier .wait() .or(async { async_io::Timer::after(Duration::from_secs(5)).await; panic!("timed out") }) .await; } #[apply(test!)] async fn with_local_rc(ex: Rc>) { let barrier = Rc::new(unsend::lock::Barrier::new(2)); ex.spawn({ let barrier = barrier.clone(); async move { barrier.wait().await; } }) .detach(); barrier .wait() .or(async { async_io::Timer::after(Duration::from_secs(5)).await; panic!("timed out") }) .await; } #[apply(test!)] async fn with_local_rcref(ex: &Rc>) { let barrier = Rc::new(unsend::lock::Barrier::new(2)); ex.spawn({ let barrier = barrier.clone(); async move { barrier.wait().await; } }) .detach(); barrier .wait() .or(async { async_io::Timer::after(Duration::from_secs(5)).await; panic!("timed out") }) .await; }