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 -

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

Why does a .NET 4.0 program produce a system.unauthorizedAccess error on a Windows Server 2012 machine with .NET 4.5 installed? -