读取文件
2025年3月31日小于 1 分钟hyperlanewebrustutilsread-file
写入文件
提示
hyperlane
框架提供了 read_from_file
函数用于向本地读取文件,需要注意的是需要指定接收的返回值类型
参数
file_path
: 文件路径
返回值
Result<T, Box<dyn std::error::Error>>
函数签名
fn read_from_file<T>(file_path: &str) -> Result<T, Box<dyn std::error::Error>>
where
T: FromStr,
T::Err: std::error::Error + 'static
使用
let data: Result<String, Box<dyn std::error::Error>> = read_from_file::<String>("./test.txt");