-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Implement int_format_into
feature
#142098
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
base: master
Are you sure you want to change the base?
Conversation
Failed to set assignee to
|
assert_eq!(ret, value); | ||
|
||
let mut buffer = NumBuffer::<$int>::new(); | ||
assert_eq!(value.format_into(&mut buffer), s.as_str()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since format_into
is not part of a trait, I needed to switch from a function to a macro to avoid the generics limitations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could write and implement a trait right here, in the test - right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could indeed, but would be better than the current code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Less churn; other than that I don't have strong feelings.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If someone else agrees with you I'll make the change (lazyness++ 😆).
library/core/src/fmt/num_buffer.rs
Outdated
#[derive(Debug)] | ||
pub struct NumBuffer<T: NumBufferTrait> { | ||
// FIXME: Once const generics feature is working, use `T::BUF_SIZE` instead of 40. | ||
pub(crate) buf: [MaybeUninit::<u8>; 40], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was a great frustration to discover that I couldn't just use [MaybeUninit::<u8>; T::BUF_SIZE]
so until it's actually supported, they will all use the max size. 😞
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@programmerjake sketched an alternative in the ACP that works without const generic expressions. But it's complicated enough that I don't think it's worth it as long as the maximum is just 40 bytes. Between that and the fact that the type parameter on NumBuffer is only an unresolved question, not part of the approved ACP, I don't really see the point of including it in this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lqd provided me a way to do it so all solved now. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah sadly it breaks something else so it cannot. For reference here is the code showing the feature that was supposed to unlock the situation: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2024&gist=11cfd87eaeeef6481be6433123fc0caf (the min_generic_const_args
feature).
r? @Amanieu |
This comment has been minimized.
This comment has been minimized.
1d9a06e
to
2589402
Compare
d11cb44
to
70ab4e0
Compare
This comment has been minimized.
This comment has been minimized.
70ab4e0
to
3eecb24
Compare
3eecb24
to
2f869c5
Compare
Applied suggestions and opened another PR for the number of digits of u128 computation to not add even more changes to this PR. |
unsafe fn slice_buffer_to_str(buf: &[MaybeUninit<u8>], offset: usize) -> &str { | ||
// SAFETY: All buf content since offset is set. | ||
let written = unsafe { buf.get_unchecked(offset..) }; | ||
// SAFETY: Writes use ASCII from the lookup table exclusively. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this must be part of the precondition....? and the comment above should reference the precondition as well.
2f869c5
to
9324432
Compare
☔ The latest upstream changes (presumably #142133) made this pull request unmergeable. Please resolve the merge conflicts. |
I took over #138338 with @madhav-madhusoodanan's approval.
Since #136264, a lot of changes happened so I made use of them to reduce the number of changes.
ACP approval: rust-lang/libs-team#546 (comment)
Associated Issue
r? @hanna-kruppe