| <!-- WARNING: This file is machine generated by //src/tests/fidl/source_compatibility/gen, do not edit. --> |
| |
| Note: This document covers API impact only. For more details, see the |
| [ABI compatibility page](/docs/development/languages/fidl/guides/compatibility/README.md) |
| |
| # Remove an enum member |
| |
| ## Overview |
| |
| -|[init](#init)|[step 1](#step-1)|[step 2](#step-2)|[step 3](#step-3) |
| ---|---|---|---|--- |
| fidl|[link](#fidl-init)||[link](#fidl-2)| |
| dart|[link](#dart-init)|[link](#dart-1)|| |
| go|[link](#go-init)|[link](#go-1)|| |
| hlcpp|[link](#hlcpp-init)|[link](#hlcpp-1)|| |
| llcpp|[link](#llcpp-init)|[link](#llcpp-1)|| |
| rust|[link](#rust-init)|[link](#rust-1)||[link](#rust-3) |
| |
| ## Initial State {#init} |
| |
| ### FIDL {#fidl-init} |
| |
| ```fidl |
| type Color = flexible enum { |
| RED = 1; |
| BLUE = 2; |
| YELLOW = 3; |
| }; |
| ``` |
| |
| ### Dart {#dart-init} |
| |
| ```dart |
| fidllib.Color writer(String s) { |
| if (s == 'red') { |
| return fidllib.Color.red; |
| } else if (s == 'blue') { |
| return fidllib.Color.blue; |
| } else if (s == 'yellow') { |
| return fidllib.Color.yellow; |
| } else { |
| return fidllib.Color.$unknown; |
| } |
| } |
| |
| String reader(fidllib.Color color) { |
| switch (color) { |
| case fidllib.Color.blue: |
| return 'blue'; |
| case fidllib.Color.red: |
| return 'red'; |
| case fidllib.Color.yellow: |
| return 'yellow'; |
| default: |
| return '<unknown>'; |
| } |
| } |
| ``` |
| |
| ### Go {#go-init} |
| |
| ```go |
| func writer(s string) lib.Color { |
| switch s { |
| case "blue": |
| return lib.ColorBlue |
| case "red": |
| return lib.ColorRed |
| case "yellow": |
| return lib.ColorYellow |
| default: |
| return lib.Color_Unknown |
| } |
| } |
| |
| func reader(color lib.Color) string { |
| switch color { |
| case lib.ColorBlue: |
| return "blue" |
| case lib.ColorRed: |
| return "red" |
| case lib.ColorYellow: |
| return "yellow" |
| default: |
| return "<unknown>" |
| } |
| } |
| |
| ``` |
| |
| ### HLCPP {#hlcpp-init} |
| |
| ```cpp |
| fidl_test::Color writer(std::string s) { |
| if (s == "red") { |
| return fidl_test::Color::RED; |
| } else if (s == "blue") { |
| return fidl_test::Color::BLUE; |
| } else if (s == "yellow") { |
| return fidl_test::Color::YELLOW; |
| } else { |
| return fidl_test::Color::Unknown(); |
| } |
| } |
| |
| std::string reader(fidl_test::Color color) { |
| switch (color) { |
| case fidl_test::Color::RED: |
| return "red"; |
| case fidl_test::Color::BLUE: |
| return "blue"; |
| case fidl_test::Color::YELLOW: |
| return "yellow"; |
| default: |
| return "<unknown>"; |
| } |
| } |
| ``` |
| |
| ### LLCPP {#llcpp-init} |
| |
| ```cpp |
| fidl_test::wire::Color writer(std::string s) { |
| if (s == "red") { |
| return fidl_test::wire::Color::kRed; |
| } else if (s == "blue") { |
| return fidl_test::wire::Color::kBlue; |
| } else if (s == "yellow") { |
| return fidl_test::wire::Color::kYellow; |
| } else { |
| return fidl_test::wire::Color::Unknown(); |
| } |
| } |
| |
| std::string reader(fidl_test::wire::Color color) { |
| switch (color) { |
| case fidl_test::wire::Color::kRed: |
| return "red"; |
| case fidl_test::wire::Color::kBlue: |
| return "blue"; |
| case fidl_test::wire::Color::kYellow: |
| return "yellow"; |
| default: |
| return "<unknown>"; |
| } |
| } |
| ``` |
| |
| ### Rust {#rust-init} |
| |
| ```rust |
| fn writer(s: &str) -> fidl_lib::Color { |
| match s { |
| "red" => fidl_lib::Color::Red, |
| "blue" => fidl_lib::Color::Blue, |
| "yellow" => fidl_lib::Color::Yellow, |
| _ => fidl_lib::Color::unknown(), |
| } |
| } |
| |
| fn reader(color: fidl_lib::Color) -> &'static str { |
| match color { |
| fidl_lib::Color::Red => "red", |
| fidl_lib::Color::Blue => "blue", |
| fidl_lib::Color::Yellow => "yellow", |
| fidl_lib::ColorUnknown!() => "unknown", |
| } |
| } |
| ``` |
| |
| ## Update Source Code {#step-1} |
| |
| ### Dart {#dart-1} |
| |
| - Remove all references to the soon-to-be-removed member. |
| |
| ```diff |
| fidllib.Color writer(String s) { |
| if (s == 'red') { |
| return fidllib.Color.red; |
| } else if (s == 'blue') { |
| return fidllib.Color.blue; |
| - } else if (s == 'yellow') { |
| - return fidllib.Color.yellow; |
| } else { |
| return fidllib.Color.$unknown; |
| } |
| } |
| |
| String reader(fidllib.Color color) { |
| switch (color) { |
| case fidllib.Color.blue: |
| return 'blue'; |
| case fidllib.Color.red: |
| return 'red'; |
| - case fidllib.Color.yellow: |
| - return 'yellow'; |
| default: |
| return '<unknown>'; |
| } |
| } |
| |
| ``` |
| |
| ### Go {#go-1} |
| |
| - Remove all references to the soon-to-be-removed member. |
| |
| ```diff |
| func writer(s string) lib.Color { |
| switch s { |
| case "blue": |
| return lib.ColorBlue |
| case "red": |
| return lib.ColorRed |
| - case "yellow": |
| - return lib.ColorYellow |
| default: |
| return lib.Color_Unknown |
| } |
| } |
| |
| func reader(color lib.Color) string { |
| switch color { |
| case lib.ColorBlue: |
| return "blue" |
| case lib.ColorRed: |
| return "red" |
| - case lib.ColorYellow: |
| - return "yellow" |
| default: |
| return "<unknown>" |
| } |
| } |
| |
| |
| ``` |
| |
| ### HLCPP {#hlcpp-1} |
| |
| - Remove all references to the soon-to-be-removed member. |
| |
| ```diff |
| fidl_test::Color writer(std::string s) { |
| if (s == "red") { |
| return fidl_test::Color::RED; |
| } else if (s == "blue") { |
| return fidl_test::Color::BLUE; |
| - } else if (s == "yellow") { |
| - return fidl_test::Color::YELLOW; |
| } else { |
| return fidl_test::Color::Unknown(); |
| } |
| } |
| |
| std::string reader(fidl_test::Color color) { |
| switch (color) { |
| case fidl_test::Color::RED: |
| return "red"; |
| case fidl_test::Color::BLUE: |
| return "blue"; |
| - case fidl_test::Color::YELLOW: |
| - return "yellow"; |
| default: |
| return "<unknown>"; |
| } |
| } |
| |
| ``` |
| |
| ### LLCPP {#llcpp-1} |
| |
| - Remove all references to the soon-to-be-removed member. |
| |
| ```diff |
| fidl_test::wire::Color writer(std::string s) { |
| if (s == "red") { |
| return fidl_test::wire::Color::kRed; |
| } else if (s == "blue") { |
| return fidl_test::wire::Color::kBlue; |
| - } else if (s == "yellow") { |
| - return fidl_test::wire::Color::kYellow; |
| } else { |
| return fidl_test::wire::Color::Unknown(); |
| } |
| } |
| |
| std::string reader(fidl_test::wire::Color color) { |
| switch (color) { |
| case fidl_test::wire::Color::kRed: |
| return "red"; |
| case fidl_test::wire::Color::kBlue: |
| return "blue"; |
| - case fidl_test::wire::Color::kYellow: |
| - return "yellow"; |
| default: |
| return "<unknown>"; |
| } |
| } |
| |
| ``` |
| |
| ### 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. |
| |
| ```diff |
| fn writer(s: &str) -> fidl_lib::Color { |
| match s { |
| "red" => fidl_lib::Color::Red, |
| "blue" => fidl_lib::Color::Blue, |
| - "yellow" => fidl_lib::Color::Yellow, |
| _ => fidl_lib::Color::unknown(), |
| } |
| } |
| |
| fn reader(color: fidl_lib::Color) -> &'static str { |
| match color { |
| fidl_lib::Color::Red => "red", |
| fidl_lib::Color::Blue => "blue", |
| - fidl_lib::Color::Yellow => "yellow", |
| - fidl_lib::ColorUnknown!() => "unknown", |
| + _ => "unknown", |
| } |
| } |
| |
| ``` |
| |
| ## Update FIDL Library {#step-2} |
| |
| - Remove the enum member |
| |
| ```diff |
| type Color = flexible enum { |
| RED = 1; |
| BLUE = 2; |
| - YELLOW = 3; |
| }; |
| |
| ``` |
| |
| ## Update Source Code {#step-3} |
| |
| ### Rust {#rust-3} |
| |
| - Readers no longer need to handle the removed enum member in any switch statements. |
| |
| ```diff |
| fn writer(s: &str) -> fidl_lib::Color { |
| match s { |
| "red" => fidl_lib::Color::Red, |
| "blue" => fidl_lib::Color::Blue, |
| _ => fidl_lib::Color::unknown(), |
| } |
| } |
| |
| fn reader(color: fidl_lib::Color) -> &'static str { |
| match color { |
| fidl_lib::Color::Red => "red", |
| fidl_lib::Color::Blue => "blue", |
| - _ => "unknown", |
| + fidl_lib::ColorUnknown!() => "unknown", |
| } |
| } |
| |
| ``` |
| |