arr_ty

Crates.ioarr_ty
lib.rsarr_ty
version0.2.2
sourcesrc
created_at2023-04-02 19:00:19.166447
updated_at2024-01-14 21:45:24.388613
descriptionMacros for smart array initialization (best for trait object element types).
homepage
repositoryhttps://github.com/nossie531/arr_ty
max_upload_size
id828548
size19,035
(nossie531)

documentation

README

arr_ty

Macros for smart array initialization (best for trait object element types).

The author of this crate is not good at English.
Forgive me if the document is hard to read.

What is this?

This crate makes it a little bit smarter about initializing arrays whose element type is a trait object (just the author's personal feeling...).

let arr = arr_ty!(Box<dyn Any>; [
    Box::new(0),
    Box::new(false),
    Box::new("false")
]);

Without this crate, as far as the author knows, Rust (1.68.2) as of 2023 has the following unsmart code.

  • Redundant...

    let arr = [
        Box::new(0) as Box<dyn Any>,
        Box::new(false) as Box<dyn Any>,
        Box::new("false") as Box<dyn Any>
    ];
    
  • Or no unity...

    let arr = [
        Box::new(0) as Box<dyn Any>,
        Box::new(false),
        Box::new("false")
    ];
    
  • Or manual counting...

    let arr: [Box<dyn Any>; 3] = [
        Box::new(0),
        Box::new(false),
        Box::new("false")
    ];
    

What's New

v0.2.1-0.2.2

  • Minor refactoring.

v0.2.0

  • Removes the restriction on element types.
    Ex: Tuple type consisting of a trait object can be used as an element type.

    let arr = arr_ty!((i32, Box<dyn Any>); [
        (0, Box::new(false)),
        (0, Box::new("false"))
    ]);
    
Commit count: 5

cargo fmt