TGViewer
Go Casts | Systems & Agents 🚀 Go Casts | Systems & Agents 🚀 @gocasts · 9.92K subscribers
Post #587 3.2K
یکی از چیزایی که از rust خیلی دوست دارم pattern matching هست، خیلی تر و تمیز و انعطاف پذیر هست.
اینجا بیشتر میتونید در موردش بخونید.
https://doc.rust-lang.org/book/ch06-00-enums.html

مثلا استفاده کردن match در کنار Result ENUM خیلی practice خوبی برای بررسی خروجی یک تابع یا متد هست.

اینطوری مجبور نیستی همه توابع رو طوری بنویسی که خروجی آخرشون error باشه (در گولنگ اینطوریه)

به کمک pattern matching هم خیلی خوانایی کد کمتر نمیشه بنظرم.

let greeting_file_result = File::open("hello.txt");

let greeting_file = match greeting_file_result {
Ok(file) => file,
Err(error) => match error.kind() {
ErrorKind::NotFound => match File::create("hello.txt") {
Ok(fc) => fc,
Err(e) => panic!("Problem creating the file: {e:?}"),
},
other_error => {
panic!("Problem opening the file: {other_error:?}");
}
},
};


از نظر error handling فکر میکنم نگاه مشترکی با گولنگ داره، از این نظر که خطاهارو دو دسته recoverable و unrecoverable میبینه که یکی رو با Result مدیریت میکنه و یکی رو با panic که فکر میکنم خیلی شبیه نگاه گولنگ هست.
Most languages don’t distinguish between these two kinds of errors and handle both in the same way, using mechanisms such as exceptions. Rust doesn’t have exceptions. Instead, it has the type Result<T, E> for recoverable errors and the panic! macro that stops execution when the program encounters an unrecoverable error.


@gocasts

#rust #golang
  • 👍 22
  • ❤ 2
  • 🔥 1
More from @gocasts
  1. Oct 9, 2026با یه پارادوکسی مواجه هستیم که خیلی مهمه درست درکش کنیم. وقتی در مورد کارایی که با ایجنت‌ه…
  2. Oct 4, 2026از دیروز چند آیتم ظاهری در GoCasts به‌روز شده 🚀 اگه دقت کرده باشید، لوگو، اسم کانال و بیو…
  3. Oct 1, 2026اینم از عمو باب که تسلیم شد! کاری ندارم که با ایشون هم نظر بودید و هستید یا نه. به دور از…
  4. Oct 1, 2026ترکیب Sonnet 5.5 و Opus 5.5 این روزا خیلی خوب جواب میده. الگویی که برای من جواب داده اینه:…
  5. Sep 24, 2026این بهترین تجربه‌ای بود که تا حالا با یه agent داشتم. دیشب با تاخیر چند ساعته ایمیل هاستین…
  6. Sep 23, 2026بچه ها اگه تجربه software factory جدی داشتید توی شرکت و سازمان و محصول تون، بهم فیدبک بدید…
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →