Skip to content

Add a size parameter for ConstGenericRingBuffer::new#110

Merged
jdonszelmann merged 1 commit into
NULLx76:mainfrom
tertsdiepraam:size-parameter-on-new
Sep 15, 2023
Merged

Add a size parameter for ConstGenericRingBuffer::new#110
jdonszelmann merged 1 commit into
NULLx76:mainfrom
tertsdiepraam:size-parameter-on-new

Conversation

@tertsdiepraam
Copy link
Copy Markdown
Contributor

@tertsdiepraam tertsdiepraam commented Jun 8, 2023

This is a minor ergonomic improvement which allows us to write:

ConstGenericRingBuffer::new::<5>()

instead of

ConstGenericRingBuffer::<_, 5>::new()

when the type can be inferred, saving a grand total of 2 characters (3 if you count the space)!

This trick (ab)uses From as a stand-in for an identity trait. This is probably fine, because there is only one possible implementation of the from method, which is the identity function, since From is guaranteed to be reflexive via a blanket impl.

@tertsdiepraam tertsdiepraam changed the title Add a size parameter for ConstGenericRingBuffer::new Add a size parameter for ConstGenericRingBuffer::new Jun 8, 2023
@tertsdiepraam tertsdiepraam force-pushed the size-parameter-on-new branch from da74f59 to fff586c Compare June 8, 2023 17:24
@jdonszelmann
Copy link
Copy Markdown
Collaborator

I kinda like this @NULLx76, what're your thoughts?

Comment thread tests/conversions.rs
@jdonszelmann jdonszelmann merged commit 5c75226 into NULLx76:main Sep 15, 2023
NULLx76 pushed a commit that referenced this pull request Jul 11, 2025
Add a size parameter for `ConstGenericRingBuffer::new`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants