Skip to content

rust: implement PointerWrapper for unit type. #584

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

Merged
merged 1 commit into from
Dec 2, 2021

Conversation

wedsonaf
Copy link

@wedsonaf wedsonaf commented Dec 2, 2021

This is useful for cases when we don't need to store any information as
context. Implementing PointerWrapper for () allows us to directly
use it as the context type.

Signed-off-by: Wedson Almeida Filho [email protected]

@bjorn3
Copy link
Member

bjorn3 commented Dec 2, 2021

as opposed to, for example, Box<()>, which would require an allocation.

Box and Vec don't allocate for ZST's. Instead they cast an integer to a pointer. (the alignment of the type to be precise. this gives a non-null aligned pointer)

@wedsonaf
Copy link
Author

wedsonaf commented Dec 2, 2021

as opposed to, for example, Box<()>, which would require an allocation.

Box and Vec don't allocate for ZST's. Instead they cast an integer to a pointer. (the alignment of the type to be precise. this gives a non-null aligned pointer)

This is interesting. So if we have two instances of Box where T is a ZST, we can't tell them apart?

@bjorn3
Copy link
Member

bjorn3 commented Dec 2, 2021

Correct.

This is useful for cases when we don't need to store any information as
context. Implementing `PointerWrapper` for `()` allows us to directly
use it as the context type.

Signed-off-by: Wedson Almeida Filho <[email protected]>
@wedsonaf wedsonaf force-pushed the unit-pointer-wrapper branch from 0a6e577 to 104fa4f Compare December 2, 2021 16:14
@wedsonaf
Copy link
Author

wedsonaf commented Dec 2, 2021

PTAL.

  • Updated commit message to remove claim that Box<()> allocates memory.
  • Return 1 as the pointer value now.
  • Fixed clippy errors (omitting () as the return value).

@wedsonaf
Copy link
Author

wedsonaf commented Dec 2, 2021

Correct.

I need to review the LockedBy code to make sure all pointer comparisons there are expected to work then.

@wedsonaf wedsonaf merged commit a3fb8b8 into Rust-for-Linux:rust Dec 2, 2021
@wedsonaf wedsonaf deleted the unit-pointer-wrapper branch December 2, 2021 16:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants