[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: [RFC PATCH 04/25] tools/xenbindgen: Add a TOML spec reader
Hi, > + let _specification = match spec::Spec::new(&cli.indir) { > + Ok(x) => x, > + Err(spec::Error::Toml(x)) => { > + error!("TOML parsing error:"); > + error!("{x:#?}"); > + std::process::exit(1); > + } > + Err(spec::Error::Io(x)) => { > + error!("IO error:"); > + error!("{x:#?}"); > + std::process::exit(1); > + } > + }; I think it can be replaced with .unwrap() (or making the main function returns a Result<T, E>) as long as our internal error implements Display. > +/// Internal error type for every error spec parsing could encounter > +#[derive(Debug)] > +pub enum Error { > + /// Wrapper around IO errors > + Io(std::io::Error), > + /// Wrapper around deserialization errors > + Toml(toml::de::Error), > +} > + > +/// Maps an [`std::io::Error`] onto a [`Error`] type for easier propagation > +fn from_ioerr<T>(t: std::io::Result<T>) -> Result<T, Error> { > + t.map_err(Error::Io) > +} > + May be worth a impl From<std::io::Error> for super::Error such as ? operator can automatically convert it to our internal error type Cheers Teddy Teddy Astie | Vates XCP-ng Developer XCP-ng & Xen Orchestra - Vates solutions web: https://vates.tech
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |