简体   繁体   English

Result<()> 在 Rust 中是什么意思?

[英]What does Result<()> mean in rust?

I was looking at the std::env::current_dir function documentation and this caught my attention:我正在查看std::env::current_dir函数文档,这引起了我的注意:

std::io::Result<()>

My understanding is that a Result should have a T and an E .我的理解是 Result 应该有一个T和一个E How can you substitute them with () ?你怎么能用()代替它们?

std::io::Result is a type alias specific to the std::io module, which is defined as std::io::Result是特定于std::io模块的类型别名,定义为

type Result<T> = Result<T, ::std::io::Error>;

Essentially, it's a std::result::Result with the error type prefilled as a std::io::Error .本质上,它是一个std::result::Result ,错误类型预填充为std::io::Error Using this type only requires one type parameter, which corresponds to the "ok" type T in Result<T,E> .使用这种类型只需要一个类型参数,它对应于Result<T,E>的“ok”类型T

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM