How to do polymorphic IO from either a File or stdin in Rust?
问题 I'm trying to implement a "polymorphic" Input enum which hides whether we're reading from a file or from a stdin. More concretely, I'm trying build an enum that will have a lines method that will in turn "delegate" that call to either a File wrapped into a BufReader or to a StdInLock (both of which have the lines() method). Here's the enum: enum Input<'a> { Console(std::io::StdinLock<'a>), File(std::io::BufReader<std::fs::File>) } I have three methods: from_arg for deciding whether we're