From b8f71d206574dcaf23adc39f04355aa8c2e370ed Mon Sep 17 00:00:00 2001 From: FL03 Date: Thu, 28 Aug 2025 15:40:36 -0500 Subject: [PATCH 1/6] v0.2.2 Signed-off-by: FL03 --- Cargo.lock | 8 ++++---- Cargo.toml | 10 +++++----- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e42d19d..0d9b270 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -101,7 +101,7 @@ checksum = "b94f61472cee1439c0b966b47e3aca9ae07e45d070759512cd390ea2bebc6675" [[package]] name = "contained" -version = "0.2.1" +version = "0.2.2" dependencies = [ "contained-core", "contained-derive", @@ -111,7 +111,7 @@ dependencies = [ [[package]] name = "contained-core" -version = "0.2.1" +version = "0.2.2" dependencies = [ "paste", "serde", @@ -123,7 +123,7 @@ dependencies = [ [[package]] name = "contained-derive" -version = "0.2.1" +version = "0.2.2" dependencies = [ "proc-macro2", "quote", @@ -132,7 +132,7 @@ dependencies = [ [[package]] name = "contained-macros" -version = "0.2.1" +version = "0.2.2" dependencies = [ "proc-macro2", "quote", diff --git a/Cargo.toml b/Cargo.toml index 06c9d86..7b42465 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,13 +21,13 @@ license = "Apache-2.0" readme = "README.md" repository = "https://github.com/FL03/contained.git" rust-version = "1.85.0" -version = "0.2.1" +version = "0.2.2" [workspace.dependencies] -contained = { default-features = false, path = "contained", version = "0.2.1" } -contained-core = { default-features = false, path = "core", version = "0.2.1" } -contained-derive = { default-features = false, path = "derive", version = "0.2.1" } -contained-macros = { default-features = false, path = "macros", version = "0.2.1" } +contained = { default-features = false, path = "contained", version = "0.2.2" } +contained-core = { default-features = false, path = "core", version = "0.2.2" } +contained-derive = { default-features = false, path = "derive", version = "0.2.2" } +contained-macros = { default-features = false, path = "macros", version = "0.2.2" } # error handling anyhow = { default-features = false, version = "1" } From 3a3ccc46865cdeff0b2cd684bffb014bd29d0a2c Mon Sep 17 00:00:00 2001 From: FL03 Date: Thu, 28 Aug 2025 15:50:26 -0500 Subject: [PATCH 2/6] update Signed-off-by: FL03 --- contained/examples/macros.rs | 99 ++++++++++++++++++------------------ core/Cargo.toml | 7 ++- 2 files changed, 55 insertions(+), 51 deletions(-) diff --git a/contained/examples/macros.rs b/contained/examples/macros.rs index d0a5b81..05e7785 100644 --- a/contained/examples/macros.rs +++ b/contained/examples/macros.rs @@ -1,50 +1,49 @@ -/* - appellation: macros - authors: @FL03 -*/ -use contained::fmt_wrapper; - -fn main() -> contained::Result<()> { - - let a = A(255); - let b = B { value: 255 }; - println!("A: {a:?}, B: {b:?}"); - assert_eq!(format!("{:x}", a), format!("{:x}", b)); - Ok(()) -} - -#[derive(Clone, Copy, Eq, Hash, PartialEq, PartialOrd)] -pub struct A(T); - -#[derive(Clone, Copy, Eq, Hash, PartialEq, PartialOrd)] -pub struct B { - pub value: T, -} - -fmt_wrapper! { - impl A { - Debug, - Display, - LowerHex, - UpperHex, - LowerExp, - UpperExp, - Binary, - Octal, - Pointer, - } -} - -fmt_wrapper! { - impl B.value { - Debug, - Display, - LowerHex, - UpperHex, - LowerExp, - UpperExp, - Binary, - Octal, - Pointer, - } -} +/* + appellation: macros + authors: @FL03 +*/ +use contained::fmt_wrapper; + +fn main() -> contained::Result<()> { + let a = A(255); + let b = B { value: 255 }; + println!("A: {a:?}, B: {b:?}"); + assert_eq!(format!("{:x}", a), format!("{:x}", b)); + Ok(()) +} + +#[derive(Clone, Copy, Eq, Hash, PartialEq, PartialOrd)] +pub struct A(T); + +#[derive(Clone, Copy, Eq, Hash, PartialEq, PartialOrd)] +pub struct B { + pub value: T, +} + +fmt_wrapper! { + impl A { + Debug, + Display, + LowerHex, + UpperHex, + LowerExp, + UpperExp, + Binary, + Octal, + Pointer, + } +} + +fmt_wrapper! { + impl B.value { + Debug, + Display, + LowerHex, + UpperHex, + LowerExp, + UpperExp, + Binary, + Octal, + Pointer, + } +} diff --git a/core/Cargo.toml b/core/Cargo.toml index d444de8..b3b8b68 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -20,11 +20,13 @@ bench = false doctest = true test = true +# ********* Package Metadata ********* [package.metadata.docs.rs] all-features = false features = ["full"] rustc-args = ["--cfg", "docsrs"] +# ********* Unit Tests ********* [[test]] name = "default" @@ -43,13 +45,16 @@ serde_json = { optional = true, workspace = true } # WebAssembly wasm-bindgen = { optional = true, workspace = true } +# ********* Feature Flags ********* [features] default = [ "std" ] full = [ - "default" + "default", + "json", + "serde", ] # ********* [FF] Features ********* From 58172d0a9afcfdfa5720b5c0024a81b2e92e52dc Mon Sep 17 00:00:00 2001 From: FL03 Date: Mon, 8 Sep 2025 20:55:29 -0500 Subject: [PATCH 3/6] update Signed-off-by: FL03 --- .artifacts/docs/QUICKSTART.md | 3 - .artifacts/license/APACHE.LICENSE | 201 ---------------------- .artifacts/license/MIT.LICENSE | 21 --- .envrc | 1 + CONTRIBUTING.md | 40 +++++ Cargo.lock | 118 +++---------- Cargo.toml | 1 - core/Cargo.toml | 4 - core/src/error.rs | 92 +++++----- core/src/lib.rs | 2 - core/src/macros/wrapper_ops.rs | 110 ------------ core/tests/macros.rs | 33 ---- derive/Cargo.toml | 4 +- flake.nix | 67 +++++--- macros/Cargo.toml | 6 +- macros/src/impl_binary.rs | 268 +++++++++++++++++++---------- macros/src/impl_unary.rs | 112 ++++++++++++ macros/src/lib.rs | 138 +++++++++++---- macros/tests/{binary.rs => ops.rs} | 24 ++- shell.nix | 10 ++ 20 files changed, 594 insertions(+), 661 deletions(-) delete mode 100644 .artifacts/docs/QUICKSTART.md delete mode 100644 .artifacts/license/APACHE.LICENSE delete mode 100644 .artifacts/license/MIT.LICENSE create mode 100644 .envrc delete mode 100644 core/src/macros/wrapper_ops.rs delete mode 100644 core/tests/macros.rs create mode 100644 macros/src/impl_unary.rs rename macros/tests/{binary.rs => ops.rs} (70%) create mode 100644 shell.nix diff --git a/.artifacts/docs/QUICKSTART.md b/.artifacts/docs/QUICKSTART.md deleted file mode 100644 index 9061985..0000000 --- a/.artifacts/docs/QUICKSTART.md +++ /dev/null @@ -1,3 +0,0 @@ -# Quickstart - -## Getting Started diff --git a/.artifacts/license/APACHE.LICENSE b/.artifacts/license/APACHE.LICENSE deleted file mode 100644 index f25b2b1..0000000 --- a/.artifacts/license/APACHE.LICENSE +++ /dev/null @@ -1,201 +0,0 @@ - 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 2023 Joe McCain III - - 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. diff --git a/.artifacts/license/MIT.LICENSE b/.artifacts/license/MIT.LICENSE deleted file mode 100644 index 4cea9a3..0000000 --- a/.artifacts/license/MIT.LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -The MIT License (MIT) - -Copyright (c) 2023 Joe McCain III - -Permission 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. diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..8392d15 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake \ No newline at end of file diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index e69de29..065ddc3 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -0,0 +1,40 @@ +# Contributing + +We welcome contributions to Eryon! Whether you're fixing bugs, adding new features, or improving documentation, your help is appreciated. That being said, we implore all of our contributors to adhere to a standard of quality and professionalism. Please follow the guidelines below to ensure a smooth contribution process. + +## Code of Conduct + +By participating in this project, you agree to abide by our [Code of Conduct](CODE_OF_CONDUCT.md). We are committed to providing a welcoming and inclusive environment for all contributors. + +## How to Contribute + +**Note**: Every contribution should have a corresponding feature request or, for larger changes, a dedicated proposal detailing the intended changes and their rationale. This helps maintain clarity and ensures that all contributions align with the project's goals. + +1. **Fork the Repository**: Start by forking the Eryon repository to your own GitHub account. +2. **Clone Your Fork**: Clone your forked repository to your local machine. +3. **Create a Branch**: Create a new branch for your feature or bug fix. Use a descriptive name for your branch. +4. **Make Changes**: Implement your changes in the new branch. Ensure your code adheres to the project's coding standards. +5. **Test Your Changes**: Thoroughly test your changes to ensure they work as expected +6. **Commit Your Changes**: Commit your changes with clear and concise commit messages. +7. **Push to Your Fork**: Push your changes to your forked repository on Git +8. **Open a Pull Request**: Navigate to the original Eryon repository and open a pull request from your forked repository. Provide a detailed description of your changes and the problem they solve. +9. **Address Feedback**: Be responsive to any feedback or requests for changes from the project maintainers. + +## Coding Standards + +- Follow the existing coding style and conventions used in the project. +- Write clear, concise, and well-documented code. +- Ensure your code is efficient and avoids unnecessary complexity. +- Include unit tests for new features or bug fixes. +- Ensure all tests pass before submitting your pull request. +- Use meaningful variable and function names. +- Avoid large, monolithic commits. Break your changes into smaller, manageable commits. +- Keep your pull requests focused on a single issue or feature. +- Avoid including unrelated changes in your pull request. +- Ensure your pull request does not introduce any new warnings or errors. +- Use descriptive titles and detailed descriptions for your pull requests. +- Be respectful and professional in all communications related to your contribution. + +## Reporting Issues + +If you encounter any bugs or issues while using Eryon, please report them by opening an issue on the GitHub repository. Provide as much detail as possible, including steps to reproduce the issue, expected behavior, and actual behavior. diff --git a/Cargo.lock b/Cargo.lock index 0d9b270..8ffb5f8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -76,18 +76,18 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.46" +version = "4.5.47" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c5e4fcf9c21d2e544ca1ee9d8552de13019a42aa7dbf32747fa7aaf1df76e57" +checksum = "7eac00902d9d136acd712710d71823fb8ac8004ca445a89e73a41d45aa712931" dependencies = [ "clap_builder", ] [[package]] name = "clap_builder" -version = "4.5.46" +version = "4.5.47" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fecb53a0e6fcfb055f686001bc2e2592fa527efaf38dbe81a6a9563562e57d41" +checksum = "2ad9bbf750e73b5884fb8a211a9424a1906c1e156724260fdae972f31d70e1d6" dependencies = [ "anstyle", "clap_lex", @@ -236,9 +236,9 @@ checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c" [[package]] name = "js-sys" -version = "0.3.77" +version = "0.3.78" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1cfaf33c695fc6e08064efbc1f72ec937429614f25eef83af942d0e227c3a28f" +checksum = "0c0b063578492ceec17683ef2f8c5e89121fbd0b172cbc280635ab7567db2738" dependencies = [ "once_cell", "wasm-bindgen", @@ -246,9 +246,9 @@ dependencies = [ [[package]] name = "log" -version = "0.4.27" +version = "0.4.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13dc2df351e3202783a1fe0d44375f7295ffb4049267b0f3018346dc122a1d94" +checksum = "34080505efa8e45a4b816c349525ebe327ceaa8559756f0356cba97ef3bf7432" [[package]] name = "memchr" @@ -490,21 +490,22 @@ dependencies = [ [[package]] name = "wasm-bindgen" -version = "0.2.100" +version = "0.2.101" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1edc8929d7499fc4e8f0be2262a241556cfc54a0bea223790e71446f2aab1ef5" +checksum = "7e14915cadd45b529bb8d1f343c4ed0ac1de926144b746e2710f9cd05df6603b" dependencies = [ "cfg-if", "once_cell", "rustversion", "wasm-bindgen-macro", + "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-backend" -version = "0.2.100" +version = "0.2.101" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f0a0651a5c2bc21487bde11ee802ccaf4c51935d0d3d42a6101f98161700bc6" +checksum = "e28d1ba982ca7923fd01448d5c30c6864d0a14109560296a162f80f305fb93bb" dependencies = [ "bumpalo", "log", @@ -516,9 +517,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.100" +version = "0.2.101" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7fe63fc6d09ed3792bd0897b314f53de8e16568c2b3f7982f468c0bf9bd0b407" +checksum = "7c3d463ae3eff775b0c45df9da45d68837702ac35af998361e2c84e7c5ec1b0d" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -526,9 +527,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.100" +version = "0.2.101" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ae87ea40c9f689fc23f209965b6fb8a99ad69aeeb0231408be24920604395de" +checksum = "7bb4ce89b08211f923caf51d527662b75bdc9c9c7aab40f86dcb9fb85ac552aa" dependencies = [ "proc-macro2", "quote", @@ -539,18 +540,18 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.100" +version = "0.2.101" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a05d73b933a847d6cccdda8f838a22ff101ad9bf93e33684f39c1f5f0eece3d" +checksum = "f143854a3b13752c6950862c906306adb27c7e839f7414cec8fea35beab624c1" dependencies = [ "unicode-ident", ] [[package]] name = "web-sys" -version = "0.3.77" +version = "0.3.78" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "33b6dd2ef9186f1f2072e409e99cd22a975331a6b3591b12c764e0e55c60d5d2" +checksum = "77e4b637749ff0d92b8fad63aa1f7cff3cbe125fd49c175cd6345e7272638b12" dependencies = [ "js-sys", "wasm-bindgen", @@ -558,89 +559,24 @@ dependencies = [ [[package]] name = "winapi-util" -version = "0.1.10" +version = "0.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0978bf7171b3d90bac376700cb56d606feb40f251a475a5d6634613564460b22" +checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22" dependencies = [ "windows-sys", ] [[package]] name = "windows-link" -version = "0.1.3" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e6ad25900d524eaabdbbb96d20b4311e1e7ae1699af4fb28c17ae66c80d798a" +checksum = "45e46c0661abb7180e7b9c281db115305d49ca1709ab8242adf09666d2173c65" [[package]] name = "windows-sys" -version = "0.60.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2f500e4d28234f72040990ec9d39e3a6b950f9f22d3dba18416c35882612bcb" -dependencies = [ - "windows-targets", -] - -[[package]] -name = "windows-targets" -version = "0.53.3" +version = "0.61.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d5fe6031c4041849d7c496a8ded650796e7b6ecc19df1a431c1a363342e5dc91" +checksum = "e201184e40b2ede64bc2ea34968b28e33622acdbbf37104f0e4a33f7abe657aa" dependencies = [ "windows-link", - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_gnullvm", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", ] - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.53.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86b8d5f90ddd19cb4a147a5fa63ca848db3df085e25fee3cc10b39b6eebae764" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.53.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c7651a1f62a11b8cbd5e0d42526e55f2c99886c77e007179efff86c2b137e66c" - -[[package]] -name = "windows_i686_gnu" -version = "0.53.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1dc67659d35f387f5f6c479dc4e28f1d4bb90ddd1a5d3da2e5d97b42d6272c3" - -[[package]] -name = "windows_i686_gnullvm" -version = "0.53.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ce6ccbdedbf6d6354471319e781c0dfef054c81fbc7cf83f338a4296c0cae11" - -[[package]] -name = "windows_i686_msvc" -version = "0.53.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "581fee95406bb13382d2f65cd4a908ca7b1e4c2f1917f143ba16efe98a589b5d" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.53.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2e55b5ac9ea33f2fc1716d1742db15574fd6fc8dadc51caab1c16a3d3b4190ba" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.53.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a6e035dd0599267ce1ee132e51c27dd29437f63325753051e71dd9e42406c57" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.53.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "271414315aff87387382ec3d271b52d7ae78726f5d44ac98b4f4030c91880486" diff --git a/Cargo.toml b/Cargo.toml index 7b42465..66f0aae 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -30,7 +30,6 @@ contained-derive = { default-features = false, path = "derive", version = "0.2.2 contained-macros = { default-features = false, path = "macros", version = "0.2.2" } # error handling -anyhow = { default-features = false, version = "1" } thiserror = { default-features = false, version = "2" } # serialization serde = { default-features = false, features = ["derive"], version = "1" } diff --git a/core/Cargo.toml b/core/Cargo.toml index b3b8b68..feae3e5 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -26,13 +26,9 @@ all-features = false features = ["full"] rustc-args = ["--cfg", "docsrs"] -# ********* Unit Tests ********* [[test]] name = "default" -[[test]] -name = "macros" - [dependencies] # error handling thiserror = { workspace = true } diff --git a/core/src/error.rs b/core/src/error.rs index 98ae317..d5b5455 100644 --- a/core/src/error.rs +++ b/core/src/error.rs @@ -1,40 +1,52 @@ -/* - appellation: error - authors: @FL03 -*/ -//! this module defines the core error type for the crate - -#[cfg(feature = "alloc")] -use alloc::{boxed::Box, string::String}; -/// a type alias for a [`Result`](core::result::Result) configured to use the custom [`Error`] type. -pub type Result = core::result::Result; - -/// The custom error type for the crate. -#[derive(Debug, thiserror::Error)] -pub enum Error { - #[cfg(feature = "alloc")] - #[error(transparent)] - BoxError(#[from] Box), - #[error(transparent)] - FmtError(#[from] core::fmt::Error), - #[cfg(feature = "std")] - #[error(transparent)] - IOError(#[from] std::io::Error), - #[cfg(feature = "alloc")] - #[error("Unknown Error: {0}")] - Unknown(String), -} - -#[cfg(feature = "alloc")] -impl From<&str> for Error { - fn from(value: &str) -> Self { - Self::Unknown(String::from(value)) - } -} - -#[cfg(feature = "alloc")] -impl From for Error { - fn from(value: String) -> Self { - Self::Unknown(value) - } -} +/* + appellation: error + authors: @FL03 +*/ +//! this module defines the core error type for the crate + +/// a type alias for a [`Result`](core::result::Result) configured to use the custom [`Error`] type. +pub type Result = core::result::Result; + +/// The custom error type for the crate. +#[derive(Debug, thiserror::Error)] +pub enum Error { + #[cfg(feature = "alloc")] + #[error(transparent)] + BoxError(#[from] alloc::boxed::Box), + #[error(transparent)] + FmtError(#[from] core::fmt::Error), + #[cfg(feature = "std")] + #[error(transparent)] + IOError(#[from] std::io::Error), + #[cfg(feature = "alloc")] + #[error("Unknown Error: {0}")] + Unknown(alloc::string::String), +} + +#[cfg(feature = "alloc")] +mod impl_alloc { + use super::Error; + use alloc::boxed::Box; + use alloc::string::String; + + impl Error { + pub fn box_error(error: E) -> Self + where + E: core::error::Error + Send + Sync + 'static, + { + Self::BoxError(Box::new(error)) + } + } + + impl From<&str> for Error { + fn from(value: &str) -> Self { + Self::Unknown(String::from(value)) + } + } + + impl From for Error { + fn from(value: String) -> Self { + Self::Unknown(value) + } + } +} diff --git a/core/src/lib.rs b/core/src/lib.rs index 845d914..02df903 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -27,8 +27,6 @@ pub(crate) mod macros { #[macro_use] pub mod seal; #[macro_use] - pub mod wrapper_ops; - #[macro_use] pub mod wrapper; } diff --git a/core/src/macros/wrapper_ops.rs b/core/src/macros/wrapper_ops.rs deleted file mode 100644 index 4c43b72..0000000 --- a/core/src/macros/wrapper_ops.rs +++ /dev/null @@ -1,110 +0,0 @@ -/* - appellation: wrapper_ops - authors: @FL03 -*/ - -/// the [`impl_wrapper_unary!`] macro implements binary operations for a wrapper type. -/// -/// ## Syntax -/// -/// For tuple structs: -/// -/// ```ignore -/// impl_wrapper_unary! { -/// ${struct} { Op1.call, Op2.call, ... } -/// } -/// ``` -/// -/// For structs with named fields: -/// -/// ```ignore -/// impl_wrapper_unary! { -/// ${struct}.${field} { Op1.call, Op2.call, ... } -/// } -/// ``` -/// -/// **Note**: The target struct must have exactly one field; -#[macro_export] -macro_rules! impl_wrapper_unary { - ($s:ident.$field:ident { $($op:ident.$call:ident),* $(,)?}) => { - $( - $crate::impl_wrapper_unary!(@impl $s::$op.$call($field)); - )* - }; - ($s:ident { $($op:ident.$call:ident),* $(,)?}) => { - $( - $crate::impl_wrapper_unary!(@impl $s::$op.$call(0)); - )* - }; - (@impl $s:ident::$op:ident.$call:ident($field:ident)) => { - impl<_A, _B> ::core::ops::$op for $s<_A> - where - _A: ::core::ops::$op, - { - type Output = $s<_B>; - - fn $call(self) -> Self::Output { - let $field = ::core::ops::$op::$call(self.$field); - $s { $field } - } - } - - impl<'a, _A, _B> ::core::ops::$op for &'a $s<_A> - where - &'a _A: ::core::ops::$op, - { - type Output = $s<_B>; - - fn $call(self) -> Self::Output { - let $field = ::core::ops::$op::$call(&self.$field); - $s { $field } - } - } - - impl<'a, _A, _B> ::core::ops::$op for &'a mut $s<_A> - where - &'a mut _A: ::core::ops::$op, - { - type Output = $s<_B>; - - fn $call(self) -> Self::Output { - let $field = ::core::ops::$op::$call(&mut self.$field); - $s { $field } - } - } - }; - (@impl $s:ident::$op:ident.$call:ident(0)) => { - impl<_A, _B> ::core::ops::$op for $s<_A> - where - _A: ::core::ops::$op, - { - type Output = $s<_B>; - - fn $call(self) -> Self::Output { - $s(::core::ops::$op::$call(self.0)) - } - } - - impl<'a, _A, _B> ::core::ops::$op for &'a $s<_A> - where - &'a _A: ::core::ops::$op, - { - type Output = $s<_B>; - - fn $call(self) -> Self::Output { - $s(::core::ops::$op::$call(&self.0)) - } - } - - impl<'a, _A, _B> ::core::ops::$op for &'a mut $s<_A> - where - &'a mut _A: ::core::ops::$op, - { - type Output = $s<_B>; - - fn $call(self) -> Self::Output { - $s(::core::ops::$op::$call(&mut self.0)) - } - } - }; -} diff --git a/core/tests/macros.rs b/core/tests/macros.rs deleted file mode 100644 index b3096c0..0000000 --- a/core/tests/macros.rs +++ /dev/null @@ -1,33 +0,0 @@ -/* - appellation: macros - authors: @FL03 -*/ -use contained_core::impl_wrapper_unary; - -#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] -pub struct A(pub T); - -#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] -pub struct B { - pub field: T, -} - -impl_wrapper_unary! { - A { - Not.not - } -} - -impl_wrapper_unary! { - B.field { - Not.not - } -} - -#[test] -fn test_unary_impls() { - let a = A(true); - let b = B { field: true }; - assert_eq!(!a, A(false)); - assert_eq!(!b, B { field: false }); -} diff --git a/derive/Cargo.toml b/derive/Cargo.toml index 78a69a6..0009e0f 100644 --- a/derive/Cargo.toml +++ b/derive/Cargo.toml @@ -17,9 +17,9 @@ version.workspace = true [lib] bench = false doc = true -doctest = false +doctest = true proc-macro = true -test = false +test = true [[test]] name = "default" diff --git a/flake.nix b/flake.nix index 98dbaca..5e3f96f 100644 --- a/flake.nix +++ b/flake.nix @@ -1,24 +1,43 @@ -{ - description = "A flake for building a Rust workspace using buildRustPackage."; - - inputs = { - rust-overlay.url = "github:oxalica/rust-overlay"; - flake-utils.follows = "rust-overlay/flake-utils"; - nixpkgs.follows = "rust-overlay/nixpkgs"; - }; - - outputs = inputs: with inputs; - flake-utils.lib.eachDefaultSystem (system: - let - pkgs = nixpkgs.legacyPackages.${system}; - code = pkgs.callPackage ./. { inherit nixpkgs system rust-overlay; }; - in rec { - packages = { - default = pkgs.symlinkJoin { - name = "all"; - paths = with code; []; - }; - }; - } - ); -} +{ + description = "A developmental environment for a Rust project using Nix flakes with direnv"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + flake-utils.url = "github:numtide/flake-utils"; + rust-overlay = { + url = "github:oxalica/rust-overlay"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + }; + + outputs = { self, nixpkgs, flake-utils, rust-overlay, ... }: + flake-utils.lib.eachDefaultSystem (system: + let + overlays = [ (import rust-overlay) ]; + pkgs = import nixpkgs { inherit system overlays; }; + rustToolchain = pkgs.rust-bin.stable.latest.default; + in rec { + packages.default = pkgs.rustPlatform.buildRustPackage { + pname = "contained"; + version = "0.2.2"; + src = ./.; + cargoLock = { + lockFile = ./Cargo.lock; + }; + }; + + devShells.default = pkgs.mkShell { + buildInputs = [ + rustToolchain + pkgs.cargo + pkgs.rust-analyzer + pkgs.pkg-config + pkgs.openssl + ]; + shellHook = '' + export CARGO_HOME=$PWD/.cargo + ''; + }; + } + ); +} \ No newline at end of file diff --git a/macros/Cargo.toml b/macros/Cargo.toml index aa628bd..feccb3f 100644 --- a/macros/Cargo.toml +++ b/macros/Cargo.toml @@ -27,15 +27,15 @@ tag-name = "{{version}}" [lib] bench = false doc = true -doctest = false +doctest = true proc-macro = true -test = false +test = true [[test]] name = "default" [[test]] -name = "binary" +name = "ops" [dependencies] # procedural macros diff --git a/macros/src/impl_binary.rs b/macros/src/impl_binary.rs index e1c1152..4362540 100644 --- a/macros/src/impl_binary.rs +++ b/macros/src/impl_binary.rs @@ -5,6 +5,7 @@ use crate::ast::WrapperOpsAst; use proc_macro2::TokenStream; use quote::{format_ident, quote}; +use syn::Ident; /// Procedural macro entry point pub fn impl_wrapper_binary_ops(input: WrapperOpsAst) -> TokenStream { @@ -26,101 +27,9 @@ fn impl_core_binary_ops( let mut impls = Vec::new(); for (op, call) in ops { let _impl = if let Some(f) = field { - quote! { - impl<_A, _B, _C> ::core::ops::#op<#target<_B>> for #target<_A> - where - _A: ::core::ops::#op<_B, Output = _C>, - { - type Output = #target<_C>; - - fn #call(self, rhs: #target<_B>) -> Self::Output { - let #f = ::core::ops::#op::#call(self.#f, rhs.#f); - #target { #f } - } - } - - impl<'a, _A, _B, _C> ::core::ops::#op<&'a #target<_B>> for #target<_A> - where - _A: ::core::ops::#op<&'a _B, Output = _C>, - { - type Output = #target<_C>; - - fn #call(self, rhs: &'a #target<_B>) -> Self::Output { - let #f = ::core::ops::#op::#call(self.#f, &rhs.#f); - #target { #f } - } - } - - impl<'a, _A, _B, _C> ::core::ops::#op<&'a #target<_B>> for &'a #target<_A> - where - &'a _A: ::core::ops::#op<&'a _B, Output = _C>, - { - type Output = #target<_C>; - - fn #call(self, rhs: &'a #target<_B>) -> Self::Output { - let #f = ::core::ops::#op::#call(&self.#f, &rhs.#f); - #target { #f } - } - } - - impl<'a, _A, _B, _C> ::core::ops::#op<#target<_B>> for &'a #target<_A> - where - &'a _A: ::core::ops::#op<_B, Output = _C>, - { - type Output = #target<_C>; - - fn #call(self, rhs: #target<_B>) -> Self::Output { - let #f = ::core::ops::#op::#call(&self.#f, rhs.#f); - #target { #f } - } - } - } + impl_named(op, target, call, f) } else { - quote! { - impl<_A, _B, _C> ::core::ops::#op<#target<_B>> for #target<_A> - where - _A: ::core::ops::#op<_B, Output = _C>, - { - type Output = #target<_C>; - - fn #call(self, rhs: #target<_B>) -> Self::Output { - #target(::core::ops::#op::#call(self.0, rhs.0)) - } - } - - impl<'a, _A, _B, _C> ::core::ops::#op<&'a #target<_B>> for #target<_A> - where - _A: ::core::ops::#op<&'a _B, Output = _C>, - { - type Output = #target<_C>; - - fn #call(self, rhs: &'a #target<_B>) -> Self::Output { - #target(::core::ops::#op::#call(self.0, &rhs.0)) - } - } - - impl<'a, _A, _B, _C> ::core::ops::#op<&'a #target<_B>> for &'a #target<_A> - where - &'a _A: ::core::ops::#op<&'a _B, Output = _C>, - { - type Output = #target<_C>; - - fn #call(self, rhs: &'a #target<_B>) -> Self::Output { - #target(::core::ops::#op::#call(&self.0, &rhs.0)) - } - } - - impl<'a, _A, _B, _C> ::core::ops::#op<#target<_B>> for &'a #target<_A> - where - &'a _A: ::core::ops::#op<_B, Output = _C>, - { - type Output = #target<_C>; - - fn #call(self, rhs: #target<_B>) -> Self::Output { - #target(::core::ops::#op::#call(&self.0, rhs.0)) - } - } - } + impl_unnamed(op, target, call) }; impls.push(_impl); } @@ -165,3 +74,174 @@ fn impl_assign_ops(options: &WrapperOpsAst) -> Vec { } impls } + +fn impl_unnamed(op: &Ident, target: &Ident, call: &Ident) -> TokenStream { + quote! { + impl<_A, _B, _C> ::core::ops::#op<#target<_B>> for #target<_A> + where + _A: ::core::ops::#op<_B, Output = _C>, + { + type Output = #target<_C>; + + fn #call(self, rhs: #target<_B>) -> Self::Output { + #target(::core::ops::#op::#call(self.0, rhs.0)) + } + } + + impl<'a, _A, _B, _C> ::core::ops::#op<&'a #target<_B>> for #target<_A> + where + _A: ::core::ops::#op<&'a _B, Output = _C>, + { + type Output = #target<_C>; + + fn #call(self, rhs: &'a #target<_B>) -> Self::Output { + #target(::core::ops::#op::#call(self.0, &rhs.0)) + } + } + + impl<'a, _A, _B, _C> ::core::ops::#op<&'a #target<_B>> for &'a #target<_A> + where + &'a _A: ::core::ops::#op<&'a _B, Output = _C>, + { + type Output = #target<_C>; + + fn #call(self, rhs: &'a #target<_B>) -> Self::Output { + #target(::core::ops::#op::#call(&self.0, &rhs.0)) + } + } + + impl<'a, _A, _B, _C> ::core::ops::#op<#target<_B>> for &'a #target<_A> + where + &'a _A: ::core::ops::#op<_B, Output = _C>, + { + type Output = #target<_C>; + + fn #call(self, rhs: #target<_B>) -> Self::Output { + #target(::core::ops::#op::#call(&self.0, rhs.0)) + } + } + + impl<'a, _A, _B, _C> ::core::ops::#op<&'a mut #target<_B>> for #target<_A> + where + _A: ::core::ops::#op<&'a mut _B, Output = _C>, + { + type Output = #target<_C>; + + fn #call(self, rhs: &'a mut #target<_B>) -> Self::Output { + #target(::core::ops::#op::#call(self.0, &mut rhs.0)) + } + } + + impl<'a, _A, _B, _C> ::core::ops::#op<&'a mut #target<_B>> for &'a mut #target<_A> + where + &'a mut _A: ::core::ops::#op<&'a mut _B, Output = _C>, + { + type Output = #target<_C>; + + fn #call(self, rhs: &'a mut #target<_B>) -> Self::Output { + #target(::core::ops::#op::#call(&mut self.0, &mut rhs.0)) + } + } + + impl<'a, _A, _B, _C> ::core::ops::#op<#target<_B>> for &'a mut #target<_A> + where + &'a mut _A: ::core::ops::#op<_B, Output = _C>, + { + type Output = #target<_C>; + + fn #call(self, rhs: #target<_B>) -> Self::Output { + #target(::core::ops::#op::#call(&mut self.0, rhs.0)) + } + } + } +} + +fn impl_named(op: &Ident, target: &Ident, call: &Ident, field: &Ident) -> TokenStream { + quote! { + impl<_A, _B, _C> ::core::ops::#op<#target<_B>> for #target<_A> + where + _A: ::core::ops::#op<_B, Output = _C>, + { + type Output = #target<_C>; + + fn #call(self, rhs: #target<_B>) -> Self::Output { + let #field = ::core::ops::#op::#call(self.#field, rhs.#field); + #target { #field } + } + } + + impl<'a, _A, _B, _C> ::core::ops::#op<&'a #target<_B>> for #target<_A> + where + _A: ::core::ops::#op<&'a _B, Output = _C>, + { + type Output = #target<_C>; + + fn #call(self, rhs: &'a #target<_B>) -> Self::Output { + let #field = ::core::ops::#op::#call(self.#field, &rhs.#field); + #target { #field } + } + } + + impl<'a, _A, _B, _C> ::core::ops::#op<&'a #target<_B>> for &'a #target<_A> + where + &'a _A: ::core::ops::#op<&'a _B, Output = _C>, + { + type Output = #target<_C>; + + fn #call(self, rhs: &'a #target<_B>) -> Self::Output { + let #field = ::core::ops::#op::#call(&self.#field, &rhs.#field); + #target { #field } + } + } + + impl<'a, _A, _B, _C> ::core::ops::#op<#target<_B>> for &'a #target<_A> + where + &'a _A: ::core::ops::#op<_B, Output = _C>, + { + type Output = #target<_C>; + + fn #call(self, rhs: #target<_B>) -> Self::Output { + let #field = ::core::ops::#op::#call(&self.#field, rhs.#field); + #target { #field } + } + } + + + + impl<'a, _A, _B, _C> ::core::ops::#op<&'a mut #target<_B>> for #target<_A> + where + _A: ::core::ops::#op<&'a mut _B, Output = _C>, + { + type Output = #target<_C>; + + fn #call(self, rhs: &'a mut #target<_B>) -> Self::Output { + let #field = ::core::ops::#op::#call(self.#field, &mut rhs.#field); + #target { #field } + } + } + + impl<'a, _A, _B, _C> ::core::ops::#op<&'a mut #target<_B>> for &'a mut #target<_A> + where + &'a mut _A: ::core::ops::#op<&'a mut _B, Output = _C>, + { + type Output = #target<_C>; + + fn #call(self, rhs: &'a mut #target<_B>) -> Self::Output { + let #field = ::core::ops::#op::#call(&mut self.#field, &mut rhs.#field); + #target { #field } + } + } + + impl<'a, _A, _B, _C> ::core::ops::#op<#target<_B>> for &'a mut #target<_A> + where + &'a mut _A: ::core::ops::#op<_B, Output = _C>, + { + type Output = #target<_C>; + + fn #call(self, rhs: #target<_B>) -> Self::Output { + let #field = ::core::ops::#op::#call(&mut self.#field, rhs.#field); + #target { #field } + } + } + } +} diff --git a/macros/src/impl_unary.rs b/macros/src/impl_unary.rs new file mode 100644 index 0000000..7b73a99 --- /dev/null +++ b/macros/src/impl_unary.rs @@ -0,0 +1,112 @@ +/* + appellation: impl_unary + authors: @FL03 +*/ +use crate::ast::WrapperOpsAst; +use proc_macro2::TokenStream; +use quote::quote; +use syn::Ident; + +/// Procedural macro entry point +pub fn impl_wrapper_unary_ops(input: WrapperOpsAst) -> TokenStream { + let base = impl_core_unary_ops(&input); + + quote! { + #(#base)* + + } +} + +fn impl_core_unary_ops( + WrapperOpsAst { + target, field, ops, .. + }: &WrapperOpsAst, +) -> Vec { + let mut impls = Vec::new(); + for (op, call) in ops { + let _impl = if let Some(f) = field { + impl_named(op, target, call, &f) + } else { + impl_tuple(op, target, call) + }; + impls.push(_impl); + } + impls +} + +fn impl_tuple(op: &Ident, target: &Ident, call: &Ident) -> TokenStream { + quote! { + impl<_A, _B> ::core::ops::#op for #target<_A> + where + _A: ::core::ops::#op, + { + type Output = #target<_B>; + + fn #call(self) -> Self::Output { + #target(::core::ops::#op::#call(self.0)) + } + } + + impl<'a, _A, _B> ::core::ops::#op for &'a #target<_A> + where + &'a _A: ::core::ops::#op, + { + type Output = #target<_B>; + + fn #call(self) -> Self::Output { + #target(::core::ops::#op::#call(&self.0)) + } + } + + impl<'a, _A, _B> ::core::ops::#op for &'a mut #target<_A> + where + &'a mut _A: ::core::ops::#op, + { + type Output = #target<_B>; + + fn #call(self) -> Self::Output { + #target(::core::ops::#op::#call(&mut self.0)) + } + } + } +} + +fn impl_named(op: &Ident, target: &Ident, call: &Ident, field: &Ident) -> TokenStream { + quote! { + impl<_A, _B> ::core::ops::#op for #target<_A> + where + _A: ::core::ops::#op, + { + type Output = #target<_B>; + + fn #call(self) -> Self::Output { + let #field = ::core::ops::#op::#call(self.#field); + #target { #field } + } + } + + impl<'a, _A, _B> ::core::ops::#op for &'a #target<_A> + where + &'a _A: ::core::ops::#op, + { + type Output = #target<_B>; + + fn #call(self) -> Self::Output { + let #field = ::core::ops::#op::#call(&self.#field); + #target { #field } + } + } + + impl<'a, _A, _B> ::core::ops::#op for &'a mut #target<_A> + where + &'a mut _A: ::core::ops::#op, + { + type Output = #target<_B>; + + fn #call(self) -> Self::Output { + let #field = ::core::ops::#op::#call(&mut self.#field); + #target { #field } + } + } + } +} diff --git a/macros/src/lib.rs b/macros/src/lib.rs index 31c5429..5194bd6 100644 --- a/macros/src/lib.rs +++ b/macros/src/lib.rs @@ -1,31 +1,107 @@ -/* - Appellation: contained-macros - Contributors: FL03 -*/ -//! procedural macros for interacting with various wrappers -extern crate proc_macro; - -pub(crate) mod impl_binary; - -pub(crate) mod ast { - #[doc(inline)] - #[allow(unused_imports)] - pub use self::{ops::*, wrapper::*}; - - mod ops; - #[allow(dead_code)] - mod wrapper; -} - -use crate::ast::WrapperOpsAst; -use proc_macro::TokenStream; -use syn::parse_macro_input; - -/// A procedural macro for generating implementations for core binary operations on a wrapper -/// type -#[proc_macro] -pub fn binary_wrapper(input: TokenStream) -> TokenStream { - let ast = parse_macro_input!(input as WrapperOpsAst); - let output = impl_binary::impl_wrapper_binary_ops(ast); - output.into() -} +/* + Appellation: contained-macros + Contributors: FL03 +*/ +//! procedural macros for interacting with various wrappers +extern crate proc_macro; + +pub(crate) mod impl_binary; +pub(crate) mod impl_unary; + +pub(crate) mod ast { + #[doc(inline)] + #[allow(unused_imports)] + pub use self::{ops::*, wrapper::*}; + + mod ops; + #[allow(dead_code)] + mod wrapper; +} + +use crate::ast::WrapperOpsAst; +use proc_macro::TokenStream; +use syn::parse_macro_input; + +/// The [`binary_wrapper!`] macro generates implementations for the core binary operations +/// onto a generic wrapper type. It supports both tuple structs and structs with named fields. +/// +/// ```rust +/// use contained_macros::binary_wrapper; +/// +/// pub struct Wrapper(pub T); +/// +/// binary_wrapper! { +/// impl Wrapper { +/// Add.add, +/// Sub.sub, +/// Mul.mul, +/// Div.div, +/// Rem.rem, +/// ... +/// } +/// } +/// ``` +/// +/// or, for transparent structs with a named field: +/// +/// ```rust +/// use contained_macros::binary_wrapper; +/// +/// pub struct Wrapper { +/// pub field: T, +/// } +/// +/// binary_wrapper! { +/// impl Wrapper.$field { +/// Add.add, +/// Sub.sub, +/// Mul.mul, +/// Div.div, +/// Rem.rem, +/// ... +/// } +/// } +/// ``` +#[proc_macro] +pub fn binary_wrapper(input: TokenStream) -> TokenStream { + let ast = parse_macro_input!(input as WrapperOpsAst); + let output = impl_binary::impl_wrapper_binary_ops(ast); + output.into() +} + +/// The [`unary_wrapper!`] macro generates implementations for the core unary operations +/// onto a generic wrapper type. It supports both tuple structs and structs with named fields. +/// +/// ```rust +/// pub struct Wrapper { +/// pub field: T, +/// } +/// +/// contained_macros::unary_wrapper! { +/// impl Wrapper { +/// Neg.neg, +/// Not.not, +/// } +/// } +/// ``` +/// +/// or, for transparent structs with a named field: +/// +/// ```rust +/// pub struct Wrapper { +/// pub field: T, +/// } +/// +/// contained_macros::unary_wrapper! { +/// impl Wrapper.$field { +/// Neg.neg, +/// Not.not, +/// } +/// } +/// ``` +#[proc_macro] +pub fn unary_wrapper(input: TokenStream) -> TokenStream { + let ast = parse_macro_input!(input as WrapperOpsAst); + let output = impl_unary::impl_wrapper_unary_ops(ast); + output.into() +} diff --git a/macros/tests/binary.rs b/macros/tests/ops.rs similarity index 70% rename from macros/tests/binary.rs rename to macros/tests/ops.rs index 6c2b8be..fe863a4 100644 --- a/macros/tests/binary.rs +++ b/macros/tests/ops.rs @@ -2,7 +2,7 @@ appellation: macros authors: @FL03 */ -use contained_macros::binary_wrapper; +use contained_macros::{binary_wrapper, unary_wrapper}; #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] #[repr(transparent)] @@ -44,6 +44,20 @@ binary_wrapper! { } } +unary_wrapper! { + impl A { + Neg.neg, + Not.not, + } +} + +unary_wrapper! { + impl B.value { + Neg.neg, + Not.not, + } +} + #[test] fn test_impl_binary_ops_on_tuple() { let (x, y) = (A(42), A(&2)); @@ -57,3 +71,11 @@ fn test_impl_binary_ops_on_struct() { assert_eq!((x + y), B { value: 44 }); assert_eq!((x - y), B { value: 40 }); } + +#[test] +fn test_unary_impls() { + let a = A(true); + let b = B { value: true }; + assert_eq!(!a, A(false)); + assert_eq!(!b, B { value: false }); +} diff --git a/shell.nix b/shell.nix new file mode 100644 index 0000000..7507c2e --- /dev/null +++ b/shell.nix @@ -0,0 +1,10 @@ +{ channel ? "stable", profile ? "default" }: +with import { overlays = [ (import rust-overlay) ]; }; +mkShell { + nativeBuildInputs = [ + (if channel == "nightly" then + rust-bin.selectLatestNightlyWith (toolchain: toolchain.${profile}) + else + rust-bin.${channel}.latest.${profile}) + ]; +} \ No newline at end of file From 4832e597fc843f5bb150b13a5e54bd149006ce37 Mon Sep 17 00:00:00 2001 From: FL03 Date: Mon, 8 Sep 2025 21:00:07 -0500 Subject: [PATCH 4/6] update Signed-off-by: FL03 --- .vscode/settings.json | 3 +++ Cargo.lock | 7 ------- Cargo.toml | 8 +++++--- core/Cargo.toml | 2 -- macros/src/lib.rs | 26 +++++++++++++------------- 5 files changed, 21 insertions(+), 25 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 0dddf02..51060ba 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -2,5 +2,8 @@ "rust-analyzer.check.features": [ "default", "full" + ], + "github-actions.workflows.pinned.workflows": [ + ".github/workflows/rust.yml" ] } diff --git a/Cargo.lock b/Cargo.lock index 8ffb5f8..ce9ab44 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -113,7 +113,6 @@ dependencies = [ name = "contained-core" version = "0.2.2" dependencies = [ - "paste", "serde", "serde_derive", "serde_json", @@ -277,12 +276,6 @@ version = "11.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d6790f58c7ff633d8771f42965289203411a5e5c68388703c06e14f24770b41e" -[[package]] -name = "paste" -version = "1.0.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" - [[package]] name = "plotters" version = "0.3.7" diff --git a/Cargo.toml b/Cargo.toml index 66f0aae..e047036 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -51,8 +51,9 @@ incremental = true lto = "thin" opt-level = 2 overflow-checks = true -panic = "unwind" +panic = "abort" rpath = false +strip = "symbols" [profile.release] codegen-units = 16 @@ -60,7 +61,8 @@ debug = false debug-assertions = false incremental = false lto = true -opt-level = 0 +opt-level = "z" overflow-checks = false -panic = "unwind" +panic = "abort" rpath = false +strip = "debuginfo" diff --git a/core/Cargo.toml b/core/Cargo.toml index feae3e5..8df78f2 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -32,8 +32,6 @@ name = "default" [dependencies] # error handling thiserror = { workspace = true } -# macros & utilities -paste = { workspace = true } # serialization serde = { optional = true, features = ["derive"], workspace = true } serde_derive = { optional = true, workspace = true } diff --git a/macros/src/lib.rs b/macros/src/lib.rs index 5194bd6..00440c5 100644 --- a/macros/src/lib.rs +++ b/macros/src/lib.rs @@ -26,18 +26,17 @@ use syn::parse_macro_input; /// onto a generic wrapper type. It supports both tuple structs and structs with named fields. /// /// ```rust -/// use contained_macros::binary_wrapper; +/// extern crate contained_macros as macros; /// /// pub struct Wrapper(pub T); /// -/// binary_wrapper! { +/// macros::binary_wrapper! { /// impl Wrapper { /// Add.add, /// Sub.sub, /// Mul.mul, /// Div.div, /// Rem.rem, -/// ... /// } /// } /// ``` @@ -45,20 +44,19 @@ use syn::parse_macro_input; /// or, for transparent structs with a named field: /// /// ```rust -/// use contained_macros::binary_wrapper; +/// extern crate contained_macros as macros; /// /// pub struct Wrapper { /// pub field: T, /// } /// -/// binary_wrapper! { -/// impl Wrapper.$field { +/// macros::binary_wrapper! { +/// impl Wrapper.field { /// Add.add, /// Sub.sub, /// Mul.mul, /// Div.div, /// Rem.rem, -/// ... /// } /// } /// ``` @@ -73,11 +71,11 @@ pub fn binary_wrapper(input: TokenStream) -> TokenStream { /// onto a generic wrapper type. It supports both tuple structs and structs with named fields. /// /// ```rust -/// pub struct Wrapper { -/// pub field: T, -/// } +/// extern crate contained_macros as macros; +/// +/// pub struct Wrapper(pub T); /// -/// contained_macros::unary_wrapper! { +/// macros::unary_wrapper! { /// impl Wrapper { /// Neg.neg, /// Not.not, @@ -88,12 +86,14 @@ pub fn binary_wrapper(input: TokenStream) -> TokenStream { /// or, for transparent structs with a named field: /// /// ```rust +/// extern crate contained_macros as macros; +/// /// pub struct Wrapper { /// pub field: T, /// } /// -/// contained_macros::unary_wrapper! { -/// impl Wrapper.$field { +/// macros::unary_wrapper! { +/// impl Wrapper.field { /// Neg.neg, /// Not.not, /// } From 0354300f35cf828f0ff682b16e04dbc2637a4a86 Mon Sep 17 00:00:00 2001 From: FL03 Date: Mon, 8 Sep 2025 21:01:58 -0500 Subject: [PATCH 5/6] update impl_unary.rs Signed-off-by: FL03 --- macros/src/impl_unary.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/macros/src/impl_unary.rs b/macros/src/impl_unary.rs index 7b73a99..5fe6efd 100644 --- a/macros/src/impl_unary.rs +++ b/macros/src/impl_unary.rs @@ -25,7 +25,7 @@ fn impl_core_unary_ops( let mut impls = Vec::new(); for (op, call) in ops { let _impl = if let Some(f) = field { - impl_named(op, target, call, &f) + impl_named(op, target, call, f) } else { impl_tuple(op, target, call) }; From 81b938e3d780038f02dd73c7a80abc754ed96f25 Mon Sep 17 00:00:00 2001 From: FL03 Date: Mon, 8 Sep 2025 21:06:47 -0500 Subject: [PATCH 6/6] update Signed-off-by: FL03 --- contained/Cargo.toml | 18 +++++++----------- core/Cargo.toml | 16 ++++++++++------ derive/Cargo.toml | 24 ++++++++++++------------ macros/src/lib.rs | 12 ++++++++++++ 4 files changed, 41 insertions(+), 29 deletions(-) diff --git a/contained/Cargo.toml b/contained/Cargo.toml index 378e502..77d3e68 100644 --- a/contained/Cargo.toml +++ b/contained/Cargo.toml @@ -14,16 +14,9 @@ repository.workspace = true rust-version.workspace = true version.workspace = true -[lib] -crate-type = ["cdylib", "rlib"] -bench = true -doctest = true -test = true - -# ********* Package Metadata ********* [package.metadata.docs.rs] all-features = false -features = ["default"] +features = ["full"] rustc-args = ["--cfg", "docsrs"] version = "v{{version}}" @@ -31,12 +24,16 @@ version = "v{{version}}" no-dev-version = true tag-name = "{{version}}" -# ********* Benchmarks ********* +[lib] +crate-type = ["cdylib", "rlib"] +bench = true +doctest = true +test = true + [[bench]] name = "default" harness = false -# ********* Examples ********* [[example]] name = "derive" required-features = ["derive"] @@ -45,7 +42,6 @@ required-features = ["derive"] name = "macros" required-features = ["macros"] -# ********* Unit Tests ********* [[test]] name = "default" diff --git a/core/Cargo.toml b/core/Cargo.toml index 8df78f2..2cb8d12 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -14,18 +14,22 @@ repository.workspace = true rust-version.workspace = true version.workspace = true +[package.metadata.docs.rs] +all-features = false +features = ["full"] +rustc-args = ["--cfg", "docsrs"] +version = "v{{version}}" + +[package.metadata.release] +no-dev-version = true +tag-name = "{{version}}" + [lib] crate-type = ["cdylib", "rlib"] bench = false doctest = true test = true -# ********* Package Metadata ********* -[package.metadata.docs.rs] -all-features = false -features = ["full"] -rustc-args = ["--cfg", "docsrs"] - [[test]] name = "default" diff --git a/derive/Cargo.toml b/derive/Cargo.toml index 0009e0f..89db2c1 100644 --- a/derive/Cargo.toml +++ b/derive/Cargo.toml @@ -14,6 +14,16 @@ repository.workspace = true rust-version.workspace = true version.workspace = true +[package.metadata.docs.rs] +all-features = false +features = ["default"] +rustc-args = ["--cfg", "docsrs"] +version = "v{{version}}" + +[package.metadata.release] +no-dev-version = true +tag-name = "{{version}}" + [lib] bench = false doc = true @@ -21,25 +31,15 @@ doctest = true proc-macro = true test = true +# ********* [Unit Tests] ********* + [[test]] name = "default" [[test]] name = "wrapper" -# ********* Package Metadata ********* -[package.metadata.docs.rs] -all-features = false -features = ["default"] -rustc-args = ["--cfg", "docsrs"] -version = "v{{version}}" - -[package.metadata.release] -no-dev-version = true -tag-name = "{{version}}" - [dependencies] -# procedural macros proc-macro2 = { version = "1" } quote = { version = "1" } syn = { features = ["full"], version = "2" } diff --git a/macros/src/lib.rs b/macros/src/lib.rs index 00440c5..9132d8a 100644 --- a/macros/src/lib.rs +++ b/macros/src/lib.rs @@ -105,3 +105,15 @@ pub fn unary_wrapper(input: TokenStream) -> TokenStream { let output = impl_unary::impl_wrapper_unary_ops(ast); output.into() } + + +#[deprecated( + since = "0.2.2", + note = "use `unary_wrapper` instead" +)] +#[proc_macro] +pub fn impl_wrapper_unary(input: TokenStream) -> TokenStream { + let ast = parse_macro_input!(input as WrapperOpsAst); + let output = impl_unary::impl_wrapper_unary_ops(ast); + output.into() +}