我是个新手,一直在浏览源代码,发现:
#[stable(feature = "fs_read_write_bytes", since = "1.26.0")]
pub fn write<P: AsRef<Path>, C: AsRef<[u8]>>(path: P, contents: C) -> io::Result<()> {
fn inner(path: &Path, contents: &[u8]) -> io::Result<()> {
File::create(path)?.write_all(contents)
}
inner(path.as_ref(), contents.as_ref())
}
这个函数定义这样的内部函数有什么原因吗?为什么不直接写:
File::create(path.as_ref())?.write_all(contents.as_ref())