[−][src]Function lexpr::parse::from_reader_custom
pub fn from_reader_custom(rdr: impl Read, options: Options) -> Result<Value>
Parse a value from an IO stream containing a single S-expression.
The content of the IO stream is parsed directly from the stream without being buffered in memory.
When reading from a source against which short reads are not efficient, such
as a File
, you will want to apply your own buffering, e.g. using
std::io::BufReader
.
use std::error::Error; use std::fs::File; use std::io::BufReader; use std::path::Path; fn read_value_from_file<P: AsRef<Path>>(path: P) -> Result<lexpr::Value, Box<dyn Error>> { // Open the file in read-only mode with buffer. let file = File::open(path)?; let reader = BufReader::new(file); // Read an arbitrary S-expression, using parser options suitable for Emacs Lisp. let value = lexpr::from_reader_custom(reader, lexpr::parse::Options::elisp())?; // Return the value. Ok(value) } let value = read_value_from_file("test.el").unwrap(); println!("{:?}", value);