diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..f809ade --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,19 @@ +{ + "name": "remi-rs", + "image": "ghcr.io/auguwu/coder-images/rust", + "containerUser": "noel", + "remoteUser": "noel", + "customizations": { + "vscode": { + "extensions": [ + "rust-lang.rust-analyzer", + "tamasfe.even-better-toml", + "ms-azuretools.vscode-docker" + ] + } + }, + "features": { + // sshd is required for JetBrains Gateway when using Codespaces + "ghcr.io/devcontainers/features/sshd:1": {} + } +} diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..97f24a8 --- /dev/null +++ b/.envrc @@ -0,0 +1,39 @@ +# 🐻‍❄️🪚 core-rs: Collection of Rust crates that are used by and built for Noelware's projects +# Copyright (c) 2024 Noelware, LLC. +# +# 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. + +if ! has nix_direnv_version || ! nix_direnv_version 2.3.0; then + source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/2.3.0/direnvrc" "sha256-Dmd+j63L84wuzgyjITIfSxSD57Tx7v51DMxVZOsiUD8=" +fi + +# make .direnv if it doesn't exist +mkdir -p "$(direnv_layout_dir)" + +watch_file shell.nix +watch_file flake.nix # as outputs can change at anytime +watch_file flake.lock + +# we need to watch the rust-toolchain.toml file so if any edits occur, +# then direnv can react to it and change the environment. +watch_file rust-toolchain.toml + +# try to use flakes, if it fails use normal nix (ie. shell.nix) +use flake || use nix +eval "$shellHook" diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 0000000..a4d437f --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1 @@ +* @auguwu diff --git a/.github/CODE_OF_CONDUCT.md b/.github/CODE_OF_CONDUCT.md new file mode 100644 index 0000000..f2bae20 --- /dev/null +++ b/.github/CODE_OF_CONDUCT.md @@ -0,0 +1,76 @@ +# Contributor Covenant Code of Conduct + +## Our Pledge + +In the interest of fostering an open and welcoming environment, we as +contributors and maintainers pledge to making participation in our project and +our community a harassment-free experience for everyone, regardless of age, body +size, disability, ethnicity, sex characteristics, gender identity and expression, +level of experience, education, socio-economic status, nationality, personal +appearance, race, religion, or sexual identity and orientation. + +## Our Standards + +Examples of behavior that contributes to creating a positive environment +include: + +* Using welcoming and inclusive language +* Being respectful of differing viewpoints and experiences +* Gracefully accepting constructive criticism +* Focusing on what is best for the community +* Showing empathy towards other community members + +Examples of unacceptable behavior by participants include: + +* The use of sexualized language or imagery and unwelcome sexual attention or + advances +* Trolling, insulting/derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or electronic + address, without explicit permission +* Other conduct which could reasonably be considered inappropriate in a + professional setting + +## Our Responsibilities + +Project maintainers are responsible for clarifying the standards of acceptable +behavior and are expected to take appropriate and fair corrective action in +response to any instances of unacceptable behavior. + +Project maintainers have the right and responsibility to remove, edit, or +reject comments, commits, code, wiki edits, issues, and other contributions +that are not aligned to this Code of Conduct, or to ban temporarily or +permanently any contributor for other behaviors that they deem inappropriate, +threatening, offensive, or harmful. + +## Scope + +This Code of Conduct applies both within project spaces and in public spaces +when an individual is representing the project or its community. Examples of +representing a project or community include using an official project e-mail +address, posting via an official social media account, or acting as an appointed +representative at an online or offline event. Representation of a project may be +further defined and clarified by project maintainers. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be +reported by contacting the project team at **team@noelware.org**. All +complaints will be reviewed and investigated and will result in a response that +is deemed necessary and appropriate to the circumstances. The project team is +obligated to maintain confidentiality with regard to the reporter of an incident. +Further details of specific enforcement policies may be posted separately. + +Project maintainers who do not follow or enforce the Code of Conduct in good +faith may face temporary or permanent repercussions as determined by other +members of the project's leadership. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, +available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html + +[homepage]: https://www.contributor-covenant.org + +For answers to common questions about this code of conduct, see +https://www.contributor-covenant.org/faq diff --git a/.github/workflows/CI.yaml b/.github/workflows/CI.yaml new file mode 100644 index 0000000..d176e50 --- /dev/null +++ b/.github/workflows/CI.yaml @@ -0,0 +1,95 @@ +# 🐻‍❄️🪚 core-rs: Collection of Rust crates that are used by and built for Noelware's projects +# Copyright (c) 2024 Noelware, LLC. +# +# 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. + +name: CI +on: + workflow_dispatch: {} + pull_request: + types: [opened, synchronize] + branches: + - master + + paths-ignore: + - 'assets/**' + - .dockerignore + - .gitignore + - '**.md' + - LICENSE + - renovate.json + push: + branches: + - 'issue/gh-**' + - 'feat/**' + - master + + paths-ignore: + - '.github/**' + - '.coder/**' + - '.vscode/**' + - 'assets/**' + - '.*ignore' + - '**.md' + - LICENSE + - renovate.json +jobs: + rust: + name: Rust CI [${{matrix.rust-version}} on ${{matrix.runner == 'ubuntu-latest' && 'Linux (x86_64)' || matrix.runner == 'windows-latest' && 'Windows' || matrix.runner == 'macos-latest' && 'macOS' || matrix.runner == 'self-hosted' && 'Linux (arm64)' || matrix.runner}}] + runs-on: ${{matrix.runner}} + strategy: + matrix: + rust-version: [stable, nightly] + runner: [ubuntu-latest, windows-latest, macos-latest] + steps: + - name: Checkout repository + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4 + + - name: Setup Rust toolchain + uses: dtolnay/rust-toolchain@master + with: + toolchain: ${{matrix.rust-version}} + components: clippy, rustfmt + + - name: Setup Rust cache + uses: Swatinem/rust-cache@v2 + + - name: Pull dependencies + run: cargo build --all-features + clippy: + name: Clippy + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4 + + - name: Setup Rust toolchain + uses: dtolnay/rust-toolchain@master + with: + toolchain: stable + components: clippy, rustfmt + + - name: Setup Rust cache + uses: Swatinem/rust-cache@v2 + + - name: Clippy! + uses: auguwu/clippy-action@1.3.0 + with: + all-features: true + token: ${{secrets.GITHUB_TOKEN}} diff --git a/.github/workflows/Release.yaml b/.github/workflows/Release.yaml new file mode 100644 index 0000000..d80fba8 --- /dev/null +++ b/.github/workflows/Release.yaml @@ -0,0 +1,46 @@ +# 🐻‍❄️🪚 core-rs: Collection of Rust crates that are used by and built for Noelware's projects +# Copyright (c) 2024 Noelware, LLC. +# +# 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. + +name: Release crates +on: + release: + types: + - published +jobs: + release: + name: Release crate on crates.io + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + submodules: 'true' + + - name: Setup Rust toolchain + uses: dtolnay/rust-toolchain@stable + with: + components: clippy, rustfmt + + - name: Setup Rust cache + uses: Swatinem/rust-cache@v2 + + - name: Publish! + run: cargo publish diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..bedf8ed --- /dev/null +++ b/.gitignore @@ -0,0 +1,514 @@ +# User-specific stuff +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/**/usage.statistics.xml +.idea/**/dictionaries +.idea/**/shelf + +# AWS User-specific +.idea/**/aws.xml + +# Generated files +.idea/**/contentModel.xml + +# Sensitive or high-churn files +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml +.idea/**/dbnavigator.xml + +# Gradle +.idea/**/gradle.xml +.idea/**/libraries + +# Gradle and Maven with auto-import +# When using Gradle or Maven with auto-import, you should exclude module files, +# since they will be recreated, and may cause churn. Uncomment if using +# auto-import. +# .idea/artifacts +# .idea/compiler.xml +# .idea/jarRepositories.xml +# .idea/modules.xml +# .idea/*.iml +# .idea/modules +# *.iml +# *.ipr + +# CMake +cmake-build-*/ + +# Mongo Explorer plugin +.idea/**/mongoSettings.xml + +# File-based project format +*.iws + +# IntelliJ +out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# SonarLint plugin +.idea/sonarlint/ + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +# Editor-based Rest Client +.idea/httpRequests + +# Android studio 3.1+ serialized cache file +.idea/caches/build_file_checksums.ser + +### JetBrains+all Patch ### +# Ignore everything but code style settings and run configurations +# that are supposed to be shared within teams. + +.idea/* + +!.idea/codeStyles +!.idea/runConfigurations + +### Rust ### +# Generated by Cargo +# will have compiled files and executables +debug/ +target/ + +# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries +# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html +Cargo.lock + +# These are backup files generated by rustfmt +**/*.rs.bk + +# MSVC Windows builds of rustc generate these, which store debugging information +*.pdb + +### VisualStudioCode ### +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +!.vscode/*.code-snippets + +# Local History for Visual Studio Code +.history/ + +# Built Visual Studio Code Extensions +*.vsix + +### VisualStudioCode Patch ### +# Ignore all local history of files +.history +.ionide + +### VisualStudio ### +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. +## +## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore + +# User-specific files +*.rsuser +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Mono auto generated files +mono_crash.* + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +[Ww][Ii][Nn]32/ +[Aa][Rr][Mm]/ +[Aa][Rr][Mm]64/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ +[Ll]ogs/ + +# Visual Studio 2015/2017 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# Visual Studio 2017 auto generated files +Generated\ Files/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUnit +*.VisualState.xml +TestResult.xml +nunit-*.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# Benchmark Results +BenchmarkDotNet.Artifacts/ + +# .NET Core +project.lock.json +project.fragment.lock.json +artifacts/ + +# ASP.NET Scaffolding +ScaffoldingReadMe.txt + +# StyleCop +StyleCopReport.xml + +# Files built by Visual Studio +*_i.c +*_p.c +*_h.h +*.ilk +*.meta +*.obj +*.iobj +*.pch +*.ipdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*_wpftmp.csproj +*.log +*.tlog +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# Visual Studio Trace Files +*.e2e + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# AxoCover is a Code Coverage Tool +.axoCover/* +!.axoCover/settings.json + +# Coverlet is a free, cross platform Code Coverage Tool +coverage*.json +coverage*.xml +coverage*.info + +# Visual Studio code coverage results +*.coverage +*.coveragexml + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# Note: Comment the next line if you want to checkin your web deploy settings, +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# NuGet Symbol Packages +*.snupkg +# The packages folder can be ignored because of Package Restore +**/[Pp]ackages/* +# except build/, which is used as an MSBuild target. +!**/[Pp]ackages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/[Pp]ackages/repositories.config +# NuGet v3's project.json files produces more ignorable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt +*.appx +*.appxbundle +*.appxupload + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!?*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +orleans.codegen.cs + +# Including strong name files can present a security risk +# (https://github.com/github/gitignore/pull/2483#issue-259490424) +#*.snk + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm +ServiceFabricBackup/ +*.rptproj.bak + +# SQL Server files +*.mdf +*.ldf +*.ndf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings +*.rptproj.rsuser +*- [Bb]ackup.rdl +*- [Bb]ackup ([0-9]).rdl +*- [Bb]ackup ([0-9][0-9]).rdl + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat +node_modules/ + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio 6 auto-generated project file (contains which files were open etc.) +*.vbp + +# Visual Studio 6 workspace and project file (working project files containing files to include in project) +*.dsw +*.dsp + +# Visual Studio 6 technical files + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# CodeRush personal settings +.cr/personal + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config + +# Tabs Studio +*.tss + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs + +# OpenCover UI analysis results +OpenCover/ + +# Azure Stream Analytics local run output +ASALocalRun/ + +# MSBuild Binary and Structured Log +*.binlog + +# NVidia Nsight GPU debugger configuration file +*.nvuser + +# MFractors (Xamarin productivity tool) working folder +.mfractor/ + +# Local History for Visual Studio +.localhistory/ + +# Visual Studio History (VSHistory) files +.vshistory/ + +# BeatPulse healthcheck temp database +healthchecksdb + +# Backup folder for Package Reference Convert tool in Visual Studio 2017 +MigrationBackup/ + +# Ionide (cross platform F# VS Code tools) working folder +.ionide/ + +# Fody - auto-generated XML schema +FodyWeavers.xsd + +# VS Code files for those working on multiple tools +*.code-workspace + +# Local History for Visual Studio Code + +# Windows Installer files from build outputs +*.cab +*.msi +*.msix +*.msm +*.msp + +# JetBrains Rider +*.sln.iml + +### VisualStudio Patch ### +# Additional files built by Visual Studio + +.direnv/ diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..efb4377 --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,8 @@ +{ + "recommendations": [ + "me-dutour-mathieu.vscode-github-actions", + "tamasfe.even-better-toml", + "rust-lang.rust-analyzer", + "redhat.vscode-yaml" + ] +} diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..69ce395 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,12 @@ +{ + "editor.tabSize": 4, + "editor.formatOnSave": true, + "rust-analyzer.check.command": "clippy", + "rust-analyzer.showUnlinkedFileNotification": false, + "[rust]": { + "editor.defaultFormatter": "rust-lang.rust-analyzer" + }, + "files.associations": { + ".*-version": "plaintext" + } +} diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..a3e2625 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,34 @@ +# 🐻‍❄️🪚 core-rs: Collection of Rust crates that are used by and built for Noelware's projects +# Copyright (c) 2024 Noelware, LLC. +# +# 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. + +[workspace] +resolver = "2" +members = ["crates/log", "crates/serde"] + +[workspace.package] +version = "0.1.0" +authors = ["Noel Towa "] +edition = "2021" +homepage = "https://cargo.noelware.cloud" +license = "MIT" +publish = ["noelware"] +repository = "https://github.com/Noelware/core-rs" +rust-version = "1.71" diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..ff615dc --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2024 Noelware, LLC. + +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/README.md b/README.md new file mode 100644 index 0000000..bc8f44c --- /dev/null +++ b/README.md @@ -0,0 +1,18 @@ +# 🐻‍❄️🪚 `core-rs` +> *Collection of Rust crates that are used by and built for Noelware's projects* + +`core-rs` is the main repository that hosts most of Noelware's crates that can be publically used, but for applications/programs only, which is why all the crates available here are not on [`crates.io`](https://crates.io). Which means, library-facing code outside of the scope of this repository cannot be published with `crates.io`. + +> [!IMPORTANT] +> The only crate from `core-rs` is available on [`crates.io`](https://crates.io) is [`noelware-serde`](https://docs.rs/noelware-serde) as it is probably a crate that most people would want to use. + +## Why aren't you publishing these crates to crates.io? +Because, it felt unneccessary to upload and pollute crates.io with Rust crates that are the scope of Noelware's software projects itself, while you're free to use them and grab the code for library-facing code (with the license attached), since this repository is released under the **MIT License**. + +## Are you going to do this to your public crates already on `crates.io`? +No. We don't plan on moving our public-facing crates like [`remi-rs`](https://github.com/Noelware/remi-rs) to our Cargo registry. + +## License +**core-rs** by Noelware, LLC. is released under the **MIT License** with love. Please read the [`LICENSE`](./LICENSE) file in the repository attached for more information about on what you can do with the code. + +If you're going to use the code from `core-rs` in your public-facing crates, please copy the code ***with the license on top*** of the file. diff --git a/clippy.toml b/clippy.toml new file mode 100644 index 0000000..cab0662 --- /dev/null +++ b/clippy.toml @@ -0,0 +1,22 @@ +# 🐻‍❄️🪚 core-rs: Collection of Rust crates that are used by and built for Noelware's projects +# Copyright (c) 2024 Noelware, LLC. +# +# 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. + +msrv = "1.71" diff --git a/crates/serde/Cargo.toml b/crates/serde/Cargo.toml new file mode 100644 index 0000000..6346886 --- /dev/null +++ b/crates/serde/Cargo.toml @@ -0,0 +1,47 @@ +# 🐻‍❄️🪚 core-rs: Collection of Rust crates that are used by and built for Noelware's projects +# Copyright (c) 2024 Noelware, LLC. +# +# 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. + +[package] +name = "noelware-serde" +description = "🐻‍❄️🪚 Provides `serde` implementations for important structs/enums/etc" +version.workspace = true +authors.workspace = true +edition.workspace = true +homepage.workspace = true +license.workspace = true +repository.workspace = true +rust-version.workspace = true + +[features] +default = [] +tracing = ["dep:tracing"] +aws = ["dep:aws-types"] +s3 = ["dep:aws-sdk-s3"] + +[dependencies] +aws-sdk-s3 = { version = "1.12.0", optional = true } +aws-types = { version = "1.1.2", optional = true } +serde = "1.0.195" +tracing = { version = "0.1.40", optional = true } + +[package.metadata.docs.rs] +all-features = true +rustdoc-args = ["--cfg", "docsrs"] diff --git a/crates/serde/README.md b/crates/serde/README.md new file mode 100644 index 0000000..1e194e4 --- /dev/null +++ b/crates/serde/README.md @@ -0,0 +1,32 @@ +# 🐻‍❄️🪚 `noelware-serde` +The **noelware-serde** crate provides blanket `serde` implementations for crates that don't expose any. This uses Cargo's crate features to explicitly enable which implementations you need, rather than adding them all at once. + +We only provide implementations to Rust types that are most used by us, so we will probably reject most requests to add more types other than the ones listed. + +> [!NOTE] +> This crate is apart of the [`core-rs`](https://github.com/Noelware/core-rs) family of crates by [Noelware, LLC.](https://noelware.org) +> +> This is the only crate that is available on [`crates.io`](https://crates.io/crates/noelware-serde) from Noelware's `core-rs` family. + +## Usage +### `tracing::Level` (requires `tracing` feature) +```rust,ignore +use serde::{Serialize, Deserialize}; + +#[derive(Serialize, Deserialize)] +struct MyStruct { + #[serde(with = "noelware_serde::tracing")] + level: tracing::Level, +} +``` + +### `aws_types::types::Region` (requires `aws` feature) +```rust,ignore +use serde::{Serialize, Deserialize}; + +#[derive(Serialize, Deserialize)] +struct MyStruct { + #[serde(with = "noelware_serde::aws::region")] + region: aws_sdk_s3::types::Region +} +``` diff --git a/crates/serde/src/aws.rs b/crates/serde/src/aws.rs new file mode 100644 index 0000000..610173c --- /dev/null +++ b/crates/serde/src/aws.rs @@ -0,0 +1,73 @@ +// 🐻‍❄️🪚 core-rs: Collection of Rust crates that are used by and built for Noelware's projects +// Copyright (c) 2024 Noelware, LLC. +// +// 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. + +//! Defines extra [`Serializer`](serde::ser::Serializer) and [`Deserializer`](serde::de::Deserializer) functions for +//! AWS-specific types that are most useful to use `serde` with. + +/// `serde` implementation for [`Region`](aws_types::region::Region) +pub mod region { + use aws_types::region::Region; + use serde::{Deserializer, Serializer}; + + /// Provides a [`Serializer`] implementation to [`Region`]. This is mainly to be used + /// with the `#[serde(with)]` attribute when using serde's derive macros. It can be used for + /// your own serializers as well. + /// + /// ## Example + /// ```no_run + /// # use aws_types::region::Region; + /// # use serde::Serialize; + /// # + /// #[derive(Serialize)] + /// pub struct MyStruct { + /// #[serde(serialize_with = "noelware_serde::aws::region::serialize")] + /// region: Region, + /// } + /// ``` + pub fn serialize(value: &Region, serializer: S) -> Result { + // TODO(@auguwu): Same in src/s3.rs, do we allow this since the `Region` type is just a + // container of Cow<'static, str> (copy-on-write). For now, I guess it'll be the bare + // minimum, but do we collect all the valid AWS regions? (that would require work) + serializer.serialize_str(value.to_string().as_str()) + } + + /// Provides a [`Deserializer`] implementation to [`Region`]. This is mainly to be used + /// with the `#[serde(with)]` attribute when using serde's derive macros. It can be used for + /// your own serializers as well. + /// + /// ## Example + /// ```no_run + /// # use aws_types::region::Region; + /// # use serde::Serialize; + /// # + /// #[derive(Serialize)] + /// pub struct MyStruct { + /// #[serde(deserialize_with = "noelware_serde::aws::region::deserialize")] + /// region: Region, + /// } + /// ``` + pub fn deserialize<'de, D: Deserializer<'de>>(deserializer: D) -> Result { + use serde::Deserialize; + + let value = String::deserialize(deserializer)?; + Ok(Region::new(value)) + } +} diff --git a/crates/serde/src/lib.rs b/crates/serde/src/lib.rs new file mode 100644 index 0000000..925431a --- /dev/null +++ b/crates/serde/src/lib.rs @@ -0,0 +1,36 @@ +// 🐻‍❄️🪚 core-rs: Collection of Rust crates that are used by and built for Noelware's projects +// Copyright (c) 2024 Noelware, LLC. +// +// 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. + +#![doc(html_logo_url = "https://cdn.floofy.dev/images/trans.png")] +#![doc = include_str!("../README.md")] +#![cfg_attr(docsrs, feature(doc_cfg))] + +#[cfg(feature = "tracing")] +#[cfg_attr(docsrs, doc(cfg(feature = "tracing")))] +pub mod tracing; + +#[cfg(feature = "aws")] +#[cfg_attr(docsrs, doc(cfg(feature = "aws")))] +pub mod aws; + +#[cfg(feature = "s3")] +#[cfg_attr(docsrs, doc(cfg(feature = "s3")))] +pub mod s3; diff --git a/crates/serde/src/s3.rs b/crates/serde/src/s3.rs new file mode 100644 index 0000000..6c3d663 --- /dev/null +++ b/crates/serde/src/s3.rs @@ -0,0 +1,77 @@ +// 🐻‍❄️🪚 core-rs: Collection of Rust crates that are used by and built for Noelware's projects +// Copyright (c) 2024 Noelware, LLC. +// +// 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. + +//! Defines extra [`Serializer`](serde::ser::Serializer) and [`Deserializer`](serde::de::Deserializer) functions for +//! AWS S3 types that are most useful to use `serde` with. + +macro_rules! impl_methods { + ($mod:ident: $name:ident) => { + #[doc = concat!(" `serde` implementation for [`", stringify!($name), "`](aws_sdk_s3::types::", stringify!($name), ").")] + pub mod $mod { + #[doc = concat!(" Provides a [`Serializer`](serde::ser::Serializer) implementation to [`", stringify!($name), "`](aws_sdk_s3::types::", stringify!($name), "). This is mainly")] + /// to be used with the `with` serde attribute when using serde's derive macros. But, it can + /// be used with your own serializer. + /// + /// ## Example + /// ```no_run + #[doc = concat!(" #[serde(serialize_with = noelware_serde::s3::", stringify!($mod), "::serialize)]")] + #[doc = concat!(" # use aws_sdk_s3::types::", stringify!($name), ";")] + /// # use serde::Serialize; + /// # + /// #[derive(Serialize)] + /// pub struct MyStruct { + #[doc = concat!(" acl: ", stringify!($name), ",")] + /// } + /// ``` + pub fn serialize(value: &::aws_sdk_s3::types::$name, serializer: S) -> Result { + // TODO(@auguwu): I'm not sure if this is the right choice, but it does discuss that new variants + // shouldn't be errors, rather than be encouraged to be serialized for new SDK revisions, but + // should we allow unknown variants? For the moment, yes, but I'm not sure in the long-term. + serializer.serialize_str(value.as_str()) + } + + #[doc = concat!(" Provides a [`Deserializer`](serde::de::Deserializer) implementation to [`", stringify!($name), "`](aws_sdk_s3::types::", stringify!($name), "). This is mainly")] + /// to be used with the `with` serde attribute when using serde's derive macros. But, it can + /// be used with your own serializer. + /// + /// ## Example + /// ```no_run + #[doc = concat!(" # use aws_sdk_s3::types::", stringify!($name), ";")] + /// # use serde::Deserialize; + /// # + /// #[derive(Deserialize)] + /// pub struct MyStruct { + #[doc = concat!(" #[serde(deserialize_with = noelware_serde::s3::", stringify!($mod), "::deserialize)]")] + #[doc = concat!(" acl: ", stringify!($name), ",")] + /// } + /// ``` + pub fn deserialize<'de, D: ::serde::de::Deserializer<'de>>(deserializer: D) -> Result<::aws_sdk_s3::types::$name, D::Error> { + use ::serde::Deserialize; + + let value = String::deserialize(deserializer)?; + Ok(::aws_sdk_s3::types::$name::from(value.as_str())) + } + } + }; +} + +impl_methods!(objectcannedacl: ObjectCannedAcl); +impl_methods!(bucketcannedacl: BucketCannedAcl); diff --git a/crates/serde/src/tracing.rs b/crates/serde/src/tracing.rs new file mode 100644 index 0000000..9984967 --- /dev/null +++ b/crates/serde/src/tracing.rs @@ -0,0 +1,79 @@ +// 🐻‍❄️🪚 core-rs: Collection of Rust crates that are used by and built for Noelware's projects +// Copyright (c) 2024 Noelware, LLC. +// +// 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. + +//! Defines extra [`Serializer`] and [`Deserializer`] functions for [`tracing`]'s types that are most useful to use `serde` with. + +use serde::{ + de::{Deserializer, Error}, + ser::Serializer, + Deserialize, +}; +use tracing::Level; + +/// [`Serializer`] implementation for [`Level`]. +/// +/// ## Example +/// ```no_run +/// # use serde::Serialize; +/// # use tracing::Level; +/// # +/// #[derive(Serialize)] +/// pub struct MyStruct { +/// #[serde(serialize_with = "noelware_serde::tracing::serialize")] +/// level: Level, +/// } +/// ``` +pub fn serialize(filter: &Level, serializer: S) -> Result { + serializer.serialize_str(match *filter { + Level::TRACE => "trace", + Level::DEBUG => "debug", + Level::ERROR => "error", + Level::WARN => "warn", + Level::INFO => "info", + }) +} + +/// [`Deserializer`] implementation for [`Level`]. +/// +/// ## Example +/// ```no_run +/// # use serde::Deserialize; +/// # use tracing::Level; +/// # +/// #[derive(Deserialize)] +/// pub struct MyStruct { +/// #[serde(deserialize_with = "noelware_serde::tracing::deserialize_level")] +/// level: Level, +/// } +/// ``` +pub fn deserialize<'de, D: Deserializer<'de>>(deserializer: D) -> Result { + let string = String::deserialize(deserializer)?; + match string.to_lowercase().as_str() { + "trace" => Ok(Level::TRACE), + "debug" => Ok(Level::DEBUG), + "error" => Ok(Level::ERROR), + "info" => Ok(Level::INFO), + "warn" => Ok(Level::WARN), + level => Err(D::Error::custom(format!( + "wanted [trace, debug, error, info, warn]; received {level} instead" + ))), + } +} diff --git a/default.nix b/default.nix new file mode 100644 index 0000000..6d3862d --- /dev/null +++ b/default.nix @@ -0,0 +1,28 @@ +# 🐻‍❄️🪚 core-rs: Collection of Rust crates that are used by and built for Noelware's projects +# Copyright (c) 2024 Noelware, LLC. +# +# 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. +let + lockfile = builtins.fromJSON (builtins.readFile ./flake.lock); + compat = builtins.fetchTarball { + url = "https://github.com/edolstra/flake-compat/archive/${lockfile.nodes.flake-compat.locked.rev}.tar.gz"; + sha256 = "${lockfile.nodes.flake-compat.locked.narHash}"; + }; +in + (import compat {src = ./.;}).defaultNix.default diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..c25555c --- /dev/null +++ b/flake.lock @@ -0,0 +1,102 @@ +{ + "nodes": { + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1696426674, + "narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "0f9255e01c2351cc7d116c072cb317785dd33b33", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1701680307, + "narHash": "sha256-kAuep2h5ajznlPMD9rnQyffWG8EM/C73lejGofXvdM8=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "4022d587cbbfd70fe950c1e2083a02621806a725", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1704842529, + "narHash": "sha256-OTeQA+F8d/Evad33JMfuXC89VMetQbsU4qcaePchGr4=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "eabe8d3eface69f5bb16c18f8662a702f50c20d5", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-compat": "flake-compat", + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs", + "rust-overlay": "rust-overlay" + } + }, + "rust-overlay": { + "inputs": { + "flake-utils": [ + "flake-utils" + ], + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1705112162, + "narHash": "sha256-IAM0+Uijh/fwlfoeDrOwau9MxcZW3zeDoUHc6Z3xfqM=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "9e0af26ffe52bf955ad5575888f093e41fba0104", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..fd8b9f7 --- /dev/null +++ b/flake.nix @@ -0,0 +1,78 @@ +# 🐻‍❄️🪚 core-rs: Collection of Rust crates that are used by and built for Noelware's projects +# Copyright (c) 2024 Noelware, LLC. +# +# 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. +{ + description = "Collection of Rust crates that are used by and built for Noelware's projects"; + inputs = { + nixpkgs.url = github:NixOS/nixpkgs/nixpkgs-unstable; + flake-utils.url = github:numtide/flake-utils; + rust-overlay = { + url = github:oxalica/rust-overlay; + inputs = { + nixpkgs.follows = "nixpkgs"; + flake-utils.follows = "flake-utils"; + }; + }; + + flake-compat = { + url = github:edolstra/flake-compat; + flake = false; + }; + }; + + outputs = { + self, + nixpkgs, + flake-utils, + rust-overlay, + ... + }: + flake-utils.lib.eachDefaultSystem (system: let + pkgs = import nixpkgs { + inherit system; + + overlays = [(import rust-overlay)]; + }; + + stdenv = + if pkgs.stdenv.isLinux + then pkgs.stdenv + else pkgs.clangStdenv; + + rust = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml; + rustflags = + if stdenv.isLinux + then ''-C link-arg=-fuse-ld=mold -C target-cpu=native $RUSTFLAGS'' + else "$RUSTFLAGS"; + in { + devShells.default = pkgs.mkShell { + nativeBuildInputs = with pkgs; + [pkg-config] + ++ (lib.optional stdenv.isLinux [mold lldb]) + ++ (lib.optional stdenv.isDarwin [darwin.apple_sdk.frameworks.CoreFoundation]); + + buildInputs = with pkgs; [ + cargo-expand + openssl + rust + ]; + }; + }); +} diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 0000000..752b35c --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,34 @@ +# 🐻‍❄️🪚 core-rs: Collection of Rust crates that are used by and built for Noelware's projects +# Copyright (c) 2024 Noelware, LLC. +# +# 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. + + +[toolchain] +channel = "1.75" +profile = "minimal" +components = [ + "rustc", + "cargo", + "rust-analyzer", + "rust-src", + "rust-std", + "clippy", + "rustfmt", +] diff --git a/rustfmt.toml b/rustfmt.toml new file mode 100644 index 0000000..6db00a1 --- /dev/null +++ b/rustfmt.toml @@ -0,0 +1,27 @@ +# 🐻‍❄️🪚 core-rs: Collection of Rust crates that are used by and built for Noelware's projects +# Copyright (c) 2024 Noelware, LLC. +# +# 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. + +use_field_init_shorthand = true +match_arm_leading_pipes = "Preserve" +use_try_shorthand = true +newline_style = "Unix" # keep it consistent +max_width = 120 +edition = "2021" diff --git a/shell.nix b/shell.nix new file mode 100644 index 0000000..55de7bd --- /dev/null +++ b/shell.nix @@ -0,0 +1,28 @@ +# 🐻‍❄️🪚 core-rs: Collection of Rust crates that are used by and built for Noelware's projects +# Copyright (c) 2024 Noelware, LLC. +# +# 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. +let + lockfile = builtins.fromJSON (builtins.readFile ./flake.lock); + compat = builtins.fetchTarball { + url = "https://github.com/edolstra/flake-compat/archive/${lockfile.nodes.flake-compat.locked.rev}.tar.gz"; + sha256 = "${lockfile.nodes.flake-compat.locked.narHash}"; + }; +in + (import compat {src = ./.;}).shellNix.default