GithubHelp home page GithubHelp logo

project-safe-transmute's Introduction

project-safe-transmute's People

Contributors

jswrenn avatar kornelski avatar lqd avatar mbartlett21 avatar rylev avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

project-safe-transmute's Issues

Safe transmute between #[repr(transparent)] and the type it contains

I'd like to write the following code:

/// A newtype wrapper around u32 that guarantees the number is even
#[repr(transparent)]
pub struct EvenU32(u32);

impl EvenU32 {
  pub fn try_from_u32_ref(value: &u32) -> Result<&Self, ()> {
    if *value % 2 == 0 {
      Ok(safe_transmute(value))
    } else {
      Err(())
    }
  }
}

To enforce the invariant of the wrapper type, safe_transmute should look at the visibility of the field. For example, the following code in a different module would not work:

// Should not compile, because the `u32` field is inaccessible from the outside
let _: EvenU32 = safe_transmute(&100);

CC @Manishearth

Safe std::mem::uninitialized too?

I might be nice to get that back for "plain old data". Couldn't many of the same analyses that support safe transmute also support that?

Why does the cast_slice parameter have to be of type Pod?

pub fn try_cast_slice<A: Pod, B: Pod>(a: &[A]) -> Result<&[B], PodCastError>
requires that the parameter a is a slice of type Pod. Pods can't be chars (because the type must allow any bit pattern).

However I don't understand why. It's not like I can introduce illegal bit patterns through a non-mutable reference?!
Is this some random limitiation of this crate?

Can we not fix this because of #41?
Is relaxing trait boundaries not allowed?

Comments/prior art on `Atomic<T>`

I was not sure where best to comment this RFC draft. I just wanted to throw a library of mine into the discussion: atomig, which main feature is Atomic<T>.

In atomig's case, the trait bounds on T are a bit more specific and deliberate than in the RFC draft. The docs should explain all the traits fairly well, so I won't repeat myself here.

But one important aspect of having more specific traits: some methods, like fetch_add and fetch_or are bounded by AtomInteger and AtomLogic traits respectively, which in turn are only implemented for types on which integer operations and logical operations make sense, respectively. With the current draft, one could have an Atomic<f32> and call fetch_add on it, but get garbage back, as the atomic add operation is an integer addition. Again, I think the docs should explain this nicely.

Just wanted to throw that out here.

CC @jswrenn

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.