The way to notify the implementation which return value is disuse.
When an algorithm can calculate multiple useful values simultaneously, you will write like the following code. ```rust pub fn some_algorithm(x: f64) -> (f64, f64, f64) { let mut r1 = 0f64; let mut r2 = 0f64; let mut r3 = 0f64;
for _ in 0..1000 { // ... some eavy calculations here ...
r1 += x;
r2 += x * 2.0;
r3 += x * 3.0;
}
(r1, r2, r3)
}
But your users are not always need all return values.
rust
#
// Yes, we can ignore the return values, but calculations done.
let (a, , _) = somealgorithm(4.0);
Above example code can be rewrite using [Disuse] as follows,
rust
use disuse::Disuse;
pub fn some_algorithm
for _ in 0..1000 { // ... heavy calculations here ... r1 += x; r2 += x * 2.0; // When user call this function like below, r3 += x * 3.0; // we can expect the compiler eliminate this two line, right? } ((r1,).into(), (r2,).into(), (r3,).into()) }
let ((a,), , _): ((f64,), Disuse, Disuse) = somealgorithm(4.0); ``` Oops, just a little ugly...(a little?)
If the unit type (()) implements [From] trait like as follows,
rust
impl<T> From<T> for () {
fn from(_: T) -> () { () }
}
above example code can be write more smart.
```rust
pub fn some_algorithm
for _ in 0..1000 { // ... heavy calculations here ... r1 += x; r2 += x * 2.0; // When user call this function like below, r3 += x * 3.0; // we can expect the compiler eliminate this two line, right? } (r1.into(), r2.into(), r3.into()) }
let (a, , _): (f64, (), ()) = somealgorithm(4.0); ``` It's just unrealizable dream...