File io 将字符串传递给具有读取特征的函数

File io 将字符串传递给具有读取特征的函数,file-io,rust,File Io,Rust,我想在第三方库()中调用此函数: 但是,我有一个字符串,我想传递它,大致如下: xmltree::Element::parse("<example>blah</example>".to_owned()); 如果不写临时文件,我该怎么做?(例如,在Python中,我将使用将字符串包装在类似文件的对象中)要了解实现特征的是什么,请转到 在这种情况下,最有前途的实现者是&'a[u8]和游标 您可以通过调用&str或String获取和[u8],注意自动取消引用,并打开Strin

我想在第三方库()中调用此函数:

但是,我有一个
字符串
,我想传递它,大致如下:

xmltree::Element::parse("<example>blah</example>".to_owned());

如果不写临时文件,我该怎么做?(例如,在Python中,我将使用将字符串包装在类似文件的对象中)

要了解实现特征的是什么,请转到

在这种情况下,最有前途的实现者是
&'a[u8]
游标

您可以通过调用
&str
String
获取
和[u8]
,注意自动取消引用,并打开
String
s。或者,如果只使用ASCII子集,则可以使用字节文字

let e: Element = Element::parse(File::open("tests/data/01.xml").unwrap());
xmltree::Element::parse("<example>blah</example>".to_owned());
error: the trait `std::io::Read` is not implemented for the type `collections::string::String` [E0277]