downgrade
Downgrade a mutable reference to an immutable one.
Usage
use Downgrade;
let mut x = 5;
let y = &mut x; // `y` is a mutable reference to `x` (`&mut x`)
let z = y.downgrade; // `z` is an immutable reference to `x` (`&x`)
Why?
Brief
Some functions return a mutable reference to a value, but you only need an immutable reference. A mutable reference cannot be .clone()d, while an immutable reference can, so this method might come in handy.
Example
Consider the following example:
use thread;
This would not compile, since leaked is a mutable reference, which does not implement Clone. However, the compiler does not know that we will only use the reference in a read-only way, so we must tell it explicitly. Normally, you can:
# use thread;
#
#
#
#
Which looks a bit ugly. By using downgrade, we can make it a bit cleaner:
use Downgrade;
# use thread;
#
#
#
#