raylib-rs
raylib-rs copied to clipboard
[Suggestion] Use Clippy to improve code
Use Clippy in order to improve some parts of the library, notably, use a slice in functions instead of vectors. Why is that a problem? Well, this requires me to allocate a vector even if I could use an array, which could make the program slower. One example I have is with include_bytes!
macro, sometimes I just want to hardcode some sprites into the binary, but due to how picky Image::load_image_from_mem
is, I have to allocate a vector and then pass it to function.
That's fair. I haven't used Clippy before and I'm not sure how to set it up. I'll have to see about that.
Also, I'm not sure if Clippy can even lint this, but some functions that logically should not accept negative values accept i32
, like RaylibBuilder::size
, which makes no sense at all since there are no monitors with negative width/height, it just crashes in runtime if you attempt to give it a negative value.
Maybe use Into
trait for functions? A lot of times I have to convert some value back and forth, making functions accept values that implement Into
could make user experience more pleasant.
AKA something like this:
fn example(n: impl Into<u32>) -> u32 {
n.into()
}
and it tells you wether you're out of range or not at compile-time
example(255_u8); // Works
example(255_u64); // Might go out of bounds, thus `From<u64>` is not implemented for u32