Code Monkey home page Code Monkey logo

Comments (10)

Kixunil avatar Kixunil commented on May 30, 2024 2

Exactly. I'd submit a PR, but I'm currently low on time. I expect to have more time after ~2 weeks.

from byteorder.

Kixunil avatar Kixunil commented on May 30, 2024 1

This is weird, I completely forgot about this. I do remember trying to add unsafe but something stopped me and then I didn't continue for some reason. Can't remember anything more. I guess it's a good thing because MaybeUninit was introduced since then and it doesn't make sense to guarantee anything about uninitialized &mut [u8] as that's UB already.

No change is actually required because performant writing can be done safely already: https://play.rust-lang.org/?version=stable&mode=release&edition=2018&gist=26babbb49afda7644f61f4e7ffe1ad2c

TL;DR is that writing to a safe, 0-init array first and then copying it into uninit slice gets optimized just fine.
It could be nice to guarantee that unsafe code can rely on values being written as expected but I personally wouldn't consider unsafe code being broken if it relies on it implicitly as that's a reasonable assumption.

Maybe a more appropriate label would be magically-fixed-itself instead of wontfix. 😆

from byteorder.

BurntSushi avatar BurntSushi commented on May 30, 2024

This seems reasonable to me. I can't imagine any circumstances under which the write methods would actually want to read from the buffer. Can you?

from byteorder.

Kixunil avatar Kixunil commented on May 30, 2024

I can't. Would it be breaking change to make the trait unsafe? If the only implementors are LittleEndian and BigEndian, then it should be fine...

from byteorder.

Kixunil avatar Kixunil commented on May 30, 2024

Ping?

from byteorder.

BurntSushi avatar BurntSushi commented on May 30, 2024

I don't think it would be a breaking change.

Why does the standard io::Read trait not make this guarantee?

from byteorder.

Kixunil avatar Kixunil commented on May 30, 2024

There's a PR addressing this.

from byteorder.

BurntSushi avatar BurntSushi commented on May 30, 2024

I see. So it seems like the preferred solution is to make the trait unsafe, but we couldn't do that for std::io::Read. However, I believe we can here since the trait is sealed.

from byteorder.

Kixunil avatar Kixunil commented on May 30, 2024

Sorry, I forgot about this completely. I'll look at it today (not sooner than 9 hours from now).

from byteorder.

BurntSushi avatar BurntSushi commented on May 30, 2024

I think that if you're already dealing with unsafe code and uninitialized buffers, then it probably doesn't make sense to use byteorder's safe APIs, since they impose a cost.

from byteorder.

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.