]> git.proxmox.com Git - perlmod.git/blob - perlmod-test/src/pkg142.rs
add reference deserialization test data
[perlmod.git] / perlmod-test / src / pkg142.rs
1 use serde::{Deserialize, Serialize};
2
3 use perlmod::Value;
4
5 #[derive(Debug, Deserialize, Serialize)]
6 pub struct Blubber(String);
7
8 #[derive(Debug, Deserialize, Serialize)]
9 pub struct RawRefs {
10 copied: String,
11
12 reference: Value,
13 }
14
15 #[perlmod::package(name = "RSPM::Foo142", lib = "perlmod_test")]
16 mod export {
17 use anyhow::{bail, Error};
18
19 use perlmod::Value;
20
21 #[export]
22 fn foo142(a: u32, b: u32) -> Result<u32, Error> {
23 if a == 42 {
24 bail!("dying on magic number");
25 }
26
27 Ok(a + b)
28 }
29
30 #[export]
31 fn test(t: Option<String>) -> Result<(), Error> {
32 println!("test called with {:?}", t);
33 Ok(())
34 }
35
36 #[export]
37 fn teststr(t: Option<&str>) -> Result<(), Error> {
38 println!("teststr called with {:?}", t);
39 Ok(())
40 }
41
42 #[export]
43 fn test_serde(value: super::Blubber) -> Result<String, Error> {
44 println!("got {:?}", value);
45 Ok(value.0)
46 }
47
48 #[export]
49 fn test_refs(data: super::RawRefs) -> Result<Value, Error> {
50 println!("test_refs: copied text: {:?}", data.copied);
51 Ok(data.reference)
52 }
53 }
54
55 #[perlmod::package(name = "RSPM::EnvVarLibrary", lib = "x-${CARGO_PKG_NAME}-y")]
56 mod expanded_export {
57 use anyhow::Error;
58
59 #[export]
60 fn test_lib_env_vars(value: &str) -> Result<(), Error> {
61 println!("foo: {:?}", value);
62 Ok(())
63 }
64 }