1 //! Crate for creating perl packages/bindings for rust code.
3 //! The main feature of this crate is the [`package`] macro provided by the `perlmod-macro` crate
4 //! and documented here.
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.
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.
15 //! The currently recommended way is found in the documentation of the [`magic`] module, which is
16 //! considered the least error prone.
18 //! A less safe (and lower-level) example can be found in the documentation of the
19 //! [`Value::bless`](Value::bless()) method.
21 //! [`package`]: attr.package.html
22 //! [`export`]: attr.export.html
37 pub use de
::{from_ref_value, from_value}
;
39 pub use ser
::to_value
;
43 pub use scalar
::{Mortal, Scalar, ScalarRef}
;
57 pub(crate) mod raw_value
;
58 pub use raw_value
::RawValue
;
62 pub use magic
::{MagicSpec, MagicTag}
;
64 #[cfg(feature = "exporter")]
66 pub use perlmod_macro
::package
;
68 #[cfg(feature = "exporter")]
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.
73 /// This macro has the following optional arguments:
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
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
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.
89 /// Additionally, function parameters can also use the following attributes:
91 /// * `#[raw]` with a parameter of type [`Value`]: The parameter will be passed as
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.
94 /// * `#[try_from_ref]`: Instead of regular deserialization, `TryFrom::try_from(&Value)` will be
97 /// Implementing the `TryFrom` trait accordingly can make using blessed references more
98 /// convenient, but at the cost of hiding underlying `unsafe` code.
100 /// For an example on making blessed objects, see [`Value::bless_box`](Value::bless_box()).
101 pub use perlmod_macro
::export
;