Skip to content

Improve on using features of a dependency in plrust function #325

@anth0nyleung

Description

@anth0nyleung

PL/Rust does not handle using features for a dependencies quite well currently.

For instance, I have made serde an allowed dependency with the feature derive

$ > cat plrust_allowed_dependencies.toml
serde = { version = "1.0", features = ["derive"] }

But when i try to define a function with serde as dependency and enable the derive marco, it errors out because it expect the value of a dependency to be a string not a toml table

postgres=# CREATE FUNCTION foo (r INT, g INT, b INT) RETURNS INT AS
$$
CREATE FUNCTION table_deps (r INT, g INT, b INT) RETURNS TEXT STRICT AS
$$
                  [dependencies]
                  serde = { version = "1.0", features = ["derive"] }
                  rand = "*"
                  
                  [code]
                  use serde::{Serialize, Deserialize};
                  
                  #[derive(Debug, Serialize, Deserialize)]
                  struct Color {
                       r: u8,
                       g: u8,
                       b: u8,
                  }
                  
                  let r = r as u8;
                  let g = g as u8;
                  let b = b as u8;
                  
                  Ok(Some(format!("{:?}", Color{ r, g, b})))
                  $$ language plrust;        
$$ language plrust;

ERROR:
   0: dependency serde with values Table({"features": Array([String("derive")]), "version": String("1.0")}) is malformatted. Only strings are supported

Location:
   plrust/src/user_crate/mod.rs:355

Backtrace omitted. Run with RUST_BACKTRACE=1 environment variable to display it.
Run with RUST_BACKTRACE=full to include source snippets.
postgres=#

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions