lib.rs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // Copyright 2016 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #![feature(maybe_uninit_slice)]
  5. #![feature(new_uninit)]
  6. // Require unsafe blocks for unsafe operations even in an unsafe fn.
  7. #![deny(unsafe_op_in_unsafe_fn)]
  8. #[macro_use]
  9. mod macros {
  10. /// This macro must be used at the top-level in any
  11. /// Rust Mojo application. It defines and abstracts away the
  12. /// hook needed by Mojo in order to set up the basic
  13. /// functionality (see mojo::system::ffi). It must take the
  14. /// name of a function who returns a MojoResult and takes
  15. /// exactly one argument: a mojo::handle::Handle, or on in
  16. /// other words, an untyped handle.
  17. #[macro_export]
  18. macro_rules! set_mojo_main {
  19. ( $fn_main:ident ) => {
  20. #[allow(bad_style)]
  21. #[no_mangle]
  22. pub fn MojoMain(app_request_handle: mojo::system::MojoHandle) -> mojo::MojoResult {
  23. use mojo::system::CastHandle;
  24. use std::panic;
  25. let handle = unsafe {
  26. mojo::system::message_pipe::MessageEndpoint::from_untyped(
  27. mojo::system::acquire(app_request_handle),
  28. )
  29. };
  30. let result = panic::catch_unwind(|| $fn_main(handle));
  31. match result {
  32. Ok(value) => value,
  33. Err(_) => mojo::MojoResult::Aborted,
  34. }
  35. }
  36. };
  37. }
  38. }
  39. #[macro_use]
  40. pub mod bindings;
  41. pub mod system;
  42. pub use crate::system::MojoResult;