Note: This document covers API impact only. For more details, see the ABI compatibility page

Remove an enum member

Overview

- init step 1 step 2 step 3
fidl link link
dart link link
go link link
hlcpp link link
llcpp link link
rust link link link

Initial State {#init}

FIDL {#fidl-init}

  1. flexible enum Color {
  2. RED = 1;
  3. BLUE = 2;
  4. YELLOW = 3;
  5. };

Dart {#dart-init}

  1. fidllib.Color writer(String s) {
  2. if (s == 'red') {
  3. return fidllib.Color.red;
  4. } else if (s == 'blue') {
  5. return fidllib.Color.blue;
  6. } else if (s == 'yellow') {
  7. return fidllib.Color.yellow;
  8. } else {
  9. return fidllib.Color.$unknown;
  10. }
  11. }
  12. String reader(fidllib.Color color) {
  13. switch (color) {
  14. case fidllib.Color.blue:
  15. return 'blue';
  16. case fidllib.Color.red:
  17. return 'red';
  18. case fidllib.Color.yellow:
  19. return 'yellow';
  20. default:
  21. return '<unknown>';
  22. }
  23. }

Go {#go-init}

  1. func writer(s string) lib.Color {
  2. switch s {
  3. case "blue":
  4. return lib.ColorBlue
  5. case "red":
  6. return lib.ColorRed
  7. case "yellow":
  8. return lib.ColorYellow
  9. default:
  10. return lib.Color_Unknown
  11. }
  12. }
  13. func reader(color lib.Color) string {
  14. switch color {
  15. case lib.ColorBlue:
  16. return "blue"
  17. case lib.ColorRed:
  18. return "red"
  19. case lib.ColorYellow:
  20. return "yellow"
  21. default:
  22. return "<unknown>"
  23. }
  24. }

HLCPP {#hlcpp-init}

  1. fidl_test::Color writer(std::string s) {
  2. if (s == "red") {
  3. return fidl_test::Color::RED;
  4. } else if (s == "blue") {
  5. return fidl_test::Color::BLUE;
  6. } else if (s == "yellow") {
  7. return fidl_test::Color::YELLOW;
  8. } else {
  9. return fidl_test::Color::Unknown();
  10. }
  11. }
  12. std::string reader(fidl_test::Color color) {
  13. switch (color) {
  14. case fidl_test::Color::RED:
  15. return "red";
  16. case fidl_test::Color::BLUE:
  17. return "blue";
  18. case fidl_test::Color::YELLOW:
  19. return "yellow";
  20. default:
  21. return "<unknown>";
  22. }
  23. }

LLCPP {#llcpp-init}

  1. fidl_test::Color writer(std::string s) {
  2. if (s == "red") {
  3. return fidl_test::Color::RED;
  4. } else if (s == "blue") {
  5. return fidl_test::Color::BLUE;
  6. } else if (s == "yellow") {
  7. return fidl_test::Color::YELLOW;
  8. } else {
  9. return fidl_test::Color::Unknown();
  10. }
  11. }
  12. std::string reader(fidl_test::Color color) {
  13. switch (color) {
  14. case fidl_test::Color::RED:
  15. return "red";
  16. case fidl_test::Color::BLUE:
  17. return "blue";
  18. case fidl_test::Color::YELLOW:
  19. return "yellow";
  20. default:
  21. return "<unknown>";
  22. }
  23. }

Rust {#rust-init}

  1. fn writer(s: &str) -> fidl_lib::Color {
  2. match s {
  3. "red" => fidl_lib::Color::Red,
  4. "blue" => fidl_lib::Color::Blue,
  5. "yellow" => fidl_lib::Color::Yellow,
  6. _ => fidl_lib::Color::unknown(),
  7. }
  8. }
  9. fn reader(color: fidl_lib::Color) -> &'static str {
  10. match color {
  11. fidl_lib::Color::Red => "red",
  12. fidl_lib::Color::Blue => "blue",
  13. fidl_lib::Color::Yellow => "yellow",
  14. fidl_lib::ColorUnknown!() => "unknown",
  15. }
  16. }

Update Source Code {#step-1}

Dart {#dart-1}

  • Remove all references to the soon-to-be-removed member.
  1. fidllib.Color writer(String s) {
  2. if (s == 'red') {
  3. return fidllib.Color.red;
  4. } else if (s == 'blue') {
  5. return fidllib.Color.blue;
  6. - } else if (s == 'yellow') {
  7. - return fidllib.Color.yellow;
  8. } else {
  9. return fidllib.Color.$unknown;
  10. }
  11. }
  12. String reader(fidllib.Color color) {
  13. switch (color) {
  14. case fidllib.Color.blue:
  15. return 'blue';
  16. case fidllib.Color.red:
  17. return 'red';
  18. - case fidllib.Color.yellow:
  19. - return 'yellow';
  20. default:
  21. return '<unknown>';
  22. }
  23. }

Go {#go-1}

  • Remove all references to the soon-to-be-removed member.
  1. func writer(s string) lib.Color {
  2. switch s {
  3. case "blue":
  4. return lib.ColorBlue
  5. case "red":
  6. return lib.ColorRed
  7. - case "yellow":
  8. - return lib.ColorYellow
  9. default:
  10. return lib.Color_Unknown
  11. }
  12. }
  13. func reader(color lib.Color) string {
  14. switch color {
  15. case lib.ColorBlue:
  16. return "blue"
  17. case lib.ColorRed:
  18. return "red"
  19. - case lib.ColorYellow:
  20. - return "yellow"
  21. default:
  22. return "<unknown>"
  23. }
  24. }

HLCPP {#hlcpp-1}

  • Remove all references to the soon-to-be-removed member.
  1. fidl_test::Color writer(std::string s) {
  2. if (s == "red") {
  3. return fidl_test::Color::RED;
  4. } else if (s == "blue") {
  5. return fidl_test::Color::BLUE;
  6. - } else if (s == "yellow") {
  7. - return fidl_test::Color::YELLOW;
  8. } else {
  9. return fidl_test::Color::Unknown();
  10. }
  11. }
  12. std::string reader(fidl_test::Color color) {
  13. switch (color) {
  14. case fidl_test::Color::RED:
  15. return "red";
  16. case fidl_test::Color::BLUE:
  17. return "blue";
  18. - case fidl_test::Color::YELLOW:
  19. - return "yellow";
  20. default:
  21. return "<unknown>";
  22. }
  23. }

LLCPP {#llcpp-1}

  • Remove all references to the soon-to-be-removed member.
  1. fidl_test::Color writer(std::string s) {
  2. if (s == "red") {
  3. return fidl_test::Color::RED;
  4. } else if (s == "blue") {
  5. return fidl_test::Color::BLUE;
  6. - } else if (s == "yellow") {
  7. - return fidl_test::Color::YELLOW;
  8. } else {
  9. return fidl_test::Color::Unknown();
  10. }
  11. }
  12. std::string reader(fidl_test::Color color) {
  13. switch (color) {
  14. case fidl_test::Color::RED:
  15. return "red";
  16. case fidl_test::Color::BLUE:
  17. return "blue";
  18. - case fidl_test::Color::YELLOW:
  19. - return "yellow";
  20. default:
  21. return "<unknown>";
  22. }
  23. }

Rust {#rust-1}

  • Remove all references to the soon-to-be-removed member. For readers, the member should be temporarily handled as part of a catch-all case.
  1. fn writer(s: &str) -> fidl_lib::Color {
  2. match s {
  3. "red" => fidl_lib::Color::Red,
  4. "blue" => fidl_lib::Color::Blue,
  5. - "yellow" => fidl_lib::Color::Yellow,
  6. _ => fidl_lib::Color::unknown(),
  7. }
  8. }
  9. fn reader(color: fidl_lib::Color) -> &'static str {
  10. match color {
  11. fidl_lib::Color::Red => "red",
  12. fidl_lib::Color::Blue => "blue",
  13. - fidl_lib::Color::Yellow => "yellow",
  14. - fidl_lib::ColorUnknown!() => "unknown",
  15. + _ => "unknown",
  16. }
  17. }

Update FIDL Library {#step-2}

  • Remove the enum member
  1. flexible enum Color {
  2. RED = 1;
  3. BLUE = 2;
  4. - YELLOW = 3;
  5. };

Update Source Code {#step-3}

Rust {#rust-3}

  • Readers no longer need to handle the removed enum member in any switch statements.
  1. fn writer(s: &str) -> fidl_lib::Color {
  2. match s {
  3. "red" => fidl_lib::Color::Red,
  4. "blue" => fidl_lib::Color::Blue,
  5. _ => fidl_lib::Color::unknown(),
  6. }
  7. }
  8. fn reader(color: fidl_lib::Color) -> &'static str {
  9. match color {
  10. fidl_lib::Color::Red => "red",
  11. fidl_lib::Color::Blue => "blue",
  12. - _ => "unknown",
  13. + fidl_lib::ColorUnknown!() => "unknown",
  14. }
  15. }