as.carbon 658 B

12345678910111213141516171819202122232425
  1. // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. // Exceptions. See /LICENSE for license information.
  3. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. package Core library "prelude/operators/as";
  5. import library "prelude/copy";
  6. interface UnsafeAs(Dest:! type) {
  7. fn Convert[self: Self]() -> Dest;
  8. }
  9. interface As(Dest:! type) {
  10. // TODO: extend UnsafeAs(Dest);
  11. fn Convert[self: Self]() -> Dest;
  12. }
  13. interface ImplicitAs(Dest:! type) {
  14. // TODO: extend As(Dest);
  15. fn Convert[self: Self]() -> Dest;
  16. }
  17. impl forall [T:! Copy] T as ImplicitAs(T) {
  18. fn Convert[self: Self]() -> Self { return self.(Copy.Op)(); }
  19. }