We are currently using quite a few hacks to make caching for Rust projects work, but there are certain limitations.
Mtime
Rust relies on the `mtime` within the target folder. We currently work around this by creating a tar of the target folder and cache that, and on restore unpack it again. Bitbucket should really preserve the original mtime from caches.
Dependency updates
This is the real issue. We are basing our cache on the `Cargo.lock` file. This works generally okay, build dependencies are only recompiled when we change any dependency. The problem here is that when only one dependency is updated, Rust has to recompile all dependencies.
Ideally we'd have an option to update caches incrementally. What the Github rust-ache action (https://github.com/Swatinem/rust-cache) does is to try to restore from the last Cargo.lock version, uses potential old build artifacts, and then updates the cache.
Additionally, the Github action does not only take the Cargo.lock file into account, but also the rustc version, other toolchains and a few other things. This could mostly be covered by taking the Bitbucket pipeline image into account, so switching to a different image would invalidate the cache completely.
Incremental caches would also allow to cache artifacts from local crates, so if multiple binaries are compiled, only changed ones would have to be processed.