Rust
String.push(char)
takes charVec
hasreverse
method where as iterator hasrev
methodString
and&str
both havechars
method that convert string toChar
String
and&str
can 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 -1
could 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::clone
should 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) += 1
can be used as default map- Double side queue:
VecDeque
, we canpush/pop_front
andpush/pop_back
char
can be force convert tou8
if we want:'a' as u8
Rc<RefCell<T>>
can be get the internal&mut T
by callborrow_mut()
&mut [T]
can call&mut [T].clone/copy_from_slice(&[T])
, but their length needs to be the same&[T]
has methodto_vec
that can clone it to a new vector&mut [T]
hasrotate_left/right
andreverse
methodVec<char>
can be collect into string usingx.chars().into_iter().collect<String>()
char
can useto_uppercase/lowercase()
convert to up/lower case characters.char
hasis_ascii_alphabetic
methodslice
has method.split_at(usize)
so the slice can be split into two partsiter
has 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=host
on 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
.