Skip to content

Instantly share code, notes, and snippets.

@eduardonunesp
Created January 4, 2022 16:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eduardonunesp/8d02aeed2d36f076a80a37279d06f2bc to your computer and use it in GitHub Desktop.
Save eduardonunesp/8d02aeed2d36f076a80a37279d06f2bc to your computer and use it in GitHub Desktop.
let str_to_int = u64::from_str_radix(&"10", 10).expect("Not an integer");
let int_string = "1000000".to_string();
let parse_int: u64 = "1000000".parse().unwrap();
let parse_int: u64 = "1000000".parse::<u64>().unwrap(); // Turbo fish syntax ::<>()
let padded = format!("{:08.2}", 1000.1234); // 00001000.12
let pad_left = format!("{txt:=<width$}", txt="text", width=20); // left padded to a variable place with = as padding
let pad_right = format!("{:=>7}", "text"); // right padded to 7 places with = as padding
let justified = format!("{:=^width$}", "text", 12); // centered with = on both sides
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment