项目作者: inspier

项目描述 :
Macros for concatenating const arrays.
高级语言: Rust
项目地址: git://github.com/inspier/array-concat.git
创建时间: 2021-04-15T16:55:12Z
项目社区:https://github.com/inspier/array-concat

开源协议:MIT License

下载


Current Crates.io Version
docs-rs

array-concat

Macros for concatenating and splitting arrays.

To add to your Cargo.toml:

  1. array-concat = "0.5.5"

Example

  1. use array_concat::*;
  2. const A: [u32; 3] = [1, 2, 3];
  3. const B: [u32; 2] = [4, 5];
  4. const C: [u32; concat_arrays_size!(A, B)] = concat_arrays!(A, B);
  5. // Non-Copy struct
  6. #[derive(Debug, PartialEq)]
  7. struct S(bool);
  8. const D: [S; 1] = [S(true)];
  9. const E: [S; 1] = [S(false)];
  10. const F: [S; concat_arrays_size!(D, E)] = concat_arrays!(D, E);
  11. fn main() {
  12. let c = concat_arrays!(A, B);
  13. assert_eq!([1, 2, 3, 4, 5], C);
  14. assert_eq!([1, 2, 3, 4, 5], c);
  15. assert_eq!([S(true), S(false)], F);
  16. // Split the array into three parts with lengths: 1, 3, and 1
  17. assert_eq!(([1], [2, 3, 4], [5]), split_array!(c, 1, 3, 1));
  18. let a = [1, 2, 3];
  19. let b = [4, 5];
  20. let c = concat_arrays!(a, b); // Size is inferred by the assert below
  21. assert_eq!([1, 2, 3, 4, 5], c);
  22. }