Signature for a Rust method that modifies object but might also drop it?February 22, 2019
I’w writing an app in Rust that essentially pushes data through a pipeline of steps that transforms it in ways that are different. The information is represented by an
Entry, and I am designing a
Measure trait for the measures in the pipeline.
The trait should have a method that process the entry. My initial design was this:
Fn process(&self, entry: &mut Entrance ) -> ()
Afterwards, I realize I needed some measures to have the ability to shed the entry, i.e. somehow signal to the caller which the entry shouldn’t be processed further through the pipeline. I’m considering two signatures for this:
Fn procedure (itself, entry: Entry) -> Choice //Returns None if object is dropped.
Fn process(itself, entry: &mut Entry) -> bool //Returns false if object is lost.
Which would you say is your most idiomatic and strangest? Is there some performance penalty in passing the ownership around as in the first option? Is there a better alternative?