我需要打开一个文件,并且我的标志有&Path
和i32
。我可以用File::open(path)
打开文件,但这不能让我设置选项。文档说我应该使用OpenOptions
,但是我看不出有什么方法可以从OpenOptions
中获取i32
。我的标志的内容定义为open(2)
。
我要使用的标志是526338
,如果您想自己对其进行测试。
假设您使用的是类似Unix的系统,则可以使用OpenOptionsExt
设置标志:
OpenOptionsExt
注意,您必须分别设置访问模式标志(例如,通过调用use std::fs::OpenOptions;
use std::os::unix::fs::OpenOptionsExt;
let file = OpenOptions::new()
.read(true)
.custom_flags(flags)
.open(&path)?;
或read
),因此,如果需要它们,则必须自己处理。例如:
write