| Crates.io | using-param |
| lib.rs | using-param |
| version | 0.1.2 |
| created_at | 2025-07-22 11:18:45.408431+00 |
| updated_at | 2025-07-22 11:57:07.860569+00 |
| description | Add parameters, generics and return types to all functions in the impl block |
| homepage | |
| repository | https://github.com/A4-Tacks/using-param-rs |
| max_upload_size | |
| id | 1763423 |
| size | 19,935 |
Add parameters, generics and return types to all functions in the impl block
Add parameters
struct Foo(i32);
#[using_param::using_param(&self, other: &Foo)]
#[using_param::using_return(bool)]
impl PartialEq for Foo {
fn eq() { self.0 == other.0 }
fn ne() { self.0 != other.0 }
}
assert!(Foo(2) == Foo(2));
assert!(Foo(2) != Foo(3));
Default self parameter
struct Foo(i32);
#[using_param::using_param(self)]
impl Foo {
fn use_ref(&self) -> i32 { self.0 }
fn use_owned() -> i32 { self.0 }
}
let foo = Foo(3);
assert_eq!(foo.use_ref(), 3);
assert_eq!(foo.use_owned(), 3);
Default return type
struct Foo(i32);
#[using_param::using_return(i32)]
impl Foo {
fn use_ref(&self) -> i32 { self.0 }
fn use_owned(self) { self.0 }
}
let foo = Foo(3);
assert_eq!(foo.use_ref(), 3);
assert_eq!(foo.use_owned(), 3);
Add parameters before all parameters
struct Foo(f64);
#[using_param::using_param(other: Foo)]
impl Foo {
fn div_with(this: Foo) -> f64 { this.0 / other.0 }
}
assert_eq!(Foo::div_with(Foo(8.0), Foo(4.0)), 0.5);
Add parameters after all parameters
struct Foo(f64);
#[using_param::using_param(, other: Foo)]
impl Foo {
fn div(this: Foo) -> f64 { this.0 / other.0 }
}
assert_eq!(Foo::div(Foo(8.0), Foo(4.0)), 2.0);
Add generic parameters
struct Foo;
#[using_param::using_generic(, U: Default)]
impl Foo {
fn foo() -> U { U::default() }
fn bar<T: Default>() -> (T, U) { (T::default(), U::default()) }
}
assert_eq!(Foo::foo::<i32>(), 0);
assert_eq!(Foo::bar::<i32, &str>(), (0, ""));