Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the etymology or software principle behind "fuse" in Rust?

I am running up against the word fuse in the Rust ecosystem:

  • slog::Fuse to promote errors to panics.

  • FutureExt::Fuse "Fuse a future such that poll will never again be called once it has completed."

I'm aware of Linux's FUSE, a userspace filesystem. A fuse is also an electrical component that goes into open circuit state when too much current goes through the fuse. In hardware "fusing" describes baking configuration into the silicon by (historically) blowing circuits in the silicon through over-current in specific wires of the silicon.

What does "fuse" generally mean in Rust and what is its etymology?

like image 374
Ross Rogers Avatar asked Jan 25 '23 04:01

Ross Rogers


1 Answers

The earliest use I could find of "fuse" in the Rust ecosystem is Iterator::fuse, which was added to the standard library during the pre-1.0 days. The initial documentation for Iterator::fuse said:

/// Creates an iterator that yields `None` forever after the underlying
/// iterator yields `None`. Random-access iterator behavior is not
/// affected, only single and double-ended iterator behavior.

There was also a function on the returned iterator that has since been removed:

impl<T> Fuse<T> {
    /// Resets the fuse such that the next call to .next() or .next_back() will
    /// call the underlying iterator again even if it prevously returned None.
    #[inline]
    fn reset_fuse(&mut self) {
        self.done = false
    }
}

This indicates that Fuse is an analogy to a resettable electric fuse. The name is entirely unrelated to the FUSE filesystem.

FutureExt::Fuse is basically the Future equivalent to Iterator::Fuse. Support for Futures in Rust came far after support for Iterators.

The common thread here is that a fuse function takes "a thing that produces things, and can stop", and makes it so it doesn't produce things after it stops.

slog::Fuse is not a typical use of the word "fuse": that use might be referencing the fuse of a bomb, which is easily ignited (it makes errors easily ignite/panic the program). You can kinda fit it onto the earlier definition I made if you think of it as "a thing produces a stream of successes/failures, and fuse takes a failure and makes it so it doesn't produce anything more after a failure". The commit that added it doesn't provide any hints as to the meaning.

like image 124
Smitop Avatar answered May 14 '23 21:05

Smitop