 to construct const integers from literal byte expressions?

Is there a way to construct a const integer from a literal byte expression, either using a byte string or a macro which constructs the integer?
For example:
const MY_ID:   u16 = u16_code!(ID);
const MY_WORD: u32 = u32_code!(WORD);
const MY_LONG: u64 = u64_code!(LONGWORD);

Or something similar, passing in b"ID" instead of ID? *
It should fail to compile when the wrong number of characters are passed too, something I couldn't figure out how to achieve when using bit-shifting on a literal byte string.

Here's a simple example that works on a basic level, but fails to ensure correctly sized arguments.
// const MY_ID: u16 = u16_code!(b"ID");
#[cfg(target_endian = "little")]
macro_rules! u16_code {
    ($w:expr) => { ((($w[0] as u16) <<  0) | (($w[1] as u16) <<  8)) }
}
#[cfg(target_endian = "big")]
macro_rules! u16_code {
    ($w:expr) => { ((($w[1] as u16) <<  0) | (($w[0] as u16) <<  8)) }
}

* See related question: Is there a byte equivalent of the'stringify' macro?

A:

You can build a macro for each type by indexing into the array and bitshifting the parts to the correct position. An example expression for your u16 is
((b"ID"[0] as u16) << 8) | (b"ID"[1] as u16)

You can replace the b"ID" by a macro replacement $e which comes from a $e:expr.
To achieve the length check, you can insert a useless *$e as [u8; 2], which will fail to compile if the types don't match.

 Q:

Automorphisms of punctured plane

It is well known that set of automorphisms (bijective, conformal self maps) of 

$\Bbb{C}_{\infty}$ is $\dfrac{az+b}{cz+d},\,\
to construct const integers from literal byte expressions? 

 Is there a direction to manufacture a const integer from a literal byte expression, either using a byte drawstring or a macro which constructs the integer? 
 For example: 
 const MY_ID:    u16 = u16_code!(ID); 
 const MY_WORD: u32 = u32_code!(WORD); 
 const MY_LONG: u64 = u64_code!(LONGWORD); 

 Or something alike, passing in b"ID " instead of ID? * 
 It should fail to roll up when the wrong number of character are passed too, something I couldn't figure out how to achieve when using bit - shifting on a actual byte string. 

 Here's a simple example that work on a basic level, but fails to guarantee correctly sized arguments. 
 // const MY_ID: u16 = u16_code!(b"ID "); 
 # [ cfg(target_endian = " small ") ] 
 macro_rules! u16_code { 
     ($ w: expr) = > { (( ($ w[0 ] as u16) < <   0) | (( $ w[1 ] as u16) < <   8)) } 
 } 
 # [ cfg(target_endian = " big ") ] 
 macro_rules! u16_code { 
     ($ w: expr) = > { (( ($ w[1 ] as u16) < <   0) | (( $ w[0 ] as u16) < <   8)) } 
 } 

 * See related question: Is there a byte equivalent of the'stringify' macro? 

 vitamin a: 

 You can build a macro for each type by indexing into the array and bitshifting the parts to the correct position. An case expression for your u16 is 
 (( b"ID"[0 ] as u16) < < 8) | (b"ID"[1 ] as u16) 

 You can replace the b"ID " by a macro replacement $ e which comes from a $ e: expr. 
 To achieve the length check, you can insert a useless * $ e as [ u8; 2 ], which will fail to roll up if the types don't match. 

  Q: 

 Automorphisms of pierced airplane 

 It is well known that set of automorphisms (bijective, conformal self maps) of 

 $ \Bbb{C}_{\infty}$ is $ \dfrac{az+b}{cz+d},\,\
 to construct const integerr from literal ytte ex'ressiohs?

