diff options
Diffstat (limited to 'vendor/please')
| -rw-r--r-- | vendor/please/.cargo-checksum.json | 1 | ||||
| -rw-r--r-- | vendor/please/.github/workflows/ci.yml | 16 | ||||
| -rw-r--r-- | vendor/please/Cargo.lock | 7 | ||||
| -rw-r--r-- | vendor/please/Cargo.toml | 29 | ||||
| -rw-r--r-- | vendor/please/README.md | 57 | ||||
| -rw-r--r-- | vendor/please/src/lib.rs | 43 |
6 files changed, 153 insertions, 0 deletions
diff --git a/vendor/please/.cargo-checksum.json b/vendor/please/.cargo-checksum.json new file mode 100644 index 00000000..ac005ea2 --- /dev/null +++ b/vendor/please/.cargo-checksum.json @@ -0,0 +1 @@ +{"files":{".github/workflows/ci.yml":"c26a738b20a18cbb3251809a6e67544e0abda0ff67321000d2dcbafe9f3f93e5","Cargo.lock":"d76eec5d76f838377902dbecbc66fbec353c08b9acd5fe7fb40efc18a45c0bbc","Cargo.toml":"eeb487a5d0f8cfea2b765b0a97997ae24b2aae4b8c69fb7e03f27a54b233fc61","README.md":"aa5df1cffaa6005230cd224c5b7fd4eb949924a5b0c7f305b2685d041a513653","src/lib.rs":"64c27e67267b3b5e77e26bf128dade9bbc4309ca9c49049a7fa7fad8806babfa"},"package":null}
\ No newline at end of file diff --git a/vendor/please/.github/workflows/ci.yml b/vendor/please/.github/workflows/ci.yml new file mode 100644 index 00000000..38e19177 --- /dev/null +++ b/vendor/please/.github/workflows/ci.yml @@ -0,0 +1,16 @@ +name: CI +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] +env: + CARGO_TERM_COLOR: always +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - run: cargo build --verbose + - run: cargo test --verbose + diff --git a/vendor/please/Cargo.lock b/vendor/please/Cargo.lock new file mode 100644 index 00000000..02329551 --- /dev/null +++ b/vendor/please/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "please" +version = "0.1.0" diff --git a/vendor/please/Cargo.toml b/vendor/please/Cargo.toml new file mode 100644 index 00000000..aeed11f6 --- /dev/null +++ b/vendor/please/Cargo.toml @@ -0,0 +1,29 @@ +# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO +# +# When uploading crates to the registry Cargo will automatically +# "normalize" Cargo.toml files for maximal compatibility +# with all versions of Cargo and also rewrite `path` dependencies +# to registry (e.g., crates.io) dependencies. +# +# If you are reading this file be aware that the original Cargo.toml +# will likely look very different (and much more reasonable). +# See Cargo.toml.orig for the original contents. + +[package] +edition = "2024" +name = "please" +version = "0.1.0" +build = false +autolib = false +autobins = false +autoexamples = false +autotests = false +autobenches = false +readme = "README.md" +license = "MIT" + +[lib] +name = "please" +path = "src/lib.rs" + +[dependencies] diff --git a/vendor/please/README.md b/vendor/please/README.md new file mode 100644 index 00000000..6645b640 --- /dev/null +++ b/vendor/please/README.md @@ -0,0 +1,57 @@ +# please + +A simple Rust library providing convenient builder pattern utilities. + +## Overview + +`please` offers two main functions for creating and initializing objects: + +- `build()` - Creates a new instance using the type's `Default` implementation +- `build_with()` - Creates a new instance and applies a custom initializer function + +## Usage + +Add this to your `Cargo.toml`: + +```toml +[dependencies] +please = "0.1.0" +``` + +### Examples + +Basic usage with `build()`: + +```rust +use please::build; + +#[derive(Default)] +struct Person { + name: String, + age: i32, +} + +let person = build::<Person>(); +// Creates Person { name: "", age: 0 } +``` + +Custom initialization with `build_with()`: + +```rust +use please::build_with; + +let person = build_with(|p: &mut Person| { + p.name = String::from("Alice"); + p.age = 30; +}); +// Creates Person { name: "Alice", age: 30 } +``` + +## Requirements + +- Rust 2024 edition +- Types must implement `Default` trait + +## License + +MIT
\ No newline at end of file diff --git a/vendor/please/src/lib.rs b/vendor/please/src/lib.rs new file mode 100644 index 00000000..e4be8332 --- /dev/null +++ b/vendor/please/src/lib.rs @@ -0,0 +1,43 @@ +pub fn build<T: Default>() -> T { + T::default() +} + +pub fn build_with<T, F>(initializer: F) -> T +where + T: Default, + F: std::ops::FnOnce(&mut T), +{ + let mut item = build::<T>(); + initializer(&mut item); + item +} + +#[cfg(test)] +mod tests { + use super::*; + + #[derive(Default)] + struct Person { + name: String, + age: i32, + } + + #[test] + fn build_test_it_builds_a_new_instance_with_default_values() { + let item = build::<Person>(); + + assert_eq!(item.name, ""); + assert_eq!(item.age, 0); + } + + #[test] + fn build_with_test_initializes_the_new_instance() { + let item = build_with(|item: &mut Person| { + item.name = String::from("pidge"); + item.age = 42; + }); + + assert_eq!(item.name, "pidge"); + assert_eq!(item.age, 42); + } +} |
