| Crates.io | inline-fn |
| lib.rs | inline-fn |
| version | 0.0.1 |
| created_at | 2025-03-11 21:52:57.605561+00 |
| updated_at | 2025-03-11 21:52:57.605561+00 |
| description | Inline the content of a function without duplicating code. Useful when duplicating code is desired but you are too embarrassed to do it manually. |
| homepage | |
| repository | https://github.com/mustakimali/inline-fn |
| max_upload_size | |
| id | 1588659 |
| size | 27,479 |
Inline the content of a function without duplicating code. Useful when duplicating code is desired but you are too embarrassed to do it manually.
You have a function that you want to inline
// src/lib.rs
fn world() -> String {
"world".to_string()
}
Use the inline-fn crate to inline the content of a function without duplicating code.
// Option 1: Specify the path to the file containing the function
// relative to the workspace root.
let greetings = format!("Hello, {}", inline_fn!(world, "src/lib.rs"));
// Option 2: Recursively search all files in the workspace root.
// This has an impact on performance.
let greetings = format!("Hello, {}", inline_fn!(world));
Option 2 has an impact on performance until rust-lang#54725 is implemented
It's particularly useful for tests where one test is built on top of another.
#[test]
fn payment_works() {
let payment = payment(100);
assert_eq!(payment.value, 100);
// (very long function body)
}
#[test]
fn refund_works() {
inline_fn!(payment_works, "src/lib.rs"); // expands to the content of the previous fn
let refund = refund(payment.id);
assert_eq!(refund.value, payment.value);
}