Impl fn CratesToml::load_from_reader

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
Jiahao XU 2022-07-22 20:15:03 +10:00
parent 9e45ba1032
commit 565b404dce
No known key found for this signature in database
GPG key ID: 591C0B03040416D6

View file

@ -27,6 +27,12 @@ impl CratesToml {
Self::load_from_path(Self::default_path()?)
}
pub fn load_from_reader<R: io::Read>(mut reader: R) -> Result<Self, CratesTomlParseError> {
let mut vec = Vec::new();
reader.read_to_end(&mut vec)?;
Ok(toml::from_slice(&vec)?)
}
pub fn load_from_path(path: impl AsRef<Path>) -> Result<Self, CratesTomlParseError> {
let file = fs::read_to_string(path)?;
Self::from_str(&file)