【问题标题】:How to handle EOF with the scan_fmt crate?如何使用 scan_fmt crate 处理 EOF?
【发布时间】:2023-01-09 02:50:01
【问题描述】:

使用 scan_fmt crate,当与 scanln_fmt 助手一起使用时,我如何处理 EOF?如果提供了空行,我想做这样的事情,其中​​ xNone

let (isEOF, x) = scanln_fmt_some!("{d}");

如何区分空换行输入和 EOF?

【问题讨论】:

  • 不能,scan_fmt不提供。只需使用std::io::stdin
  • 是的,从 0.2.6 开始,ScanError 总是为 source() 返回 None,因此无法区分 EOF 和其他解析错误。

标签: input rust


【解决方案1】:

scan_fmt crate 没有公开区分 EOF 和其他错误的方法。

宏只返回(Option<X>, Option<Y>, ...)(来自scan[ln]_fmt_some)或Result<(X, Y, ...), ScanError>(来自scan[ln]_fmt)。而ScanError的内容似乎只解释了解析失败的类型,而没有解释为什么。

【讨论】:

    猜你喜欢
    • 2013-03-29
    • 1970-01-01
    • 2012-06-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-21
    • 1970-01-01
    • 2015-07-25
    相关资源
    最近更新 更多