I facing issue with char array type, how can we assign value into [m_loginId, m_hashedPassword] variables when I make mutable variable of that structure.
In Rust, arrays aren't special when it comes to assignment. In fact, no type really is – assignment works for all types (of which the size is statically known). If you have an array in a struct, you can assign to it using the_struct.the_array_field = another_array;.
One thing to keep in mind is that an array of characters is not how you usually represent strings in idiomatic Rust. You should probably use the String type instead.
Its a legacy code that I will have to use this structure to send in message, I define a mut variable of struct and assigning value array so facing problem.
You should read the documentation or at the very minimum the signature of the functions you are using. str::as_bytes() returns a reference to a dynamically-sized slice, and not a value of type array.
If you want a literal array of known size, you can initialize it using array literal syntax, listing each element in order:
or in the case of arrays of bytes, the special b"..." literal syntax is also available, which returns a reference to a 'static array-of-u8 of the appropriate length:
let login_msg = TReqMobileBinLoginIdLong {
...
loginid: *b"foo@mail.com",
...
};
By the way, drop the m_ prefix from your field names. They serve no purpose in Rust.
Mind you, from the C declaration (MAX_EMAILADDRESS_SIZE) it looks like the array is expected to be initialized with at most that many characters, in which case a b"byte string literal" won't work (unless you manually pad it to the correct size, presumably with \x00 if this is expected to be consumed by a C API).
In this case, you can just initialize it with all zeroes using the repeating array literal construct, [0; MAX_EMAIL_ADDRESS_SIZE + 1], and then use <[u8]>::copy_from_slice() on the appropriate subrange in order to copy the contents of another slice, e.g.: