]> git.proxmox.com Git - proxmox.git/commit
api-macro: support external types
authorWolfgang Bumiller <w.bumiller@proxmox.com>
Thu, 28 Nov 2019 09:42:34 +0000 (10:42 +0100)
committerWolfgang Bumiller <w.bumiller@proxmox.com>
Thu, 28 Nov 2019 09:42:35 +0000 (10:42 +0100)
commit4f042f8133b315d9aa0b8605ff0e48eaead20bb2
tree2b461c8b2c5878fbaf57a353102c5ef68c3ed28b
parent2fc2df9a78dad6034f0cd00778a485722a6cf66b
api-macro: support external types

See the test example:

assuming a `pub struct Foo` which implements `Serialize` and
`Deserialize`, we also expect it to provide a
`pub const Foo::API_SCHEMA: &Schema` like so:

    #[derive(Deserialize, Serialize)]
    pub struct StrongString(String);
    impl StrongString {
        pub const API_SCHEMA: &'static Schema =
            &StringSchema::new("Some generic string")
                .format(&ApiStringFormat::Enum(&["a", "b"]))
                .schema();
    }

Then we can use:

    #[api(
        input: {
            properties: {
                arg: { type: StrongString },
            }
        },
        ...
    )]
    fn my_api_func(arg: StrongString) -> Result<...> {
        ...
    }

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
proxmox-api-macro/src/api.rs
proxmox-api-macro/src/api/method.rs
proxmox-api-macro/src/util.rs
proxmox-api-macro/tests/types.rs [new file with mode: 0644]