از 27 مارس 2025، توصیه می کنیم از android-latest-release
به جای aosp-main
برای ساختن و کمک به AOSP استفاده کنید. برای اطلاعات بیشتر، به تغییرات AOSP مراجعه کنید.
معرفی Android Rust
با مجموعهها، منظم بمانید
ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
پلتفرم اندروید برای توسعه اجزای سیستم عامل بومی در Rust، یک زبان برنامهنویسی سیستمی مدرن که تضمینهای ایمنی حافظه را با عملکردی معادل C/C++ ارائه میکند، پشتیبانی میکند. Rust از ترکیبی از بررسیهای زمان کامپایل استفاده میکند که طول عمر و مالکیت شی را اعمال میکند، و بررسیهای زمان اجرا که دسترسی معتبر به حافظه را تضمین میکند، در نتیجه نیاز به جمعآوری زباله را از بین میبرد.
Rust طیف وسیعی از ویژگیهای زبان مدرن را ارائه میکند که به توسعهدهندگان اجازه میدهد در کد خود سازندهتر و مطمئنتر باشند:
- برنامه نویسی همزمان ایمن - سهولتی که با این کار به کاربران امکان می دهد کدهای کارآمد و ایمن را بنویسند، شعار Concurrency بدون ترس Rust را به وجود آورده است.
- سیستم نوع بیانی - Rust با اجازه دادن به انواع بسیار رسا (مانند Wrappers Newtype و انواع enum با محتوا) به جلوگیری از اشکالات برنامهنویسی منطقی کمک میکند.
- بررسیهای قویتر در زمان کامپایل - باگهای بیشتر در زمان کامپایل، اعتماد توسعهدهنده را افزایش میدهد که وقتی کد با موفقیت کامپایل میشود، همانطور که در نظر گرفته شده است کار میکند.
- چارچوب تست داخلی - Rust یک چارچوب تست داخلی را ارائه میکند که در آن تستهای واحد را میتوان در کنار پیادهسازیهایی که آزمایش میکنند قرار داد، و گنجاندن تست واحد را آسانتر میکند.
- اجرای مدیریت خطا - توابع با خرابی های قابل بازیابی می توانند یک نوع نتیجه را برگردانند که یا یک نوع موفقیت یا یک نوع خطا خواهد بود. کامپایلر از فراخوانکنندگان میخواهد تا نوع خطای
Result
enum را که از فراخوانی تابع بازگردانده شده است، بررسی کرده و آن را مدیریت کنند. این پتانسیل باگ های ناشی از خرابی های کنترل نشده را کاهش می دهد. - مقداردهی اولیه - Rust مستلزم آن است که هر متغیری قبل از استفاده به یک عضو قانونی از نوع خود مقداردهی اولیه شود و از مقدار دهی اولیه ناخواسته به مقدار ناامن جلوگیری می کند.
- مدیریت اعداد صحیح امنتر - همه تبدیلهای نوع صحیح، کستهای صریح هستند. برنامهنویسها نمیتوانند در طول فراخوانی تابع هنگام تخصیص به یک متغیر، یا هنگام تلاش برای انجام محاسبات با انواع دیگر، تصادفاً ارسال کنند. بررسی سرریز به طور پیشفرض در Android برای Rust روشن است، که نیاز به صریح بودن عملیات سرریز دارد.
برای اطلاعات بیشتر، سری پست های وبلاگ را در مورد پشتیبانی Android Rust ببینید:
محتوا و نمونه کدها در این صفحه مشمول پروانههای توصیفشده در پروانه محتوا هستند. جاوا و OpenJDK علامتهای تجاری یا علامتهای تجاری ثبتشده Oracle و/یا وابستههای آن هستند.
تاریخ آخرین بهروزرسانی 2025-07-29 بهوقت ساعت هماهنگ جهانی.
[null,null,["تاریخ آخرین بهروزرسانی 2025-07-29 بهوقت ساعت هماهنگ جهانی."],[],[],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."]]