Skip to main content

hicc_std/
lib.rs

1//! ## 使用方式
2//!
3//! 注:
4//! 1. `hicc-std`仅提供了`std::string`, `std::u16string`, `std::u32string`相关的构造函数.
5//! 1. `v0.2.0`版本, 通过增加参数校验,消除了原接口中可能抛出的各种异常.
6//!    部分接口的返回值类型发生了变化.
7//!
8//! 因为都是模板类,需要使用者显式实现实例化模版类的构建函数. 参见如下代码:
9//!
10//! ```text
11//! use hicc::AbicClass;
12//!
13//! hicc::cpp! {
14//!     // c++侧需要引用hicc提供的头文件.
15//!     #include <hicc/std/map.hpp>
16//!     #include <hicc/std/string.hpp>
17//!
18//!     // 按需定义容器类型. 可以包含非缺省的Allocator等模版参数类型.
19//!     typedef std::map<int, std::string> CppMap;
20//! }
21//!
22//! hicc::import_lib! {
23//!     #![link_name = "example"]
24//!
25//!     // 对应`c++`的`CppMap`
26//!     class RustMap = hicc_std::map<hicc::Pod<i32>, hicc_std::string>;
27//!
28//!     // 创建容器接口.
29//!     #[cpp(func = "std::unique_ptr<CppMap> hicc::make_unique<CppMap>()")]
30//!     fn rustmap_new() -> RustMap;
31//! }
32//!
33//! fn main() {
34//!     let mut map = rustmap_new();
35//!     let name = hicc_std::string::from(hicc::cstr!("hello"));
36//!     map.insert(&0, &name);
37//!     assert_eq!(map.get(&1), None);
38//!     assert_eq!(map.get(&0), Some(name.as_ref()));
39//! }
40//! ```
41//!
42//! **注意**:
43//! > 1. 模版参数类型只能是`c++`类或者可直接在`CABI`接口上传递使用的`POD`数据类型,后者只能结合`hicc::Pod<T>`使用.
44//!
45//! 3. `build.rs`编译`c++`代码
46//!
47//! ```text
48//! fn main() {
49//!     hicc_build::Build::new().rust_file("src/main.rs").compile("example");
50//!     println!("cargo::rustc-link-lib=example");
51//!     println!("cargo::rustc-link-lib=stdc++");
52//!     println!("cargo::rerun-if-changed=src/main.rs");
53//! }
54//! ```
55//!
56//! `hicc_build`仅支持生成静态库, 需要最终构建为可执行程序或者动态库时指定所依赖的`c++`标准库.
57//!
58//! ## 迭代器接口说明
59//!
60//! `c++`容器基于迭代器实现插入删除等接口违背`rust`的借用规则, `hicc-std`将迭代器做了二次封装,提供容器遍历和插入删除功能.
61//!
62//! ## 测试
63//!
64//! `doc test`需要开启`test feature`, 提供了测试用例用到的容器实例化类型的构建函数.
65//!
66//! ```text
67//! # cargo test --features "test"
68//! ```
69//!
70
71mod std_string;
72pub use std_string::*;
73
74mod std_array;
75pub use std_array::*;
76
77mod std_deque;
78pub use std_deque::*;
79
80mod std_vector;
81pub use std_vector::*;
82
83mod std_stack;
84pub use std_stack::*;
85
86mod std_queue;
87pub use std_queue::*;
88
89mod std_list;
90pub use std_list::*;
91
92mod std_forward_list;
93pub use std_forward_list::*;
94
95mod std_set;
96pub use std_set::*;
97
98mod std_unordered_set;
99pub use std_unordered_set::*;
100
101mod std_map;
102pub use std_map::*;
103
104mod std_unordered_map;
105pub use std_unordered_map::*;
106
107#[cfg(feature = "test")]
108mod std_test;
109#[cfg(feature = "test")]
110pub use std_test::*;
111