-
Notifications
You must be signed in to change notification settings - Fork 88
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement safer pixel data functions #322
Conversation
Ok, i might still be testing this by the time you see this @crumblingstatue I'm uploading some debug code, so my cargo build can see it off my branch |
ea1dda3
to
2b5f38f
Compare
Finally done testing. Here is the test code i used: use sfml::graphics::{Color, Image};
fn main() {
let mut image = Image::new(64, 64);
for x in 0..64 {
for y in 0..64 {
match image.set_pixel(x, y, Color::RED) {
Ok(_) => (),
Err(e) => {
let error_message = format!("{}", e);
println!("{}", error_message);
}
};
match image.pixel_at(x, y) {
Some(_) => (),
None => {
println!("no pixel at x:{} y:{}", x, y);
}
}
}
}
} |
2b5f38f
to
bdf6236
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall I approve of adding safe variants of these functions.
Just a few nitpicks.
bdf6236
to
4c2467f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some more nitpicks, sorry.
I believe that it is unnecessary for the user to use unsafe functions when it can easily be implemented with safe functionality. This is an example of doing it safely with a small abstraction. Rust is all about safe code, not unsafe code. Such a simple abstraction should be hidden from the user
4c2467f
to
9bf14a1
Compare
Cargo fmt caught something in |
Thank you for your contribution! I merged it manually in 3c732e8 |
I believe that it is unnecessary for the user to use unsafe functions when it can easily be implemented with safe functionality. This is an example of doing it safely with a small abstraction. Rust is all about safe code, not unsafe code. Such a simple abstraction should be hidden from the user
Note not inside of commit:
I haven't tested it. I'll test it soon and leave a comment that I have tested it's functionality.
This will be a breaking change, but I believe it is for the better. People using these functions will have to change their code and decide whether they want to use the unchecked or standard version of the function.