Add include_bytes! macro#35
Conversation
0f41a34 to
7dcafab
Compare
c53040a to
7790cfd
Compare
f651691 to
5a1ab31
Compare
jswrenn
left a comment
There was a problem hiding this comment.
Nice! When I blogged about this a few years ago, I opted to match the standard library's behavior of returning a reference. I.e., this:
#[macro_export]
macro_rules! include_bytes {
($file:expr $(,)?) => {
&$crate::transmute!(*::core::include_bytes!($file))
};
}I think it's fine to deviate from the standard library, but we probably should have some principled idea of why we're doing so.
3bae012 to
70a3819
Compare
tbh I think the stdlib is wrong here, but I agree that we should mirror it unless we have a good reason to diverge. Done. |
Actually wait: what about non- |
|
Agreed — I think that's a good reason for us to not return a reference. |
Done. |
b7e22ea to
9698b74
Compare
The `include_bytes!` macro is like the macro from `core` of the same name, except that it transmutes the file's contents to an arbitrary type (which implements `FromBytes`). Release 0.7.13.
The
include_bytes!macro is like the macro fromcoreof the same name, except that it transmutes the file's contents to an arbitrary type (which implementsFromBytes).TODO:
Change the example usage in the doc comment to use something more complex like the fixed-length header of a file format?Are there other variants we should introduce? Perhaps one for slice types? Can we design it in such a way that it would work with other (non-slice) DSTs in the future if we add support for those?