Pass string to function taking Read trait

前端 未结 1 1033
北恋
北恋 2021-02-19 22:21

I want to call this function in a 3rd party library (xmltree-rs):

pub fn parse(r: R) -> Element {

The expected use case is to

相关标签:
1条回答
  • 2021-02-19 23:19

    To find out what implements a trait, go to the bottom of the page for that trait.

    In this case, the most promising looking implementers are &'a [u8] and Cursor<Vec<u8>>.

    You can obtain a &[u8] from a &str or String by calling as_bytes(), taking note of automatic dereferencing and Deref on Strings. Alternatively, you could use a byte literal if you are only using the ASCII subset.

    0 讨论(0)
提交回复
热议问题