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

Remove a protocol method

Overview

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

Initial State {#init}

FIDL {#fidl-init}

  1. protocol Example {
  2. ExistingMethod();
  3. OldMethod();
  4. };

Dart {#dart-init}

  1. class Server extends fidllib.Example {
  2. @override
  3. Future<void> existingMethod() async {}
  4. @override
  5. Future<void> oldMethod() async {}
  6. }
  7. void client(fidllib.ExampleProxy client) async {
  8. await client.existingMethod();
  9. await client.oldMethod();
  10. }

Go {#go-init}

  1. type client struct {
  2. removeMethod *lib.ExampleWithCtxInterface
  3. }
  4. func (c client) test() {
  5. c.removeMethod.ExistingMethod(context.Background())
  6. c.removeMethod.OldMethod(context.Background())
  7. }
  8. type server struct{}
  9. // Assert that server implements the Example interface
  10. var _ lib.ExampleWithCtx = &server{}
  11. func (*server) ExistingMethod(fidl.Context) error {
  12. return nil
  13. }
  14. func (*server) OldMethod(fidl.Context) error {
  15. return nil
  16. }

HLCPP {#hlcpp-init}

  1. class Server : public fidl_test::Example {
  2. void ExistingMethod() final {}
  3. void OldMethod() final {}
  4. };
  5. void client(fidl_test::ExamplePtr client) {
  6. client->ExistingMethod();
  7. client->OldMethod();
  8. }

LLCPP {#llcpp-init}

  1. class Server final : public fidl_test::Example::Interface {
  2. public:
  3. void ExistingMethod(ExistingMethodCompleter::Sync& completer) final {}
  4. void OldMethod(OldMethodCompleter::Sync& completer) final {}
  5. };
  6. void client(fidl::Client<fidl_test::Example> client) {
  7. client->ExistingMethod();
  8. client->OldMethod();
  9. }

Rust {#rust-init}

  1. struct ExampleFakeProxy;
  2. impl fidl_lib::ExampleProxyInterface for ExampleFakeProxy {
  3. fn existing_method(&self) -> Result<(), fidl::Error> {
  4. Ok(())
  5. }
  6. fn old_method(&self) -> Result<(), fidl::Error> {
  7. Ok(())
  8. }
  9. }
  10. async fn example_service(chan: fasync::Channel) -> Result<(), fidl::Error> {
  11. let mut stream = fidl_lib::ExampleRequestStream::from_channel(chan);
  12. while let Some(req) = stream.try_next().await? {
  13. match req {
  14. fidl_lib::ExampleRequest::ExistingMethod { .. } => {}
  15. fidl_lib::ExampleRequest::OldMethod { .. } => {}
  16. }
  17. }
  18. Ok(())
  19. }

Update FIDL Library {#step-1}

  • Mark the method that is being removed with the [Transitional] attribute.
  1. protocol Example {
  2. ExistingMethod();
  3. + [Transitional]
  4. OldMethod();
  5. };

Update Source Code {#step-2}

Dart {#dart-2}

  • Remove references to the method in client code and server code.
  1. class Server extends fidllib.Example {
  2. @override
  3. Future<void> existingMethod() async {}
  4. -
  5. - @override
  6. - Future<void> oldMethod() async {}
  7. }
  8. void client(fidllib.ExampleProxy client) async {
  9. await client.existingMethod();
  10. - await client.oldMethod();
  11. }

Go {#go-2}

  • Embed the protocol’s WithCtxTransitionBase struct into the server type.
  • Remove the implementation for the method being removed from the server.
  • Remove any references to the method in client code (e.g. request calls being made)
  1. type client struct {
  2. removeMethod *lib.ExampleWithCtxInterface
  3. }
  4. func (c client) test() {
  5. c.removeMethod.ExistingMethod(context.Background())
  6. - c.removeMethod.OldMethod(context.Background())
  7. }
  8. - type server struct{}
  9. + type server struct {
  10. + lib.ExampleWithCtxInterface
  11. + }
  12. // Assert that server implements the Example interface
  13. var _ lib.ExampleWithCtx = &server{}
  14. func (*server) ExistingMethod(fidl.Context) error {
  15. return nil
  16. }
  17. - func (*server) OldMethod(fidl.Context) error {
  18. - return nil
  19. - }
  20. -

HLCPP {#hlcpp-2}

  • Remove references to the method in client code and server code.
  1. class Server : public fidl_test::Example {
  2. void ExistingMethod() final {}
  3. - void OldMethod() final {}
  4. };
  5. - void client(fidl_test::ExamplePtr client) {
  6. - client->ExistingMethod();
  7. - client->OldMethod();
  8. - }
  9. + void client(fidl_test::ExamplePtr client) { client->ExistingMethod(); }

LLCPP {#llcpp-2}

  • Remove references to the method in client code and server code.
  1. class Server final : public fidl_test::Example::Interface {
  2. public:
  3. void ExistingMethod(ExistingMethodCompleter::Sync& completer) final {}
  4. - void OldMethod(OldMethodCompleter::Sync& completer) final {}
  5. };
  6. - void client(fidl::Client<fidl_test::Example> client) {
  7. - client->ExistingMethod();
  8. - client->OldMethod();
  9. - }
  10. + void client(fidl::Client<fidl_test::Example> client) { client->ExistingMethod(); }

Rust {#rust-2}

  • Add #[allow(unreachable_patterns)] to the server’s request stream match.
  • Replace the match arm for the method that is being removed with a catchall (_) arm.
  • Remove any references to the method in client code (e.g. as part of implementations of the ProxyInterface).
  1. struct ExampleFakeProxy;
  2. impl fidl_lib::ExampleProxyInterface for ExampleFakeProxy {
  3. fn existing_method(&self) -> Result<(), fidl::Error> {
  4. - Ok(())
  5. - }
  6. - fn old_method(&self) -> Result<(), fidl::Error> {
  7. Ok(())
  8. }
  9. }
  10. async fn example_service(chan: fasync::Channel) -> Result<(), fidl::Error> {
  11. let mut stream = fidl_lib::ExampleRequestStream::from_channel(chan);
  12. while let Some(req) = stream.try_next().await? {
  13. + #[allow(unreachable_patterns)]
  14. match req {
  15. fidl_lib::ExampleRequest::ExistingMethod { .. } => {}
  16. - fidl_lib::ExampleRequest::OldMethod { .. } => {}
  17. + _ => {}
  18. }
  19. }
  20. Ok(())
  21. }

Update FIDL Library {#step-3}

  • Remove the method.
  1. protocol Example {
  2. ExistingMethod();
  3. - [Transitional]
  4. - OldMethod();
  5. };

Update Source Code {#step-4}

Go {#go-4}

  • Remove the embedded WithCtxInterface struct.
  1. type client struct {
  2. removeMethod *lib.ExampleWithCtxInterface
  3. }
  4. func (c client) test() {
  5. c.removeMethod.ExistingMethod(context.Background())
  6. }
  7. - type server struct {
  8. - lib.ExampleWithCtxInterface
  9. - }
  10. + type server struct{}
  11. // Assert that server implements the Example interface
  12. var _ lib.ExampleWithCtx = &server{}
  13. func (*server) ExistingMethod(fidl.Context) error {
  14. return nil
  15. }

Rust {#rust-4}

  • Remove the #[allow(unreachable_patterns)] attribute and the catch-all match arm.
  1. struct ExampleFakeProxy;
  2. impl fidl_lib::ExampleProxyInterface for ExampleFakeProxy {
  3. fn existing_method(&self) -> Result<(), fidl::Error> {
  4. Ok(())
  5. }
  6. }
  7. async fn example_service(chan: fasync::Channel) -> Result<(), fidl::Error> {
  8. let mut stream = fidl_lib::ExampleRequestStream::from_channel(chan);
  9. while let Some(req) = stream.try_next().await? {
  10. - #[allow(unreachable_patterns)]
  11. match req {
  12. fidl_lib::ExampleRequest::ExistingMethod { .. } => {}
  13. - _ => {}
  14. }
  15. }
  16. Ok(())
  17. }