簡體   English   中英

如何處理 rust 中的自定義字符串錯誤?

[英]How to work with custom string errors in rust?

如何在 rust 中返回我自己的字符串錯誤?

fn main()->std::io::Result<(),std::io::Error>{
    let a = 30;
    if a==10{
        println!("ten");
    }else if a==20{
        println!("twenty");
    }else {
        Err("Not ten or twenty".to_string())
    }
    Ok(())

}

這給

| fn main()->std::io::Result<(),std::io::Error>{
| 

                          ^^^^^^^^^^^^^^ unexpected type argument

如何在 rust 中返回我自己的字符串錯誤?

fn main()->std::io::Result<(),std::io::Error>{
    let a = 30;
    if a==10{
        println!("ten");
    }else if a==20{
        println!("twenty");
    }else {
        Err("Not ten or twenty".to_string())
    }
    Ok(())

}

這給

| fn main()->std::io::Result<(),std::io::Error>{
| 

                          ^^^^^^^^^^^^^^ unexpected type argument

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM