Apparently rustup has its own implementation of getting the ${CARGO_HOME} location however it could just use the official home crate that cargo is using to do the same thing:
https://crates.io/crates/home
https://docs.rs/home/0.3.4/home/fn.cargo_home.html