Загрузка...

How to read text from a file | Rust Language

Read all bytes from a reader into a new String with std::io::read_to_string
The match expression handles Ok and Error conditions.

Further reading :
More about "Ok" and "Err" - they are made from Result :

🔗 https://doc.rust-lang.org/nightly/std/result/enum.Result.html
🔗 https://www.becomebetterprogrammer.com/rust-generic-error-types/

Functions return Result whenever errors are expected and recoverable. In the std crate, Result is most prominently used for I/O.

(Result T, E is a common data type that allows propagating Rust errors without necessarily crashing the Rust program unless the program panics).

View the code here : 🔗 https://gist.github.com/RGGH/0de3e6e91d416de9d17c67d6ed6bf608

For more on match expressions check out the Rust docs:
🔗 https://doc.rust-lang.org/reference/expressions/match-expr.html

View the Rust playlist : 🔗 https://youtube.com/playlist?list=PL38rDfx7QwKbB24PRKjwAGYuyXMwKMvQl

It would be amazing if you want to support my channel via Patreon:
Patreon := 🔗 https://www.patreon.com/join/3552586

#rustlang #rusttutorial #howtoreadtextfile

Видео How to read text from a file | Rust Language канала Learning Rust
Яндекс.Метрика
Все заметки Новая заметка Страницу в заметки
Страницу в закладки Мои закладки
На информационно-развлекательном портале SALDA.WS применяются cookie-файлы. Нажимая кнопку Принять, вы подтверждаете свое согласие на их использование.
О CookiesНапомнить позжеПринять