Coder Social home page Coder Social logo

Comments (4)

andylokandy avatar andylokandy commented on May 27, 2024

Ideally, unsafe blocks should be minimized. In particular new_copy runs afoul of rust-lang/rfcs#2585 It's the write and transmute that requires unsafe?

Yeh, it's a good point. I'll make the update once the RFC is merged.

I suppose your lines like ptr_ptr.write(ptr_addr as usize); could document that they overwrite the pointer but retain any extra data inside the fat pointer.

Sure!

Ain't so idiomatic to pass around multiple references though ...

I think these should not be permanent once const generic is stable.

Why use std::alloc::{alloc.Layout} directly when seemingly Box methods suffice?

Said the std document, the underlying memory layout of Box is not defined and should not be relied on. However, we would have to handle allocation with unsized type on the fly in resize(), where we move data from ?Sized to ?Sized.

from smallbox.

burdges avatar burdges commented on May 27, 2024

new_copy uses Layout::for_value::<U>(val), while Drop uses Layout::for_value::<T>(&*self) (Deref). I suppose new_unchecked should explain that these must always agree. Also into_inner use Layout::new::<T>() but under T: Sized.

from smallbox.

andylokandy avatar andylokandy commented on May 27, 2024

The real assumption is that T and U has the same type while either can be in sized or unsized form. In this case, the result from Layout::for_value should be the same.

from smallbox.

andylokandy avatar andylokandy commented on May 27, 2024

Actually, this crate still lacks one important feature, which can't be implemented before(i dont remember why) but now may be viable, that being able to store FnOnce as the unsized type T, and take the ownership on call. Are you interested in investigating it?

from smallbox.

Related Issues (13)

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.