dst-init

Crates.iodst-init
lib.rsdst-init
version0.4.0
sourcesrc
created_at2023-04-12 15:51:27.695568
updated_at2023-07-01 11:46:27.651037
descriptionA library for rust to provide ways to emplace dynamic sized type
homepagehttps://github.com/danny-326/dst-init
repositoryhttps://github.com/danny-326/dst-init
max_upload_size
id837047
size20,029
Danny Liu (danny-326)

documentation

https://docs.rs/dst-init

README

dst-init

A library for rust to provide ways to emplace dynamic sized type

#![feature(alloc_layout_extra)]
#![feature(ptr_metadata)]

use dst_init_macros::dst;
use dst_init::{BoxExt, Slice, SliceExt};
#[dst]
#[derive(Debug)]
struct Test<A, B, C, D> {
    a: A,
    b: B,
    c: C,
    dst: [(C, D)],
}

#[dst]
#[derive(Debug)]
struct Test1<A, B, C, D> {
    a: usize,
    t: Test<A, B, C, D>,
}

let t = TestInit {
    a: 1usize,
    b: 1u8,
    c: 1u8,
    dst: Slice::iter_init(3, (0..).map(|i| (i as u8, i as usize))),
};
let u = Test1Init { a: 1usize, t };
let a = Box::emplace(u);
assert_eq!(a.a,1usize);
assert_eq!(a.t.a,1);
assert_eq!(a.t.b,1);
assert_eq!(a.t.c,1);
assert_eq!(a.t.dst,[(0,0),(1,1),(2,2)]);

Commit count: 11

cargo fmt