Use default type parameter for LocatedSpan #51
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Thanks for the help with my previous pull request! I have decided to create another one for something small that has been bugging me for a bit...
When the addition of extra information to
LocatedSpan
was implemented, a newLocatedSpanEx
struct was added which includes anextra
property with generic parameterX
. Consequently, the originalLocatedSpan
has become a type alias whereX
is set to the empty type()
.However, this is unnecessary as for some time default type parameters have been allowed — see the relevant page in the Rust book for more information on how these can be used. I have simplified the types by renaming
LocatedSpanEx
back toLocatedSpan
and adding a default type of()
for the genericX
parameter.It may be important to allow for backwards compatibility so I have recreated
LocatedSpanEx
as a type alias ofLocatedSpan
(which can be removed in a future release). I have marked it with a deprecation warning since all uses can now be replaced withLocatedSpan
. The remainder of the codebase, including documentation and testcases, has also been updated to simply useLocatedSpan
.Additionally, on an unrelated note, I have fixed a
FIXME
issue in the testcases whereby the following line was not working.The issue is that
b"foo"
has type&[u8; 3]
whereasb"foobar"
has type&[u8]
as it is implicitly casted due to the type signature ofByteSpan::new
. The solution is to perform the same treatment tob"foo"
, which must be done with an explicit cast.Please let me know if I can clarify anything or if there are any questions or issues with this 😄