Skip to content
This repository has been archived by the owner on Feb 14, 2023. It is now read-only.

The scope of the unsafe block can be appropriately reduced #21

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

peamaeq
Copy link

@peamaeq peamaeq commented Jun 23, 2022

In these functions you use the unsafe keyword for some safe expressions. However, I found that only 3 functions are real unsafe operations (see the list below).

We need to mark unsafe operations more precisely using unsafe keyword. Keeping unsafe blocks small can bring many benefits. For example, when mistakes happen, we can locate any errors related to memory safety within an unsafe block. This is the balance between Safe and Unsafe Rust. The separation is designed to make using Safe Rust as ergonomic as possible, but requires extra effort and care when writing Unsafe Rust.
Real unsafe operation list:

  1. the write_buf()\set_len()\move_head() function(these are unsafe functions)

@abonander
Hope this PR can help you.
Best regards.
References
https://doc.rust-lang.org/nomicon/safe-unsafe-meaning.html
https://doc.rust-lang.org/book/ch19-01-unsafe-rust.html

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant