encoding - Convert a string to base64 -


I want a simple thing: I used an example to convert a string into base64:

  Sort the outer crate; Serialize :: base64 :: {mod, ToBase64}; Serialize :: hex :: fromHex; Fn Main () {Input Input = "49276d206b696c6c696e6720796f757220627261696e206c696b65206120706f69736f6e6f7573206d757368726f6f6d"; Give the result = input From_hex () to open (). As_slice (). To_base64 (base64 :: standard); Println! ("{}", result); }  

Edge to work but I do not understand why there are only letters in hex in input. In addition, this python code produces a different result:

  base64.b64encode (input) # = & gt; 'NDkyNzZkMjA2YjY5NmM2YzY5NmU2NzIwNzk2Zjc1NzIyMDYyNzI2MTY5NmUyMDZjNjk2YjY1MjA2MTIwNzA2ZjY5NzM2ZjZlNmY3NTczMjA2ZDc1NzM2ODcyNmY2ZjZk'  

So I decided to do the following:

  // .... input = "some string 123"; Result2 = input.unwrap (). As_slice (). To_base64 (base64 :: standard); Result3 = input.as_slice () To_base64 (base64 :: standard);  

and was not compiled due to errors:

  Error: type `& amp; Do not apply any method in the field named 'str` `` Opening test1.rs: 9 result 2 = input. Repeat (). As_slice (). To_base64 (base64 :: standard); ^ ~~~~~~~ test1.rs: 9:34: 9:44 Error: Many applicable methods in the scope [E0034]  

So how do I code a simple string in base 64 Words to change?

If you do not have hex input, then try it:

  Give result = input Left (). To_base64 (base64 :: standard);  

Comments