-
Notifications
You must be signed in to change notification settings - Fork 13
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
Introduce a Clearable
trait to support unsized types
#5
Conversation
Adds support for unsized types and provides a possible answer to cesarb#3 However, the `impl<T> Clearable for T where T: Copy` remains problematic because `Shared<T>: Copy`. There are worse implementers for `Default` like `Box`, `Arc`, and `Rc`, but we could avoids all current pointer types with `impl<T> Clearable for T where T: Copy+Default`.
I feel supporting fixed length arrays is more important right now. Rust might have type level numerics and Default for fixed lenght arrays before it gets a garbage collector or other dangerous types based on `Shared<T>`. This reverts commit ccb563e.
We should probably add some tests for unsized types besides the |
Also move Drop closer to defition for readability and so that AsRef and AsMut are closer to Deref and DerefMut. Remove spurious use in test
Added |
We can use a `ClearOnDrop` as the key for a `HashMap` with this change.
I should likely make this Just fyi, I tried two tricks to make |
This limits how one can implement Clerable, but avoids the T: ?Sized bounds added by e53f1b2 to hide_mem which might not work. See: cesarb#6 and http://llvm.org/docs/LangRef.html#indirect-inputs-and-outputs Also generalizes impl Clearable for [T] from T: Copy to T: Clearable
This might address the concerns exlained in cesarb#3 (comment) and cesarb#7 This reverts commit 88b4c4f. Conflicts: src/clearable.rs
Just changed how unsized arrays are handled to hopefully deal with #6 (comment) I have not tried to verify that I maybe delt with #7 (comment) too, which required adding |
I'm not confident what should be marked unsafe in the Also |
I went in a slightly different direction (inspired by this pull request) with commit 517686e, and now allow With that change, this pull request will become hopelessly tangled, so I'll close it now; please open a new one based on the current master if there are still things to change. I'll probably release 0.2 in a few days. |
Introduce a
Clearable
trait to support unsized types. Addresses the most concerns in #3 as well, including the warning by @bluss that assignment might not zero everything #3 (comment)I decided to implement
Clearable
for allSized+Copy
types becauseShared<T>
is the only dangerousCopy
type I could find. there are many pointer types that satisfyDefault
butShared<T>
does not, so we can avoid all current pointer types if we usedimpl Clearable T where T: Copy+Default
instead.I added this in ccb563e but reverted it in 88b4c4f because
Shared<T>
does not seem so dangerous right now. I'd hope Rust gets type-level numerics before any new dangerousShared<T>
abstractions and any such abstractions are likely to satisfyDefault
anyways.We do drop a zeroed object as a result of reverting the
Default
bounds, but afaik the worst case would be dropping a zeroedShared<T>
, whish does nothing itself. If anything worse happens, then you can revert the revert 88b4c4f of course. :)