Rust
String.push(char)takes charVechasreversemethod where as iterator hasrevmethodStringand&strboth havecharsmethod that convert string toCharStringand&strcan besplit_whitespace- they also can call
split(pat: P)e.gsplit(' ')is equivalent to split by whitespace
- they also can call
- NOTE: in rust
usize -1could overflow to max, this might causing algorithm not working properly - If we are dealing with linked list with
Option<Box<Node>>, we can potentially usingBox::clone()to overcome some limitation due to borrow checker.Box::cloneshould be relatively not expensive as mentioned in rust book:a box is a smart pointer to a heap allocated value of T. - Check if key in HashMap, use
HashMap.contains_key(&key),HashMap.remove(&key)for delete,HashMap.insert(key, val)for insert key *HashMap.entry(&key).or_insert(value) += 1can be used as default map- Double side queue:
VecDeque, we canpush/pop_frontandpush/pop_back charcan be force convert tou8if we want:'a' as u8Rc<RefCell<T>>can be get the internal&mut Tby callborrow_mut()&mut [T]can call&mut [T].clone/copy_from_slice(&[T]), but their length needs to be the same&[T]has methodto_vecthat can clone it to a new vector&mut [T]hasrotate_left/rightandreversemethodVec<char>can be collect into string usingx.chars().into_iter().collect<String>()charcan useto_uppercase/lowercase()convert to up/lower case characters.charhasis_ascii_alphabeticmethodslicehas method.split_at(usize)so the slice can be split into two partsiterhas fold method, which allows we to fold iterator. e.g.vec![1,1,1,2,3].iter().fold(HashMap::new(), |mut map, i|{ let val = map.entry(i).or_insert(0); *val += 1; map })` // equals to HashMap{1:3, 2:1, 3:1}
Docker
Docker can be run with
--network=hoston windows, but as stated by reference, quote:The host networking driver only works on Linux hosts, and is not supported on Docker Desktop for Mac, Docker Desktop for Windows, or Docker EE for Windows Server.
So, when you notice something wired, like cannot ping docker exported port from windows/wsl2. check if your docker container is launched using
--network=host.