Implement feature char_to_u32#158940
Conversation
|
r? @JohnTitor rustbot has assigned @JohnTitor. Use Why was this reviewer chosen?The reviewer was selected based on:
|
| ToCasefold(CaseMappingIter::new(conversions::to_casefold(self))) | ||
| } | ||
|
|
||
| /// Returns the value of `self` as a `u32`. |
There was a problem hiding this comment.
The "value of a char as u32" is not necessarily obvious, let's spell out that this returns the code point value (cf. wording in the reference).
There was a problem hiding this comment.
Agree, the wording was weak and that's a better suggestion.
Pushed in 77d7cf2
| /// let heart = '❤'; | ||
| /// | ||
| /// assert_eq!(ascii.to_u32(), 97_u32); | ||
| /// assert_eq!(heart.to_u32(), 0x2764_u32); |
There was a problem hiding this comment.
Not 100% convinced this is needed, but it might be useful to show off that this is the inverse of char::from_u32 because the number looks completely arbitrary on its own.
assert_eq!(char::from_u32(heart.to_u32()), Some(heart));(Possibly the round-tripping deserves a separate example with its own introduction.)
There was a problem hiding this comment.
I felt like this needed an example but wasn't sure exactly what to write. I can note this in the tracking issue as an area for improvement before stabilization.
|
@rustbot author |
|
Reminder, once the PR becomes ready for a review, use |
Add method `char::to_u32` which returns the underlying value of `char`.
|
@bors r+ rollup |
Implement feature `char_to_u32` Accepted ACP: rust-lang/libs-team#778 (comment) Tracking issue: rust-lang#158938 Add method `char::to_u32` which returns the underlying value of `char`.
Implement feature `char_to_u32` Accepted ACP: rust-lang/libs-team#778 (comment) Tracking issue: rust-lang#158938 Add method `char::to_u32` which returns the underlying value of `char`.
Implement feature `char_to_u32` Accepted ACP: rust-lang/libs-team#778 (comment) Tracking issue: rust-lang#158938 Add method `char::to_u32` which returns the underlying value of `char`.
…uwer Rollup of 21 pull requests Successful merges: - #150946 (intrinsics: Add a fallback for non-const libm float functions) - #158510 (Enable `static_position_independent_executables` on all gnu and musl targets) - #158541 (Move `std::io::Write` to `core::io`) - #158899 (Fix `unaligned_volatile_store` by removing `MemFlags::UNALIGNED`) - #155429 (Support `u128`/`i128` c-variadic arguments) - #156370 (Reject linked dylib EII default overrides) - #156508 (Infer all anonymous lifetimes in assoc consts as `'static`) - #158617 (allow mGCA const arguments to fall back to anon consts) - #158645 (Fix splat ICEs and ban it in closures) - #158859 (Improve `-Zls` diagnostic message on `.rs` files) - #158988 (Redo `TokenStreamIter`) - #158347 (Improve generic parameters handling for #[diagnostic::on_const]) - #158722 (delegation: do not always inherit `ConstArgHasType` predicates) - #158739 (view-types: HIR lowering) - #158883 (tests: fix enum-match.rs to handle LLVM 23) - #158886 (Add documentation for the `no_std` attribute) - #158940 (Implement feature `char_to_u32`) - #158951 (Merge three `MaxUniverse`s into one) - #158961 (Reapply "LLVM 23: Run AssignGUIDPass in some places") - #158996 ([compiler] Implement `PartialOrd` via `Ord` for `Span` and newtype_indexes) - #159005 (Use `as_lang_item` instead of repeatedly matching)
Implement feature `char_to_u32` Accepted ACP: rust-lang/libs-team#778 (comment) Tracking issue: rust-lang#158938 Add method `char::to_u32` which returns the underlying value of `char`.
…uwer Rollup of 24 pull requests Successful merges: - #150946 (intrinsics: Add a fallback for non-const libm float functions) - #158510 (Enable `static_position_independent_executables` on all gnu and musl targets) - #158541 (Move `std::io::Write` to `core::io`) - #158899 (Fix `unaligned_volatile_store` by removing `MemFlags::UNALIGNED`) - #156027 (Consider captured regions for opaque type region liveness.) - #156370 (Reject linked dylib EII default overrides) - #156508 (Infer all anonymous lifetimes in assoc consts as `'static`) - #157561 (rustdoc: do not include extra stuff in span) - #158617 (allow mGCA const arguments to fall back to anon consts) - #158645 (Fix splat ICEs and ban it in closures) - #158859 (Improve `-Zls` diagnostic message on `.rs` files) - #158988 (Redo `TokenStreamIter`) - #158347 (Improve generic parameters handling for #[diagnostic::on_const]) - #158384 (Allow BackwardIncompatibleDropHint in polonius legacy) - #158722 (delegation: do not always inherit `ConstArgHasType` predicates) - #158739 (view-types: HIR lowering) - #158877 (borrowck: Keep returned `path` from `best_blame_constraint()` consistent) - #158883 (tests: fix enum-match.rs to handle LLVM 23) - #158886 (Add documentation for the `no_std` attribute) - #158940 (Implement feature `char_to_u32`) - #158951 (Merge three `MaxUniverse`s into one) - #158961 (Reapply "LLVM 23: Run AssignGUIDPass in some places") - #158995 (Use REST API in linkchecker script) - #158996 ([compiler] Implement `PartialOrd` via `Ord` for `Span` and newtype_indexes)
Implement feature `char_to_u32` Accepted ACP: rust-lang/libs-team#778 (comment) Tracking issue: rust-lang#158938 Add method `char::to_u32` which returns the underlying value of `char`.
Rollup of 24 pull requests Successful merges: - #150946 (intrinsics: Add a fallback for non-const libm float functions) - #158541 (Move `std::io::Write` to `core::io`) - #156027 (Consider captured regions for opaque type region liveness.) - #156370 (Reject linked dylib EII default overrides) - #156508 (Infer all anonymous lifetimes in assoc consts as `'static`) - #157561 (rustdoc: do not include extra stuff in span) - #158617 (allow mGCA const arguments to fall back to anon consts) - #158645 (Fix splat ICEs and ban it in closures) - #158859 (Improve `-Zls` diagnostic message on `.rs` files) - #158988 (Redo `TokenStreamIter`) - #158347 (Improve generic parameters handling for #[diagnostic::on_const]) - #158384 (Allow BackwardIncompatibleDropHint in polonius legacy) - #158722 (delegation: do not always inherit `ConstArgHasType` predicates) - #158739 (view-types: HIR lowering) - #158877 (borrowck: Keep returned `path` from `best_blame_constraint()` consistent) - #158883 (tests: fix enum-match.rs to handle LLVM 23) - #158886 (Add documentation for the `no_std` attribute) - #158940 (Implement feature `char_to_u32`) - #158951 (Merge three `MaxUniverse`s into one) - #158960 (Fix bootstrap submodule path prefix matching) - #158961 (Reapply "LLVM 23: Run AssignGUIDPass in some places") - #158995 (Use REST API in linkchecker script) - #158996 ([compiler] Implement `PartialOrd` via `Ord` for `Span` and newtype_indexes) - #159036 (bootstrap: expand '@argfile' arguments to rustc shim)
Rollup merge of #158940 - okaneco:char_to_u32, r=hanna-kruppe Implement feature `char_to_u32` Accepted ACP: rust-lang/libs-team#778 (comment) Tracking issue: #158938 Add method `char::to_u32` which returns the underlying value of `char`.
Accepted ACP: rust-lang/libs-team#778 (comment)
Tracking issue: #158938
Add method
char::to_u32which returns the underlying value ofchar.