microsoft / microsoft/regorus

Replace `String` engine parameters with `impl AsRef<str>`

Open
#445 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
346
Forks
75
Avg merge
1d 3h
Merged PRs (30d)
15

Description

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.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Engine API and the Engine::add_policy documentation example. Audit the other Engine parameters that accept String, then review the relevant tests and API compatibility. Done means string literals can be passed without to_string() wherever the change applies, with tests and documentation still passing.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
backend-api-design
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.