arr_ty

Crates.ioarr_ty
lib.rsarr_ty
version0.4.0
created_at2023-04-02 19:00:19.166447+00
updated_at2025-07-24 10:37:23.073733+00
descriptionMacros for smart array initialization.
homepage
repositoryhttps://github.com/nossie531/arr_ty
max_upload_size
id828548
size20,336
(nossie531)

documentation

README

arr_ty

Macros for smart array initialization.

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 Rust array initialization a little smarter.

Future and current

This crate will be useless by feature generic_arg_infer (See rust issue #85077 for more details).

However, as of 2025, there are cases where redundant number specifications are required at array initialization.

Examples

Use case 1 (number element type)

This is not possible.

let arr = [0, 1, 2] as [u32;_];

With this crate.

let arr = arr_ty!(u32; [0, 1, 2]);

Without this crate, manual counting approach.

let arr = [0, 1, 2] as [u32;3];

Without this crate, redundant type approach.

let arr = [0u32, 1u32, 2u32];

Without this crate, no unity approach.

let arr = [0u32, 1, 2];

Use case 2 (dynamic element type)

This is not possible.

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

With this crate.

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

Without this crate, manual counting approach.

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

Without this crate, redundant cast approach.

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

Without this crate, no unity approach.

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

What's New

See CHANGELOG.

Commit count: 6

cargo fmt