-
Notifications
You must be signed in to change notification settings - Fork 185
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
Add tinystr-neo to experimental/ #1508
Changes from 1 commit
8c13b98
ad88484
3044449
1361678
510c57a
73a799d
6bfbfc3
2cdeab3
347c955
601787d
d009c19
2d9e801
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,8 +6,13 @@ | |
macro_rules! tinystr { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thought: We maybe don't need the macro any more. People can just use the const function constructors directly. Fewer imports and friendlier to the compiler. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So as mentioned in #1511 (comment) , I think it's important to give users a convenient way to call this in a const context, given that it's rare and unusual for Rust programmers to MBEs (non proc macros, like this one) are pretty friendly to the compiler; and this is going to be even smaller once I rebase over the rust update. I don't find that argument that compelling. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, |
||
($n:literal, $s:literal) => {{ | ||
// Force it into a const context; otherwise it may get evaluated at runtime instead. | ||
const TINYSTR_MACRO_CONST: $crate::TinyAsciiStr<$n> = | ||
$crate::TinyAsciiStr::from_str_panicky($s); | ||
const TINYSTR_MACRO_CONST: $crate::TinyAsciiStr<$n> = { | ||
match $crate::TinyAsciiStr::from_bytes($s.as_bytes()) { | ||
Ok(s) => s, | ||
// Cannot format the error since formatting isn't const yet | ||
Err(_) => panic!(concat!("Failed to construct tinystr from ", $s)), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Praise: Good idea to use |
||
} | ||
}; | ||
TINYSTR_MACRO_CONST | ||
}}; | ||
} | ||
|
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.
note: previously we were able to use
.trailing_zeroes()
/leading_zeroes()
which are a single instruction. If rustc unrolls this loop for small N we should also be fine here, but I'm not sure if that's happening, we should bench this.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.
Yeah; this is one of the things I was wondering how we would implement efficiently. We should definitely test. I think this would be a good thing for IAI as opposed to Clippy.