Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a DST type?

Tags:

rust

DST (Dynamically Sized Types) are a thing in Rust now. I have used them successfully, with a flexible last member which is known to the compiler (such as [u8]).

What I am looking to do, however, is to create a custom DST. Say, for example:

struct Known<S> {
    dropit: fn (&mut S) -> (),
    data: S,
}

struct Unknown {
    dropit: fn (&mut ()) -> (),
    data: (),
}

With an expected usage being Box<Known<S>> => Box<Unknown> => Box<Known<S>>, where the middleware need not know about concrete types.

Note: yes, I know about Any, and no I am not interested in using it.

I am open to suggestions in the layout of both Known and Unknown, however:

  1. size_of::<Box<Known>>() = size_of::<Box<Unknown>>() = size_of::<Box<u32>>(); that is it should be a thin pointer.
  2. dropping Box<Unknown> drops its content
  3. cloning Box<Unknown> (assuming a clonable S), clones its content
  4. ideally, fn dup(u: &Unknown) -> Box<Unknown> { box u.clone() } works

I have particular difficulties with (3) and (4), I could solve (3) with manually allocating memory (not using box, but directly calling malloc) but I would prefer providing an idiomatic experience to the user.

I could not find any documentation on how to inform box of the right size to allocate.

like image 605
Matthieu M. Avatar asked May 11 '15 18:05

Matthieu M.


People also ask

How do I create a DST file?

It can also create a DST file through File > Save State File . If you're dealing with data related to the embroidery format, a few compatible file viewers include Wilcom's TrueSizer, Embroidermodder, Embird's Studio, BuzzXplore (previously called Buzz Tools Plus ), and SewWhat-Pro. Wilcom also has a free online DST viewer called TrueSizer Web .

What is a DST file for embroidery?

What is a dst File for Embroidery? The dst file is usually the instruction file that guides the computer technology when it needs to move the needle after you have selected your stitch pattern. It contains the instructions to different actions the needle needs to take to get the stitch right.

How to view DST file in Revit?

You can display it through View > Palettes > Sheet Set Manager. Open DeSmuME State Files with the DeSmuME program. It can also create a DST file through File > Save State File. If you're dealing with data related to the embroidery format, a few DST file viewers you can get include Wilcom's TrueSizer, Embroidermodder, Embird's Studio, ...

Can my machine read a DST file?

Popular and easy to use, it can resize and alter designs at the touch of a button. Embroidery files contain all the information the machine needs to recreate a design. A .dst file is one of the many formats these instructions can be formatted. Whether your machine can read a .dst file depends on which one you have.


1 Answers

There are exactly two types of unsized objects at present: slices ([T]), where it adds a length member; and trait objects (Trait, Trait + Send, &c.), where it adds a vtable including a destructor which knows how large an object to free.

There is not currently any mechanism for declaring your own variety of unsized objects.

like image 160
Chris Morgan Avatar answered Oct 09 '22 10:10

Chris Morgan