更改 API
让我们扩展API以提供更多功能:我们希望允许客户端指定生日贺卡的行列表:
1. package com.example.birthdayservice;
3. /** Birthday service interface. */
4. interface IBirthdayService {
5. /** Generate a Happy Birthday message. */
6. String wishHappyBirthday(String name, int years, in String[] text);
7. }
This results in an updated trait definition for IBirthdayService:
1. trait IBirthdayService {
2. fn wishHappyBirthday(
3. &self,
4. name: &str,
5. years: i32,
6. text: &[String],
7. ) -> binder::Result<String>;
8. }
- Note how the
String[]in the AIDL definition is translated as a&[String]in Rust, i.e. that idiomatic Rust types are used in the generated bindings wherever possible: inarray arguments are translated to slices.outandinoutargs are translated to&mut Vec<T>.- Return values are translated to returning a
Vec<T>.
