Skip to content

Instantly share code, notes, and snippets.

fn main() {
let s = "...".to_string();
let a = vec!["abc","abcde","abcdefgh","abcdefghijkl","abcdefghijklmnop"]
.into_iter()
.map(String::from)
.map(|mut string|
if string.len() > 5 { string.truncate(5); [string, s.to_string()].join("") }
else {string.truncate(5); string})
.collect::<Vec<String>>();
println!("{:?}",a)
@git314
git314 / main.rs
Created April 1, 2021 12:42
Format floats and strings for printing
use console::Style;
fn format_float(vec_float: Vec<Option<f64>>){
let bold = Style::new().bold();
let bright_red = Style::new().bright().red();
let bright_black = Style::new().bright().black();
println!("{}", bright_black.apply_to("<dbl>"));
for x in vec_float{
match x {
Some(i) => if i > 0.0_f64{
@git314
git314 / get_from_hashmap.rs
Last active March 30, 2021 10:17
Make a Hashmap in Rust
use toml::Value;
use pad::{PadStr, Alignment};
use std::collections::BTreeMap;
use console::style;
fn main() {
//toml_hash is a `BTreeMap<std::string::String, Vec<Value>>`
let toml_hash: BTreeMap<String, Vec<toml::Value>> = toml::from_str(r#"
foo = [1,nan,3]
bar = ["a","b","c"]
baz = [2021-03-29, 2020-03-29, 2020-03-29]