更改 API

让我们扩展API以提供更多功能:我们希望允许客户端指定生日贺卡的行列表:

  1. package com.example.birthdayservice;
  2. /** Birthday service interface. */
  3. interface IBirthdayService {
  4. /** Generate a Happy Birthday message. */
  5. String wishHappyBirthday(String name, int years, in String[] text);
  6. }

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:
    • in array arguments are translated to slices.
    • out and inout args are translated to &mut Vec<T>.
    • Return values are translated to returning a Vec<T>.