How to convert string to byte array in Rust

2 Answers

0 votes
fn main() {
    let string = "Rust";
    
    let byte_array = string.as_bytes();
    
    println!("{:?}", byte_array);
}



/*
run:

[82, 117, 115, 116]

*/

 



answered Mar 10, 2025 by avibootz
0 votes
fn main() {
    let string = String::from("Rust");
    
    let byte_array = string.into_bytes();
    
    println!("{:?}", byte_array);
}



/*
run:

[82, 117, 115, 116]

*/

 



answered Mar 10, 2025 by avibootz

Related questions

1 answer 96 views
1 answer 72 views
2 answers 115 views
1 answer 108 views
1 answer 123 views
1 answer 164 views
...