-
Notifications
You must be signed in to change notification settings - Fork 3
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
Delegate to Chars
and CharIndices
#4
Conversation
src/lib.rs
Outdated
// First, move the string | ||
let mut owned = $struct { | ||
s: s, | ||
i: unsafe { uninitialized() } |
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.
My personal "unsafe code policy" is that when leaving an unsafe
block, the invariants that we are screwing with should be restored. So could you just merge these two blocks so that lines 52-60 are under one unsafe
?
src/lib.rs
Outdated
// Then, we can call .chars, which with have the same lifetime | ||
// of the owner. We need the transmute to "widen" the lifetime | ||
// into 'static which would allow us to store it in the owner. | ||
owned.i = unsafe { transmute(owned.s.$method()) }; |
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'd prefer to write it as transmute::<Chars, Chars<'static>(...)
just to be explicit that it's only changing the lifetime, but that'd require an extra parameter to the macro...
Looks great! Happy to be an early adopter of your macro :) I meant to respond to your original issue, sorry for dropping that ball. If you can make that small change to the unsafe code I'll merge! |
Fixed! |
Awesome. I'll publish a new version soon, I guess it ought to be a minor version due to the |
Don’t worry about it! We should probably work on RFC-ing this into stdlib though 😄 |
Yeah, I'm not sure about the struct names but it seems like a pretty small
RFC.
…On Sun, May 20, 2018 at 9:53 PM, Godfrey Chan ***@***.***> wrote:
Don’t worry about it! We should probably work on RFC-ing this into stdlib
though 😄
—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub
<#4 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAC3nxbeH5bwZ7TUrr9VyyNozg_9rCLWks5t0h4ygaJpZM4UFihb>
.
|
Hello from the future... I was a Rust novice at the time, and didn't realize until two years later when nightly started complaining about |
Closes #3
I did end up making a
delegate
create, so I figured I would put this together quickly to see how it feels in real code. Unfortunately, as @doomrobo pointed out in #2, there isn't a good way to implementclone
since the state/pointers are not managed by us anymore.