rust - How to easily copy a non-mut &[u8] into to a &mut [u8] -


i want manipulations on &mut [u8].

in testing code have:

#[test] fn test_swap_bytes() {     let input: &[u8] = b"abcdef";     let result: &mut[u8] = ?;     do_something(result);     assert_eq!(b"fedcba", result); } 

how can mutable u8 slice in case? should put on place of question mark?

you can use fact binary literal knows size @ compile-time. therefor can dereference , store on stack. let binding can mutable let binding.

let mut input: [u8; 6] = *b"abcdef"; 

see playpen working example

note there's no reason specify type, showed clarity.


Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -