/* This Source Code Form is subject to the terms of the Mozilla Public *License,v.2.0.IfacopyoftheMPLwasnotdistributedwiththis
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#![allow(non_snake_case)]
#[macro_use] externcrate xpcom;
externcrate nserror; externcrate nsstring;
use nserror::{nsresult, NS_OK}; use nsstring::nsACString; use std::ffi::{CStr, CString}; use std::os::raw::c_char; use std::ptr; use xpcom::{interfaces, RefPtr};
let topic = CString::new("test-rust-observe").unwrap();
letmut run = false; let observer = Observer::allocate(InitObserver { run: &mut run }); let rv = obssvc.AddObserver(
observer.coerce::<interfaces::nsIObserver>(),
topic.as_ptr(), false,
);
assert!(rv.succeeded());
let rv = obssvc.NotifyObservers(ptr::null(), topic.as_ptr(), ptr::null());
assert!(rv.succeeded());
assert!(run, "The observer should have been run!");
let rv = obssvc.RemoveObserver(observer.coerce::<interfaces::nsIObserver>(), topic.as_ptr());
assert!(rv.succeeded());
assert!(
observer.coerce::<interfaces::nsISupports>() as *const _
== &*observer
.query_interface::<interfaces::nsISupports>()
.unwrap() as *const _
);
&*obssvc
}
#[no_mangle] pubunsafeextern"C"fn Rust_ImplementRunnableInRust(
it_worked: *mut bool,
runnable: *mut *const interfaces::nsIRunnable,
) { // Define a type which implements nsIRunnable in rust. #[xpcom(implement(nsIRunnable), atomic)] struct RunnableFn<F: Fn() + 'static> {
run: F,
}
#[no_mangle] pubunsafeextern"C"fn Rust_GetMultipleInterfaces(
runnable: *mut *const interfaces::nsIRunnable,
observer: *mut *const interfaces::nsIObserver,
) { // Define a type which implements nsIRunnable and nsIObserver in rust, and // hand both references back to c++ #[xpcom(implement(nsIRunnable, nsIObserver), atomic)] struct MultipleInterfaces {}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.