検索
Results of 1 - 10 of about 22 for Err (0.002 sec.)
- Result - Rust By Example 日本語版 11952
- Introduction 1. Hello World ❱ 1.1. コメント 1.2. フォーマットしてプリント ❱ 1.2.1. デバッグ 1.2.
...lue をラップします。( value は型 T を持ちます。) Err(why) ... これはオペレーションの失敗を意味します。...y の型は E です。) mod checked { // Mathematical "errors" we want to catch // 補足対象としたい、数学的な...「エラー」 #[derive(Debug)] pub enum MathError { DivisionByZero, NonPositiveLogarithm, Negative...quareRoot, } pub type MathResult = Result<f64, MathError>; pub fn div(x: f64, y: f64) -> MathResult { if... - https://man.plustar.jp/rust/example/std/result.html - [similar]
- ? - Rust By Example 日本語版 11716
- Introduction 1. Hello World ❱ 1.1. コメント 1.2. フォーマットしてプリント ❱ 1.2.1. デバッグ 1.2.
...and is equivalent to a match expression, where the Err(err) branch expands to an early Err(From::from(err...xpression. mod checked { #[derive(Debug)] enum MathError { DivisionByZero, NonPositiveLogarithm, Negative...SquareRoot, } type MathResult = Result<f64, MathError>; fn div(x: f64, y: f64) -> MathResult { if y ==...0.0 { Err(MathError::DivisionByZero) } else { Ok(x / y) } }... - https://man.plustar.jp/rust/example/std/result/question_mark.html - [similar]
- Resultのmap - Rust By Example 日本語版 11228
- Introduction 1. Hello World ❱ 1.1. コメント 1.2. フォーマットしてプリント ❱ 1.2.1. デバッグ 1.2.
...ようなエラー型を扱っているのかを知る必要があります。 Err 型を定めるために、 i32 に対し FromStr トレートを使...って実装された parse() を見てみましょう。結果、 Err 型は ParseIntError というものであることが分かります...扱いづらいコードにしています。 use std::num::ParseIntError; // With the return type rewritten, we use patte...r, second_number_str: &str) -> Result<i32, ParseIntError> { match first_number_str.parse::<i32>() { Ok(fi... - https://man.plustar.jp/rust/example/error/result/result_map.html - [similar]
- ?の他の活用法 - Rust By Example 日本語版 10117
- Introduction 1. Hello World ❱ 1.1. コメント 1.2. フォーマットしてプリント ❱ 1.2.1. デバッグ 1.2.
...していました。 .and_then(|s| s.parse::<i32>() .map_err(|e| e.into()) 簡単でよくあるオペレーションのため、...? なら使えます。 ? の挙動は、 unwrap または return Err(err) として説明されていました。これはほぼ正解で、本...当は unwrap 、もしくは return Err(From::from(err)) という意味があります。 From::from...の結果、 From::from がエラー型に実装されている時 map_err は消えてなくなります。 use std::error; use std::fm... - https://man.plustar.jp/rust/example/error/multiple_error_types/reenter_question_... - [similar]
- ファイルシステムとのやり取り - Rust By Example 日本語版 9881
- Introduction 1. Hello World ❱ 1.1. コメント 1.2. フォーマットしてプリント ❱ 1.2.1. デバッグ 1.2.
...; match f.read_to_string(&mut s) { Ok(_) => Ok(s), Err(e) => Err(e), } } // A simple implementation of `%...te(true).write(true).open(path) { Ok(_) => Ok(()), Err(e) => Err(e), } } fn main() { println!("`mkdir a`"...返り値は`io::Result<()>` match fs::create_dir("a") { Err(why) => println!("! {:?}", why.kind()), Ok(_) => {...a/c/b.txt`"); match cat(&Path::new("a/c/b.txt")) { Err(why) => println!("! {:?}", why.kind()), Ok(s) => p... - https://man.plustar.jp/rust/example/std_misc/fs.html - [similar]
- 早期リターン - Rust By Example 日本語版 9764
- Introduction 1. Hello World ❱ 1.1. コメント 1.2. フォーマットしてプリント ❱ 1.2.1. デバッグ 1.2.
...バージョンを考えてみましょう。 use std::num::ParseIntError; fn multiply(first_number_str: &str, second_numb...er_str: &str) -> Result<i32, ParseIntError> { let first_number = match first_number_str.par...se::<i32>() { Ok(first_number) => first_number, Err(e) => return Err(e), }; let second_number = match...rse::<i32>() { Ok(second_number) => second_number, Err(e) => return Err(e), }; Ok(first_number * second_n... - https://man.plustar.jp/rust/example/error/result/early_returns.html - [similar]
- エラー型を定義する - Rust By Example 日本語版 9393
- Introduction 1. Hello World ❱ 1.1. コメント 1.2. フォーマットしてプリント ❱ 1.2.1. デバッグ 1.2.
...ッセージを提供する 他の型との比較を楽にする 良い例: Err(EmptyVec) 悪い例: Err("Please use a vector with at..._owned()) エラーについての情報を保持できる 良い例: Err(BadChar(c, position)) 悪い例: Err("+ cannot be use...o_owned()) 他のエラーと問題なく連携できる use std::error; use std::fmt; type Result<T> = std::result::Res...ult<T, DoubleError>; // Define our error types. These may be custom... - https://man.plustar.jp/rust/example/error/multiple_error_types/define_error_type... - [similar]
- ?の導入 - Rust By Example 日本語版 9023
- Introduction 1. Hello World ❱ 1.1. コメント 1.2. フォーマットしてプリント ❱ 1.2.1. デバッグ 1.2.
...を要求しました。そして、これがまさに ? の目的です。 Err を見つけるにあたり、2つのとるべき行動があります。...可能な限り避けたいと決めた panic! Err は処理できないことを意味するため return ? は ほぼ...1 まさしく、 Err に対して panic するより return するという点で unwr...簡潔に書けるか見てみましょう。 use std::num::ParseIntError; fn multiply(first_number_str: &str, second_numb... - https://man.plustar.jp/rust/example/error/result/enter_question_mark.html - [similar]
- Result - Rust By Example 日本語版 8299
- Introduction 1. Hello World ❱ 1.1. コメント 1.2. フォーマットしてプリント ❱ 1.2.1. デバッグ 1.2.
...つの結果を持ちます。 Ok<T> : 要素 T が見つかった場合 Err<E> : 要素 E とともにエラーが見つかった場合 慣例によ...り、 Ok が期待される結果であり、 Err は期待されない結果です。 Option と同様、 Result は...バーする内容に触れていきます。 use std::num::ParseIntError; fn main() -> Result<(), ParseIntError> { let nu...number_str.parse::<i32>() { Ok(number) => number, Err(e) => return Err(e), }; println!("{}", number); Ok... - https://man.plustar.jp/rust/example/error/result.html - [similar]
- TryFromおよびTryInto - Rust By Example 日本語版 7929
- Introduction 1. Hello World ❱ 1.1. コメント 1.2. フォーマットしてプリント ❱ 1.2.1. デバッグ 1.2.
...mber(i32); impl TryFrom<i32> for EvenNumber { type Error = (); fn try_from(value: i32) -> Result<Self, Se...lf::Error> { if value % 2 == 0 { Ok(EvenNumber(value)) } e...lse { Err(()) } } } fn main() { // TryFrom assert_eq!(EvenNu...enNumber(8))); assert_eq!(EvenNumber::try_from(5), Err(())); // TryInto let result: Result<EvenNumber, ()... - https://man.plustar.jp/rust/example/conversion/try_from_try_into.html - [similar]