Skip to content
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

Add size_of and size_of_val and align_of and align_of_val to the prelude #123168

Merged
merged 1 commit into from
Jun 5, 2024

Commits on May 13, 2024

  1. Add size_of, size_of_val, align_of, and align_of_val to the p…

    …relude
    
    Many, many projects use `size_of` to get the size of a type. However,
    it's also often equally easy to hardcode a size (e.g. `8` instead of
    `size_of::<u64>()`). Minimizing friction in the use of `size_of` helps
    ensure that people use it and make code more self-documenting.
    
    The name `size_of` is unambiguous: the name alone, without any prefix or
    path, is self-explanatory and unmistakeable for any other functionality.
    Adding it to the prelude cannot produce any name conflicts, as any local
    definition will silently shadow the one from the prelude. Thus, we don't
    need to wait for a new edition prelude to add it.
    
    Add `size_of_val`, `align_of`, and `align_of_val` as well, with similar
    justification: widely useful, self-explanatory, unmistakeable for
    anything else, won't produce conflicts.
    joshtriplett committed May 13, 2024
    Configuration menu
    Copy the full SHA
    a5a60d7 View commit details
    Browse the repository at this point in the history