Git Product home page Git Product logo

Comments (9)

notgull avatar notgull commented on September 28, 2024

offset_of support predates addr_of in the standard library.

from bytemuck.

Lokathor avatar Lokathor commented on September 28, 2024

We could probably adjust things but it would have to be opt-in, because the offset_of module isn't feature gated and so it needs to work on 1.34 by default.

from bytemuck.

phil-opp avatar phil-opp commented on September 28, 2024

Ah sorry, I missed the README note about the 1.34 MSRV. In that case, the easiest solution is probably to add a new safe_offset_of macro, gated behind a cargo feature. Would that be ok with you?

from bytemuck.

Lokathor avatar Lokathor commented on September 28, 2024

Ah, well we could but I thought that the standard library offset_of was developing at a reasonable enough pace for people to just be able to use that sooner than later.

Also, double checking the file itself I actually don't see the unsafe block that is being referred to, so is that note old?

from bytemuck.

phil-opp avatar phil-opp commented on September 28, 2024

I wasn't aware that the standard library offset_of is so close to stabilization. I'm fine with waiting a bit and using a manual workaround based on addr_of for packed structs until then.

Also, double checking the file itself I actually don't see the unsafe block that is being referred to, so is that note old?

I think the unsafe block is required by Rust when you try to create a reference to a field of a packed struct, as it might be unaligned.

from bytemuck.

Lokathor avatar Lokathor commented on September 28, 2024

phil why are you using packed structs to begin with? They're very bad for your health, you shouldn't ;3

from bytemuck.

phil-opp avatar phil-opp commented on September 28, 2024

Haha, yeah :D. I'm dealing with a file format that contains some 64-bit offsets that are only aligned to 4 bytes. It's just some prototype code to figure out the details of the format, so I'm ignoring endianness for now do a direct cast to Rust structs.

from bytemuck.

Lokathor avatar Lokathor commented on September 28, 2024

https://docs.rs/pack1/latest/pack1/ may help you

from bytemuck.

phil-opp avatar phil-opp commented on September 28, 2024

Thanks, this helps indeed!

from bytemuck.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.