1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
//Copyright 2019 #UlinProject Денис Котляров //Licensed under the Apache License, Version 2.0 (the "License"); //you may not use this file except in compliance with the License. //You may obtain a copy of the License at // http://www.apache.org/licenses/LICENSE-2.0 //Unless required by applicable law or agreed to in writing, software //distributed under the License is distributed on an "AS IS" BASIS, //WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. //See the License for the specific language governing permissions and // limitations under the License. //#Ulin Project 1819 // /*! 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()); } ``` 2. 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 */ #![feature(plugin_registrar)] #![feature(rustc_private)] extern crate syntax; extern crate rustc; extern crate rustc_plugin; mod nightly; pub use self::nightly::*; //The description only for documentation not to use. //Connect a plug-in! (The plug-in is described in nightly.rs, connect a plug-in as it is specified in documentation) #[macro_export] macro_rules! concat_bytes { ($($s:expr),*) => {unimplemented!()}; ($s:expr) => {unimplemented!()}; () => {unimplemented!()}; }