Rustã®ãã¤ãåãªãã©ã«ã®å
Rustã®ãªãã©ã«ã®åæ¤æ»ã¯ check_lit
ã«ãããããã«ããã¨ãæååãªãã©ã«ã®å㯠&'static str
ã§ããä¸æ¹ããã¤ãåãªãã©ã«ã®å㯠&'static [u8]
ã§ã¯ãªãã &'static [u8; N]
ã§ããã
ãã®ããã以ä¸ã®ãããªã³ã¼ããã³ã³ãã¤ã«ã§ããã
fn main() { let x : &[u8; 5] = b"Hello"; let y : [u8; 5] = *b"Hello"; }
ãªãã b"Hello"
ã¯ã &[72, 101, 108, 108, 111]
ã¨ç価ã§ã¯ãªããæ°å¤ãªãã©ã«ã u8
ã¨ã¯éããªãã¨ããç¹ã®ã»ãã«ãçåæéãç°ãªãã
fn main() { let x : &'static [u8] = b"Hello"; let y : &'static [u8] = &[72, 101, 108, 108, 111]; }
rustc 1.20.0-nightly (3bfc18a96 2017-06-29) error[E0597]: borrowed value does not live long enough --> <anon>:3:30 | 3 | let y : &'static [u8] = &[72, 101, 108, 108, 111]; | ^^^^^^^^^^^^^^^^^^^^^^^^ does not live long enough 4 | } | - temporary value only lives until here | = note: borrowed value must be valid for the static lifetime... error: aborting due to previous error(s)
çåæéãèæ
®ããã¨ã b"Hello"
ã¯ããã以ä¸ã®ããã«è±ç³ãããã¨èããããã
fn main() { let x : &'static [u8] = b"Hello"; let y : &'static [u8] = { static S : [u8; 5] = [72, 101, 108, 108, 111]; &S }; }