5
我想調用第三方庫這個功能(xmltree-rs):傳遞字符串的功能以閱讀特質
pub fn parse<R: Read>(r: R) -> Element {
的預期使用情況是給它一個文件,像這樣:
let e: Element = Element::parse(File::open("tests/data/01.xml").unwrap());
但是我有一個String
,我想通過,依稀是這樣的:
xmltree::Element::parse("<example>blah</example>".to_owned());
然而這當然,給出了一個錯誤:
error: the trait `std::io::Read` is not implemented for the type `collections::string::String` [E0277]
我該怎麼做,短的寫一個臨時文件? (例如在Python中,我將使用StringIO module將字符串包裝到類似文件的對象中)