اعتبارًا من 27 آذار (مارس) 2025، ننصحك باستخدام android-latest-release
بدلاً من aosp-main
لإنشاء AOSP والمساهمة فيه. لمزيد من المعلومات، يُرجى الاطّلاع على التغييرات في AOSP.
مقدمة عن Android Rust
تنظيم صفحاتك في مجموعات
يمكنك حفظ المحتوى وتصنيفه حسب إعداداتك المفضّلة.
توفّر منصة Android إمكانية تطوير مكوّنات نظام التشغيل الأصلية بلغة Rust، وهي لغة حديثة لبرمجة الأنظمة توفّر ضمانات أمان الذاكرة مع أداء مماثل لـ C/C++. وتستخدم Rust مجموعة من عمليات التحقّق في وقت الترجمة التي تفرض مدة صلاحية العنصر وملكيته، وعمليات التحقّق في وقت التشغيل التي تضمن عمليات وصول صالحة إلى الذاكرة، ما يزيل الحاجة إلى أداة جمع المهملات.
توفّر Rust مجموعة من ميزات اللغة الحديثة التي تسمح للمطوّرين بالعمل بفعالية أكبر وثقة أكبر في رموزهم البرمجية:
- البرمجة المتزامنة الآمنة: إنّ سهولة استخدام هذه الميزة للمستخدمين في
كتابة رموز برمجية فعّالة وآمنة لعمليات المعالجة المتعدّدة قد أدّت إلى ظهور شعار Rust المتمثل في
البرمجة المتزامنة بلا خوف.
- نظام أنواع تعبيري: يساعد Rust في منع أخطاء البرمجة المنطقية من خلال
السماح بأنواع تعبيرية للغاية (مثل أدوات تغليف Newtype وأنواع ملف السجلّ
التي تحتوي على محتويات).
- عمليات تحقّق أقوى في وقت الترجمة: إنّ اكتشاف المزيد من الأخطاء في وقت الترجمة يزيد من ثقة المطوّر بأنّه عند ترجمة الرمز البرمجي بنجاح، سيعمل على النحو المقصود.
- إطار عمل الاختبار المضمّن: توفّر Rust إطار عمل اختبار مضمّنًا
يمكن من خلاله وضع اختبارات الوحدة بجانب التنفيذ الذي يتم اختباره، ما يسهّل
تضمين اختبارات الوحدة.
- فرض معالجة الأخطاء: يمكن للوظائف التي تتضمّن أخطاء قابلة للاسترداد
عرض نوع النتيجة،
والذي سيكون إما صيغًا للنجاح أو صيغًا للأخطاء. يطلب المُجمِّع من المُرسِلين التحقّق من متغير الخطأ في قائمة القيم الثابتة
Result
المُسترَدة من طلب استدعاء دالة ومعالجته. ويؤدي ذلك إلى تقليل احتمالية حدوث أخطاء نتيجةً لعدم معالجة حالات الفشل.
- الإعداد: تتطلّب Rust إعداد كل متغيّر ليكون عضوًا شرعيًا
من نوعه قبل الاستخدام، ما يمنع الإعداد غير المقصود
لقيمة غير آمنة.
- معالجة أعداد صحيحة أكثر أمانًا: جميع عمليات التحويل من النوع الصحيح هي عمليات تحويل صريحة.
لا يمكن للمطوّرين إجراء عملية تحويل عن طريق الخطأ أثناء استدعاء دالة عند تعيينها
لمتغيّر، أو عند محاولة إجراء عمليات حسابية بأنواع أخرى. يكون التحقّق من overflow
مفعَّلاً تلقائيًا في Android لبرنامج Rust، ما يتطلّب أن تكون عمليات overflow
صريحة.
لمزيد من المعلومات، يُرجى الاطّلاع على سلسلة المشاركات في المدونة حول إتاحة Rust على Android:
يخضع كل من المحتوى وعيّنات التعليمات البرمجية في هذه الصفحة للتراخيص الموضحّة في ترخيص استخدام المحتوى. إنّ Java وOpenJDK هما علامتان تجاريتان مسجَّلتان لشركة Oracle و/أو الشركات التابعة لها.
تاريخ التعديل الأخير: 2025-07-27 (حسب التوقيت العالمي المتفَّق عليه)
[[["يسهُل فهم المحتوى.","easyToUnderstand","thumb-up"],["ساعَدني المحتوى في حلّ مشكلتي.","solvedMyProblem","thumb-up"],["غير ذلك","otherUp","thumb-up"]],[["لا يحتوي على المعلومات التي أحتاج إليها.","missingTheInformationINeed","thumb-down"],["الخطوات معقدة للغاية / كثيرة جدًا.","tooComplicatedTooManySteps","thumb-down"],["المحتوى قديم.","outOfDate","thumb-down"],["ثمة مشكلة في الترجمة.","translationIssue","thumb-down"],["مشكلة في العيّنات / التعليمات البرمجية","samplesCodeIssue","thumb-down"],["غير ذلك","otherDown","thumb-down"]],["تاريخ التعديل الأخير: 2025-07-27 (حسب التوقيت العالمي المتفَّق عليه)"],[],[],null,["# Android Rust introduction\n\nThe Android platform provides support for developing native OS components in Rust,\na modern systems-programming language that provides memory safety guarantees with\nperformance equivalent to C/C++. Rust uses a combination of compile-time checks\nthat enforce object lifetime and ownership, and runtime checks that ensure valid\nmemory accesses, thereby eliminating the need for a garbage collector.\n\nRust provides a range of modern language features which allow developers to be\nmore productive and confident in their code:\n\n- **Safe concurrent programming** - The ease with which this allows users to write efficient, thread-safe code has given rise to Rust's [Fearless Concurrency](https://doc.rust-lang.org/book/ch16-00-concurrency.html) slogan.\n- **Expressive type system** - Rust helps prevent logical programming bugs by allowing for highly expressive types (such as Newtype wrappers, and enum variants with contents).\n- **Stronger Compile-time Checks** - More bugs caught at compile-time increases developer confidence that when code compiles successfully, it works as intended.\n- **Built-in Testing Framework** - Rust provides a built-in testing framework where unit tests can be placed alongside the implementation they test, making unit testing easier to include.\n- **Error handling enforcement** - Functions with recoverable failures can return a [Result type](https://doc.rust-lang.org/book/ch09-02-recoverable-errors-with-result.html), which will be either a success variant or an error variant. The compiler requires callers to check for and handle the error variant of a `Result` enum returned from a function call. This reduces the potential for bugs resulting from unhandled failures.\n- **Initialization** - Rust requires every variable to be initialized to a legal member of its type before use, preventing an unintentional initialization to an unsafe value.\n- **Safer integer handling** - All integer-type conversions are explicit casts. Developers can't accidentally cast during a function call when assigning to a variable, or when attempting to do arithmetic with other types. Overflow checking is on by default in Android for Rust, which requires overflow operations to be explicit.\n\nFor more information, see the series of blog posts on Android Rust support:\n\n- [Rust in the Android Platform](https://security.googleblog.com/2021/04/rust-in-android-platform.html) \n Provides an overview on why the Android team introduced Rust as a new platform language.\n- [Integrating Rust into the Android Open Source Project](https://security.googleblog.com/2021/05/integrating-rust-into-android-open.html) \n Discusses how Rust support has been introduced to the build system, and why certain design decisions were made.\n- [Rust/C++ interop in the Android Platform](https://security.googleblog.com/2021/06/rustc-interop-in-android-platform.html) \n Discusses the approach to Rust/C++ interoperability within Android."]]