]>
Commit | Line | Data |
---|---|---|
ac1ed611 WB |
1 | //! Crate for creating perl packages/bindings for rust code. |
2 | //! | |
2991a46a WB |
3 | //! The main feature of this crate is the [`package`] macro provided by the `perlmod-macro` crate |
4 | //! and documented here. | |
ac1ed611 WB |
5 | //! |
6 | //! The underlying machinery for these macros is contained in this crate and provides ways to | |
7 | //! serialize and deserialize data between perl and rust. | |
8 | //! | |
3464d8b0 WB |
9 | //! # Blessed Values |
10 | //! | |
11 | //! This crate also provides all the tools required to bless perl values into packages, and | |
12 | //! associate rust data with perl values. | |
13 | //! There are multiple ways to do this, and they come with different issues. | |
14 | //! | |
15 | //! The currently recommended way is found in the documentation of the [`magic`] module, which is | |
16 | //! considered the least error prone. | |
17 | //! | |
18 | //! A less safe (and lower-level) example can be found in the documentation of the | |
19 | //! [`Value::bless`](Value::bless()) method. | |
20 | //! | |
ac1ed611 WB |
21 | //! [`package`]: attr.package.html |
22 | //! [`export`]: attr.export.html | |
ac1ed611 | 23 | |
083e8236 | 24 | pub mod error; |
87c10237 | 25 | pub use error::Error; |
f7cc8c37 | 26 | |
89989b0f WB |
27 | #[macro_use] |
28 | mod macros; | |
29 | ||
1e46bfbe | 30 | #[macro_use] |
f7cc8c37 | 31 | pub mod ffi; |
1e46bfbe WB |
32 | |
33 | pub mod de; | |
f7cc8c37 WB |
34 | pub mod ser; |
35 | ||
36 | #[doc(inline)] | |
dd7f83c3 | 37 | pub use de::{from_ref_value, from_value}; |
f7cc8c37 WB |
38 | #[doc(inline)] |
39 | pub use ser::to_value; | |
40 | ||
41 | pub mod scalar; | |
42 | #[doc(inline)] | |
245de6dd | 43 | pub use scalar::{Mortal, Scalar, ScalarRef}; |
f7cc8c37 WB |
44 | |
45 | pub mod array; | |
46 | #[doc(inline)] | |
47 | pub use array::Array; | |
48 | ||
49 | pub mod hash; | |
50 | #[doc(inline)] | |
51 | pub use hash::Hash; | |
52 | ||
53 | pub mod value; | |
54 | #[doc(inline)] | |
55 | pub use value::Value; | |
56 | ||
245de6dd WB |
57 | pub(crate) mod raw_value; |
58 | pub use raw_value::RawValue; | |
59 | ||
083e8236 WB |
60 | pub mod magic; |
61 | #[doc(inline)] | |
62 | pub use magic::{MagicSpec, MagicTag}; | |
63 | ||
f7cc8c37 | 64 | #[cfg(feature = "exporter")] |
42f7a45b | 65 | #[doc(inline)] |
7de9fdf0 WB |
66 | pub use perlmod_macro::package; |
67 | ||
68 | #[cfg(feature = "exporter")] | |
69 | #[doc(inline)] | |
70 | /// Attribute to export a function so that it can be installed as an `xsub` in perl. See the | |
71 | /// [`package!`](macro@package) macro for a usage example. | |
72 | /// | |
b78b6ceb WB |
73 | /// This macro has the following optional arguments: |
74 | /// | |
75 | /// * `raw_return`: specifies that the return type, which must be a [`Value`], will be returned as | |
76 | /// is, and not go through serialization. As of perlmod | |
77 | /// 0.6, serialization of a [`Value`] will not produce a clone, so this is mostly an | |
78 | /// optimization. | |
79 | /// * `prototype`: The perl prototype for the function. By default, this will be guessed from the | |
80 | /// parameters as a chain of '$', with trailing `Option<>` parameters behind a `;`. So for | |
81 | /// example, an `fn(i32, Option<i32>, i32, Option<i32>)` has the prototype `$$$;$`. | |
82 | /// * `xs_name`: override the name of the exported xsub, this is not recommended and only makes | |
83 | /// sense when *not* using the `#[package]` macro, as with the `#[package]` macro, these aren't | |
84 | /// publicly visible. | |
85 | /// * `name`: the name the function should be using in perl. This only makes sense with the | |
86 | /// `#[package]` macro, as otherwise the user is responsible for loading the function via perl's | |
87 | /// `DynaLoader` on their own. | |
7de9fdf0 WB |
88 | /// |
89 | /// Additionally, function parameters can also use the following attributes: | |
90 | /// | |
91 | /// * `#[raw]` with a parameter of type [`Value`]: The parameter will be passed as | |
d1743af5 WB |
92 | /// is and not go through deserialization. As of perlmod 0.6, deserialization will not produce |
93 | /// clones anymore, so this is mostly an optimization. | |
7de9fdf0 WB |
94 | /// * `#[try_from_ref]`: Instead of regular deserialization, `TryFrom::try_from(&Value)` will be |
95 | /// used. | |
96 | /// | |
97 | /// Implementing the `TryFrom` trait accordingly can make using blessed references more | |
98 | /// convenient, but at the cost of hiding underlying `unsafe` code. | |
d1743af5 WB |
99 | /// |
100 | /// For an example on making blessed objects, see [`Value::bless_box`](Value::bless_box()). | |
7de9fdf0 | 101 | pub use perlmod_macro::export; |