在Python中,可以编写
from io import StringIO with StringIO("some text...") as stream: for line in stream: # work with the data process_line(line)
有没有方法可以做同样的事情,把一些字符串当作文件对象,并对它应用Read特征?
Read
wn9m85ua1#
是的,您可以使用std::io::Cursor:
std::io::Cursor
use std::io::{Read, Cursor}; fn use_read_trait(s: String, buff: &mut [u8]) -> usize { let mut c = Cursor::new(s); c.read(buff).unwrap() }
1条答案
按热度按时间wn9m85ua1#
是的,您可以使用
std::io::Cursor
: