cluConcatBytes

Crates.iocluConcatBytes
lib.rscluConcatBytes
version0.1.5
sourcesrc
created_at2019-04-05 12:57:36.423192
updated_at2019-08-01 06:14:01.544555
descriptionMerges literals into a static array.
homepage
repositoryhttps://github.com/clucompany/cluConcatBytes.git
max_upload_size
id125976
size23,888
Denis Kotlyarov (denisandroid)

documentation

README

cluConcatBytes

Build Status Apache licensed crates.io Documentation

Merges literals into a static array. Plugin for compiler.

Use

  1. Easy use
#![feature(plugin)]
#![plugin(cluConcatBytes)]

fn main() {
	let c_str = concat_bytes!("cluWorld");
	//&'static [u8]
	//array: [99, 108, 117, 87, 111, 114, 108, 100], len: 8
	assert_eq!(c_str, b"cluWorld");
	
	
	let c_str2 = concat_bytes!("clu", b"World");
	//&'static [u8]
	//array: [99, 108, 117, 87, 111, 114, 108, 100], len: 8
	assert_eq!(c_str2, b"cluWorld");
	
	let c_str3 = concat_bytes!(
		b'c', b'l', b'u',
		b'W', b'o', b'r', b'l', b'd'
	);
	//&'static [u8]
	//array: [99, 108, 117, 87, 111, 114, 108, 100], len: 8
	assert_eq!(c_str3, b"cluWorld");
	
	let c_str4 = concat_bytes!(
		"clu", b'W', b'o', b'r', b'l', b"d"
	);
	//&'static [u8]
	//array: [99, 108, 117, 87, 111, 114, 108, 100], len: 8
	assert_eq!(c_str4, b"cluWorld");
	
	my_function(c_str);
	my_function(c_str2);
	my_function(c_str3);
	my_function(c_str4);
}

fn my_function(array:  &'static [u8]) {
	//'static --> it is possible not to write.
	
	println!("array: {:?}, len: {}", array, array.len());
}
  1. Raw use
#![feature(plugin)]
#![plugin(cluConcatBytes)]

fn main() {
	let c_str = concat_bytes!(@"cluWorld");
	//[u8; 8]
	//array: [99, 108, 117, 87, 111, 114, 108, 100], len: 8
	assert_eq!(&c_str, b"cluWorld");
	
	
	let c_str2 = concat_bytes!(@"cluWorld");
	//[u8; 8]
	//array: [99, 108, 117, 87, 111, 114, 108, 100], len: 8
	assert_eq!(&c_str2, b"cluWorld");
	
	
	let c_str3 = concat_bytes!(@"clu", b"World");
	//[u8; 8]
	//array: [99, 108, 117, 87, 111, 114, 108, 100], len: 8
	assert_eq!(&c_str3, b"cluWorld");
	
	my_function(c_str);
	my_function(c_str2);
	my_function(c_str3);
}

fn my_function(array:  [u8; 8]) {
	//'static --> it is possible not to write.
	
	println!("array: {:?}, len: {}", array, array.len());
}

License

Copyright 2019 #UlinProject Denis Kotlyarov (Денис Котляров)

Licensed under the Apache License, Version 2.0

Commit count: 15

cargo fmt