Implement StaticString trait to produce &'static str from symbol types#159
Merged
soareschen merged 17 commits intomainfrom Sep 16, 2025
Merged
Implement StaticString trait to produce &'static str from symbol types#159soareschen merged 17 commits intomainfrom
StaticString trait to produce &'static str from symbol types#159soareschen merged 17 commits intomainfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
This PR introduces the
StaticStringtrait, which makes it possible to produce a&'static strvalue from a generic symbol type:As an example, the type
Symbol!("abc")would implementStaticStringwith"abc"asVALUE.Symbol Type
The
&'static strvalue is produced as aconstthrough const evaluation. To support the const creation of strings, theSymbol!macro has been modified to include the byte length of the string inside the expansion. For example,Symbol!("abc")would be expanded into:The
Symboltype is defined as:which basically attaches the byte length of the string as metadata. This is needed for now, as it is not possible to make use of the calculation of the byte length through const generics evaluation inside a type expression like
[u8; T::LEN]. On the other hand, by including theLENexplicitly, we can avoid doing any const evaluation and use that to produce[u8; LEN].ψandζAliasesThe new
Symboltype hasψas its alias, and the alias forCharhas been changed fromιtoζ. So with this, the typeSymbol!("abc")is shown as the following inside macro expansion:The reason we renamed
ιtoζforCharis becauseιwill trigger theconfusable_identswarning in Rust if the user code contains the use ofias an identifier.