1 /*
2 * Copyright (c) 2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 //! #[cxx::bridge]
17 #[cxx::bridge]
18 mod ffi{
19 #![allow(dead_code)]
20 #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
21 struct Shared {
22 z: usize,
23 }
24 extern "Rust"{
print_message_in_rust()25 fn print_message_in_rust();
r_return_primitive() -> usize26 fn r_return_primitive() -> usize;
r_return_shared() -> Shared27 fn r_return_shared() -> Shared;
r_return_rust_string() -> String28 fn r_return_rust_string() -> String;
r_return_sum(_: usize, _: usize) -> usize29 fn r_return_sum(_: usize, _: usize) -> usize;
30 }
31 }
32
print_message_in_rust()33 fn print_message_in_rust(){
34 println!("Here is a test for cpp call Rust.");
35 }
r_return_shared() -> ffi::Shared36 fn r_return_shared() -> ffi::Shared {
37 println!("Here is a message from Rust,test for ffi::Shared:");
38 ffi::Shared { z: 1996 }
39 }
r_return_primitive() -> usize40 fn r_return_primitive() -> usize {
41 println!("Here is a message from Rust,test for usize:");
42 1997
43 }
r_return_rust_string() -> String44 fn r_return_rust_string() -> String {
45 println!("Here is a message from Rust,test for String");
46 "Hello World!".to_owned()
47 }
r_return_sum(n1: usize, n2: usize) -> usize48 fn r_return_sum(n1: usize, n2: usize) -> usize {
49 println!("Here is a message from Rust,test for {} + {} is:",n1 ,n2);
50 n1 + n2
51 }
52