ycliper

Популярное

Музыка Кино и Анимация Автомобили Животные Спорт Путешествия Игры Юмор

Интересные видео

2025 Сериалы Трейлеры Новости Как сделать Видеоуроки Diy своими руками

Топ запросов

смотреть а4 schoolboy runaway турецкий сериал смотреть мультфильмы эдисон
Скачать

Options - Rust Programming

Автор: Code Bits

Загружено: 2023-08-14

Просмотров: 514

Описание: In rust, Option is an enum with two variants. It can either have some value, or be None. It is used to represent the presence or absence of a value.

Using Option
This division function will return None if denominator is 0.
Otherwise it will return the value wrapped in Some.

Unwrapping
You cannot straight away use an option, you must handle it. You can use unwrap to get the value, but it will panic if the option is None.

Unwrap-or
```rust
let result = divide(4.0, 0.0).unwrap_or(-1.0);
println!("{result}"); // -1.0.
```
You can safely unwrap by using unwrap or method. This will return the default value if the option is None.

Match
A safe way to handle options is to use match. However, this syntax is not commonly used


If-Let
Instead, we can use if let syntax. This is a shorthand for match. It is more concise and readable

#rustlang #coding

Не удается загрузить Youtube-плеер. Проверьте блокировку Youtube в вашей сети.
Повторяем попытку...
Options - Rust Programming

Поделиться в:

Доступные форматы для скачивания:

Скачать видео

  • Информация по загрузке:

Скачать аудио

Похожие видео

A Simpler Way to See Results

A Simpler Way to See Results

Understanding Rust Closures aka. Anonymous Functions 🦀 💻

Understanding Rust Closures aka. Anonymous Functions 🦀 💻

AKTU Data Structures Unit 2 One Shot | Stack & Queue | BCS301 | Easy Exam Preparation

AKTU Data Structures Unit 2 One Shot | Stack & Queue | BCS301 | Easy Exam Preparation

You're probably misusing unwrap in Rust...let's fix that

You're probably misusing unwrap in Rust...let's fix that

Rust: Store Data on the Heap with Box

Rust: Store Data on the Heap with Box

Choose the Right Option

Choose the Right Option

Rust

Rust

Why Rust is NOT a Passing Fad...

Why Rust is NOT a Passing Fad...

Rust: Iterators

Rust: Iterators

Полиморфизм на основе Rust ⚡️ с чертами

Полиморфизм на основе Rust ⚡️ с чертами

Understand Rust's Borrow Checker in 5 Minutes

Understand Rust's Borrow Checker in 5 Minutes

Getting started with Tokio. The ultimate starter guide to writing async Rust.

Getting started with Tokio. The ultimate starter guide to writing async Rust.

Rust's Most Important Containers 📦 10 Useful Patterns

Rust's Most Important Containers 📦 10 Useful Patterns

9 Rust Best Practices with Real Lib (part 1/3)

9 Rust Best Practices with Real Lib (part 1/3)

Как взломать любое программное обеспечение

Как взломать любое программное обеспечение

Rust Programming Tutorial #37 - Option (Enum)

Rust Programming Tutorial #37 - Option (Enum)

Распаковка самого умного банкомата Сбера с ИИ и голосовым ассистентом

Распаковка самого умного банкомата Сбера с ИИ и голосовым ассистентом

Линус Торвальдс в ярости из-за предложения RISC-V

Линус Торвальдс в ярости из-за предложения RISC-V

Zig Language | Мысли спустя 2 года

Zig Language | Мысли спустя 2 года

Error Handling in Rust

Error Handling in Rust

© 2025 ycliper. Все права защищены.



  • Контакты
  • О нас
  • Политика конфиденциальности



Контакты для правообладателей: [email protected]