On 10/12/14 01:08 PM, Matt wrote:
> Sorry if this has been covered before, and also that I'm a complete noob, but 
> I'm thinking about trying a first project in Rust, and trying to learn enough 
> to get started. 
> 
> My plan is for an on-disk key-value store. I'm going to end up writing arrays 
> of numbers to disk, and then needing to efficiently read them out of a 
> mmap-ed file. So I'm wondering how in Rust you efficiently/zero-copy-ly take 
> some slice of a read-only mmap and treat it as e.g. a vector of ints?
> 
> I see Vec.from_raw_parts() and Vec.from_raw_buf(), but I don't really 
> understand the difference between them, and also they seem like they just 
> give you a vector of the pointer's type, so I don't know how you use them 
> convert the u8s you get from MemoryMap.data() into a vector of a different 
> type, e.g. 32 bit ints.
> 
> It seems like there should be a higher level API for this kind of thing, 
> where "casting" a slice of a read-only memory buffer into an immutable vector 
> is not an unsafe operation (I mean, you can do that in Python ;) Either I 
> don't see it in the docs, or it doesn't exist yet; just wondering which :)
> 
> Thanks!
> 
> Matt

Keep in mind that the file won't be portable if you do this. It's why
it's not a common pattern.

Attachment: signature.asc
Description: OpenPGP digital signature

_______________________________________________
Rust-dev mailing list
Rust-dev@mozilla.org
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to