Crates.io | functional_macro |
lib.rs | functional_macro |
version | 0.0.2 |
source | src |
created_at | 2023-12-03 10:58:45.592538 |
updated_at | 2023-12-03 11:00:26.560808 |
description | A functional macro for Rust |
homepage | |
repository | |
max_upload_size | |
id | 1056850 |
size | 18,559 |
This macro
is aimed to help enforce pure functions
.
While it does have known limitations (see below), we still believe it provides value to help keep mutation
in check.
function
arguments and check if they are mutable
(&mut
).function
as with an internal module
to prevent globals
usage.Original:
#[pure_functional]
fn foo(arg: i32) -> i32 {
arg + 1
}
Rewrite:
fn foo(arg: i32) -> i32 {
mod inner {
pub fn foo(arg: i32) -> i32 {
arg + 1
}
}
inner::foo(arg)
}
Any struct
that internally hides mutability
will not be caught by this macro
.
For example, the following struct
will not be caught by this macro
:
Arc<Mutex<T>>
.Cell<T>
.RefCell<T>
.RwLock<T>
.UnsafeCell<T>
.All of these wrap UnsafeCell<T>
internally, which is why they are not caught by this macro
.
async
functions are not supported.
&self
and &mut self
are not supported.