&str -> String--| String::from(s) or s.to_string() or s.to_owned()
&str -> &[u8]---| s.as_bytes()
&str -> Vec<u8>-| s.as_bytes().to_vec() or s.as_bytes().to_owned()
String -> &str----| &s if possible* else s.as_str()
String -> &[u8]---| s.as_bytes()
String -> Vec<u8>-| s.into_bytes()
&[u8] -> &str----| s.to_vec() or s.to_owned()
&[u8] -> String--| std::str::from_utf8(s).unwrap(), but don't**
&[u8] -> Vec<u8>-| String::from_utf8(s).unwrap(), but don't**
Vec<u8> -> &str----| &s if possible* else s.as_slice()
Vec<u8> -> String--| std::str::from_utf8(&s).unwrap(), but don't**
Vec<u8> -> &[u8]---| String::from_utf8(s).unwrap(), but don't**
,今天小编就来聊一聊关于rust泛型是编译时还是运行时?接下来我们就一起去研究一下吧!
![rust泛型是编译时还是运行时(rust中Stringstr)](http://img.studyofnet.com/upimg/967751648.jpg)
rust泛型是编译时还是运行时
&str -> String--| String::from(s) or s.to_string() or s.to_owned()
&str -> &[u8]---| s.as_bytes()
&str -> Vec<u8>-| s.as_bytes().to_vec() or s.as_bytes().to_owned()
String -> &str----| &s if possible* else s.as_str()
String -> &[u8]---| s.as_bytes()
String -> Vec<u8>-| s.into_bytes()
&[u8] -> &str----| s.to_vec() or s.to_owned()
&[u8] -> String--| std::str::from_utf8(s).unwrap(), but don't**
&[u8] -> Vec<u8>-| String::from_utf8(s).unwrap(), but don't**
Vec<u8> -> &str----| &s if possible* else s.as_slice()
Vec<u8> -> String--| std::str::from_utf8(&s).unwrap(), but don't**
Vec<u8> -> &[u8]---| String::from_utf8(s).unwrap(), but don't**
use std::fmt::Write;
// 将u8数组转换为字符串
let mut signature_string = String::new();
for a in ciphertext.iter() { // ciphertext 该值是一个u8数组对象
write!(signature_string, "{:02x}", a);
}
signature_string