Skip to content

Commit 863e282

Browse files
Minor docs. Before reverting back to single unsafe_method macro and using if false branching.
1 parent 2026438 commit 863e282

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"markdownlint.config": {
33
"first-line-heading": false,
4-
"blanks-around-headings": false
4+
"blanks-around-headings": false,
5+
"blanks-around-lists": false
56
}
67
}

README.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,14 @@ const fn return_fn_returning_bool() -> fn() -> bool {
3838

3939
# unsafe_method_***
4040

41-
Unfortunately, Rust language limitations don't allow us to have one macro for methods that with
42-
receiver `self` being a shared reference `&self`, a mutable reference `&mut self` or a value `self`.
43-
We need to use three different macros: `unsafe_method_ref`, `unsafe_method_mut` and
44-
`unsafe_method_val`.
41+
Unfortunately, Rust macros can't have access to the type system. So they can't differentiate whether
42+
a method's receiver is a shared reference `&self`, a mutable reference `&mut self` or a value
43+
`self`.
44+
45+
We need to use three different macros:
46+
- `unsafe_method_ref`,
47+
- `unsafe_method_mut` and
48+
- `unsafe_method_val`.
4549

4650
# unsafe_method_ref and unsafe_method_mut in const
4751

src/lib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,9 @@ pub trait AsRefOrMut {
215215
}
216216
impl<T> AsRefOrMut for T {}
217217

218-
/// Invoke an unsafe method that has a shared `Self` reference as a receiver: `&self`. Like
219-
/// [unsafe_fn], but:
218+
/// Invoke an unsafe method that has a shared reference as a receiver: `&self`.
219+
///
220+
/// Like [unsafe_fn], but
220221
/// - This accepts a receiver `&self`, `&mut self` and `self` (which is then referenced, so it's
221222
/// **not** moved/copied).
222223
/// - This stores `self` in a variable outside of the generated `unsafe {...}`.

0 commit comments

Comments
 (0)