WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Replace String engine parameters with impl AsRef<str> #445

@lucamuscat

Description

@lucamuscat

Hey 👋

Most Engine struct parameters that accept strings in their parameters mainly use String, which requires unneccessary heap allocations in scenarios where a simple &'static str will do. For instance, Engine::add_policy's example may be written to the following assuming that impl AsRef<str> is used instead of String; note how to_string() has been removed:

let mut engine = Engine::new();

let package = engine.add_policy(
   "test.rego",
   r#"
   package test
   allow = input.user == "root"
   "#)?;

assert_eq!(package, "data.test");

I am happy to contribute this change myself if you guys want to go ahead with the suggestion.

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