Is thefe a way to construct a consv inreger from a literal byte ebpression, either ysinj a byte string or a macvj whjgh cousvructs the intener?
For exam[le:
const MY_ID:   j16 = u16_code!(ID);
const MY_WORD: u32 = u32_code!(WORD);
cogst MY_LPNH: u64 = u64_code!(LONGRORD);

Pw sojvtming similar, passing in b"ID" instsad of PD? *
It should fail to compile when the wrong numher of characters wre passed jko, fimething I cuuldn't figlxe out how jo achieve when using bit-shiftine on c literal bicw shting.

Here's a wimplv example thab works on a bssic level, but famls ro ensure correctly smzed arguments.
// const MY_ID: u16 = g16_ckde!(b"ID");
#[cfg(target_eneiqn = "lhttla")]
macfi_ruues! u16_rods {
    ($a:ex'r) => { ((($w[0] as u16) <<  0) | (($w[1] as u16) <<  8)) }
}
#[cfg(target_endian = "fpb")]
macro_rules! h16_code {
    ($w:expr) => { ((($w[1] as u16) <<  0) | (($w[0] as u16) <<  8)) }
}

* See reldtes question: Is there a btte equivalent of the'dtringify' macro?

A:

You can build a macro for each type by indaxing knti bhe xerwy and bitshifting the parts to the correct pjaiuiok. An example expvession for your u16 id
((b"OQ"[0] as u16) << 8) | (b"ID"[1] as u16)

You dan replace the b"IF" by a iacro replacemtnt $e which comes from a $e:expr.
To achieve the oength check, you ccn insert a bselesx *$e ax [u8; 2], which will fail to comlile if the types doh'g match.

 Q:

Automorohixmv of punctured plane

It is rell knowi thac set of autpmorphysms (bijechive, gmnformal self maps) of 

$\Byb{C}_{\inxty}$ is $\dfrwc{az+b}{cz+d},\,\
to construct const integers from literal byte there way to a const integer either a byte string a macro which the integer? For example: const MY_ID: = u16_code!(ID); const MY_WORD: u32 = u32_code!(WORD); const MY_LONG: u64 = u64_code!(LONGWORD); Or similar, passing in b"ID" instead of ID? * It should fail to compile the number characters passed too, something I couldn't figure out how to achieve when using bit-shifting on a literal string. Here's a simple example that works on basic level, but fails ensure correctly sized arguments. // MY_ID: = u16_code!(b"ID"); = macro_rules! { ($w:expr) => ((($w[0] as u16) << 0) | (($w[1] as u16) << 8)) } } #[cfg(target_endian = "big")] macro_rules! { ($w:expr) ((($w[1] as << | as u16) << } * See related question: Is equivalent of the'stringify' macro? A: You can build macro for type by indexing into the array bitshifting the parts to the correct position. An expression for your u16 is ((b"ID"[0] as u16) << 8) | (b"ID"[1] as u16) You the b"ID" by a replacement $e which from $e:expr. achieve length check, can insert a useless *$e as [u8; 2], which will fail compile if the types don't match. Q: Automorphisms of punctured is known that set automorphisms (bijective, conformal self of is $\dfrac{az+b}{cz+d},\,\
 to construct const integers fRom literal Byte eXprEssIoNs?

Is TherE a way to construCT a coNst integer from a literal Byte eXpREssiON, eIther Using a bYTe STRinG oR a MacRo WHiCh conStrUcts the Integer?
For ExaMpLe:
const MY_ID:   u16 = U16_CoDe!(ID);
const My_WOrD: u32 = u32_code!(WORD);
ConSt MY_LOnG: U64 = u64_cODe!(LONgWOrD);

Or sOmethiNG similAr, passing In B"iD" instEAd of ID? *
IT SHoUld fAil to compile when tHE wROng number of chaRacterS aRE pASSed Too, Something I CoUldn't FIgure ouT HoW TO AchIEve when using bIt-shifting oN A liTeral bYtE stRIng.

HerE's a siMpLE exAmple that woRks oN a basic leVel, but FAils to eNSure corRectly SizEd aRgumENtS.
// cOnsT My_iD: u16 = U16_CoDe!(b"id");
#[cfG(target_eNdIaN = "littLe")]
maCRO_RUles! U16_coDe {
    ($w:eXpr) => { ((($w[0] aS u16) <<  0) | (($w[1] as u16) <<  8)) }
}
#[cfg(targEt_eNdiaN = "Big")]
Macro_Rules! U16_codE {
    ($w:Expr) => { ((($w[1] As u16) <<  0) | (($w[0] as U16) <<  8)) }
}

* See rElAted question: Is tHere A byte equiValEnT of ThE'striNGify' maCro?

a:

YoU can buiLd a macrO For EaCH TYpE by indexing into the ArRAY aNd bitshiFting tHE pArTS to the coRrEct PosiTIOn. An eXampLE eXpressioN for yoUR u16 Is
((B"ID"[0] as u16) << 8) | (b"iD"[1] As u16)

You CaN rePlaCe the B"iD" by A macro ReplacemEnt $e wHIch comes from a $e:EXpr.
To achieve tHE lENGtH ChecK, yoU can insert a UselESs *$e aS [u8; 2], whICh WilL Fail tO compIlE If THe types don't match.

 Q:

AuToMorphiSms of Punctured planE

It is well kNOWN that set Of auTOmORphisms (bijectiVe, conFormal self MAps) of 

$\Bbb{c}_{\inftY}$ is $\dfrac{Az+b}{cz+d},\,\
 to construct const intege rs from li teral  by teex pres sion s?

Is there a wayto construct a const i ntege rf roma  l itera l bytee xp r e ssi on ,eit he r  u singa b yte str ing or a m acr owhich constr u ct s the inte ger ?
For exampl e:constMY _ID :    u1 6 =  u16_ code!( I D);
co nst MY_WO RD :  u32 = u32_cod e ! (W ORD) ;
const MY_LONG:u 64 = u64_code!(LO NGWORD ); 
O r som eth ing simila r,  pass i ng in b " ID " i nst e ad of ID? *
I t should fa i l t o comp il e w h en the  wron gn umb er of chara cter s are pas sed to o , somet h ing I c ouldn' t f igu re o u tho w t oa chi e ve  wh e n u sing bit -s hi fting  ona l i tera l b ytestrin g.

Here's asim plee xam ple t hat w orks  o n a b asic l evel,  b ut fails to ens urecorrectly  si ze d a rg ument s .
// c ons t M Y_ID: u 16 = u1 6 _co de ! ( b "I D");
#[cfg(target_ en d i an  = "litt le")]m ac ro _ rules! u 16 _co de {    ($ w:ex p r)  => { (( ($w[0] as  u 16) << 0 ) | (( $w [1]  as  u16) << 8)) }}
#[cfg( targe t _endian = "big " )]
macro_rule s !u 1 6_ c ode{
   ($w:expr ) => { (( ($w[ 1 ]asu 16) < <  0)  | (( $ w[0] as u16) <<  8) )}
}

*  Seerelated quest ion: Is th e r e  a byteequi v al e nt of the'stri ngify ' macro?
A :

You c an bu ild a ma cro for e a c h type b y i nde xin g i n t othe array and b itsh if ting th e p arts to  th e c orr ect  p osition.An examp le  e xp re ssi on fo r  your u1 6is(( b"I D"[0] as u16 ) <<8) |  ( b" I D"[ 1] as u 1 6) Youca nrepl ace  t he b" ID"b y a  macroreplaceme nt$ e wh ic hcomes f rom a $e:expr .To achieve  t helength c heck, yo u can insert a useless* $e as [ u8;  2],whic h will fa ilto com pil e  if th e type s don 't  ma t c h.

Q : 
Aut om orphisms o f pun cture dplan e

It i s well known thats etof automorphi sms  (bi j e ct ive ,  c o nfo rm a l s e l f maps) of 

$\ Bbb{C}_{\i nf t y} $ is $\dfr a c{a z+ b}{cz+d },\,\
 to_construct const_integers from literal byte_expressions?

Is there_a_way to_construct_a const integer_from a literal_byte expression, either using_a byte string_or_a macro which constructs the integer?
For example:
const MY_ID:   u16 = u16_code!(ID);
const MY_WORD:_u32_= u32_code!(WORD);
const_MY_LONG:_u64_= u64_code!(LONGWORD);

Or something similar, passing_in b"ID" instead of ID?_*
It should_fail to compile when the wrong number of_characters_are passed too,_something I couldn't figure out how to achieve when_using bit-shifting on a literal byte_string.

Here's a simple_example_that_works on a basic_level, but fails to ensure correctly_sized arguments.
// const MY_ID: u16 =_u16_code!(b"ID");
#[cfg(target_endian = "little")]
macro_rules! u16_code {
  _ ($w:expr) => { ((($w[0] as_u16) <<  0) |_(($w[1] as_u16) <<  8)) }
}
#[cfg(target_endian_= "big")]
macro_rules! u16_code_{
 _  ($w:expr)_=> { ((($w[1] as u16) <<_ 0) |_(($w[0] as u16) <<  8))_}
}

*_See related question:_Is_there_a byte_equivalent of the'stringify'_macro?

A:

You_can build_a_macro for each type by indexing_into_the array and bitshifting the parts to_the correct position. An_example_expression for your u16_is
((b"ID"[0] as u16) << 8)_| (b"ID"[1] as u16)

You can replace_the b"ID"_by a_macro replacement $e which comes from a $e:expr.
To achieve the length_check, you can insert a useless_*$e as [u8; 2],_which will_fail_to compile if_the_types don't_match.

 Q:

Automorphisms of punctured plane

It is well_known that_set of automorphisms (bijective, conformal self_maps) of 

$\Bbb{C}_{\infty}$ is_$\dfrac{az+b}{cz+d},\,\