-
Notifications
You must be signed in to change notification settings - Fork 12
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
slice-dst
: Provide example for custom 'slices' using SliceWithHeader
#69
Comments
If you don't mind third parties being able to perform the cast safely, the ref-cast crate automates the required bits to cast from It's still on my todo list to make a #[derive(SliceDst)]
#[repr(C)]
#[slice_dst(new(Info, &[u8]))]
struct MyStr(Info, [u8]); and get a custom type like |
Is there something specific I can call out in the documentation to help direct people towards the correct practice for this? It's pretty much standard requirement for wrappers around unsized types to know how/when you can go from |
Thank you. That helped a lot. Pulling in a third-party crate to ensure soundness seems feasible to me. |
To go a little bit further and to stay with the |
You would need to track the initialized prefix and handle reallocation. Actually, implementing our own Unfortunately I don't really have the time (or the clear freedom) to write up such a walkthrough / book-format material right now, but I'd be happy to mentor/guide/edit/review someone else doing so. |
The basic formula: Store Capacity is the length of your Probably the best format to show off the tools I'm providing would be to write a |
Okay, this looks manageable to me. I think I'll give it a try when I find the time... after I looked into my own university contract 😅 |
Thank you for this awesome crate. I always respect when people dive into the
unsafe
world of Rust.I'd like to use the
slice-dst
crate to build something similar toString
andstr
. Let's assume:To mimicry
str
I want to implementBorrow<MyStr> for MyString
andToOwned for MyStr
(type Owned = MyString
). However, I have a problem definingMyStr
. I could use a type alias:But this is inconvenient and won't allow some custom
impl MyStr
. What I would like is to use is a new-type-pattern. But this makes it difficult implementingBorrow
:Would it be safe to simple cast the reference from the
Box
withinMyString
to a&MyStr
or would this be undefined behavior?The text was updated successfully, but these errors were encountered: