casbin / casbin-rs

An authorization library that supports access control models like ACL, RBAC, ABAC in Rust.
https://casbin.org
Apache License 2.0
861 stars 74 forks source link

feat: implement string adapter for model and policy #342

Closed sanbei101 closed 1 month ago

sanbei101 commented 1 month ago

This pull request introduces a new trait TryIntoModelFromStr and integrates it into the existing codebase. The main changes include adding the new trait, implementing it for &'static str, and updating the CoreApi and Enforcer to support the new trait. Additionally, new test cases have been added to ensure the functionality works as expected.

Introduction of TryIntoModelFromStr trait:

Integration into Enforcer:

Testing:

CLAassistant commented 1 month ago

CLA assistant check
All committers have signed the CLA.

github-actions[bot] commented 1 month ago

Benchmark for c5a05d3

Click to view benchmark | Test | PR Benchmark | Master Benchmark | % | |------|--------------|------------------|---| | b_benchmark_rbac_model_large | 10.0±0.03ms | **9.9±0.06ms** | **+1.01%** | | benchmark priority model | 4.2±0.07µs | 4.2±0.05µs | 0.00% | | benchmark_abac_model | 2.5±0.05µs | 2.5±0.03µs | 0.00% | | benchmark_basic_model | 3.8±0.07µs | 3.8±0.09µs | 0.00% | | benchmark_key_match | 7.1±0.16µs | 7.1±0.14µs | 0.00% | | benchmark_raw | 0.0±0.00ns | 0.0±0.00ns | NaN% | | benchmark_rbac_model | 6.1±0.10µs | 6.2±0.10µs | -1.61% | | benchmark_rbac_model_medium | 917.1±12.59µs | **846.3±9.78µs** | **+8.37%** | | benchmark_rbac_model_with_domains | 6.0±0.11µs | 6.0±0.10µs | 0.00% | | benchmark_rbac_with_deny | 8.7±0.13µs | 8.7±0.08µs | 0.00% | | benchmark_rbac_with_resource_roles | 4.5±0.04µs | 4.5±0.04µs | 0.00% | | benchmark_role_manager_large | 4.5±0.06ms | 4.5±0.04ms | 0.00% | | benchmark_role_manager_medium | 306.0±7.46µs | 303.7±4.45µs | +0.76% | | benchmark_role_manager_small | **92.2±2.32µs** | 96.1±6.76µs | **-4.06%** |
github-actions[bot] commented 1 month ago

Benchmark for c5a05d3

Click to view benchmark | Test | PR Benchmark | Master Benchmark | % | |------|--------------|------------------|---| | b_benchmark_rbac_model_large | **9.9±0.05ms** | 10.3±0.03ms | **-3.88%** | | benchmark priority model | 4.4±0.06µs | 4.4±0.07µs | 0.00% | | benchmark_abac_model | 2.6±0.03µs | 2.6±0.04µs | 0.00% | | benchmark_basic_model | 4.0±0.05µs | 4.0±0.07µs | 0.00% | | benchmark_key_match | 7.3±0.05µs | 7.3±0.08µs | 0.00% | | benchmark_raw | 0.0±0.00ns | 0.0±0.00ns | NaN% | | benchmark_rbac_model | **6.3±0.09µs** | 6.4±0.04µs | **-1.56%** | | benchmark_rbac_model_medium | 835.8±10.08µs | 831.7±11.53µs | +0.49% | | benchmark_rbac_model_with_domains | 6.2±0.07µs | 6.2±0.12µs | 0.00% | | benchmark_rbac_with_deny | **8.7±0.14µs** | 8.8±0.08µs | **-1.14%** | | benchmark_rbac_with_resource_roles | 4.6±0.05µs | 4.6±0.05µs | 0.00% | | benchmark_role_manager_large | 4.6±0.13ms | 4.6±0.07ms | 0.00% | | benchmark_role_manager_medium | **303.0±4.46µs** | 310.3±5.20µs | **-2.35%** | | benchmark_role_manager_small | 91.3±1.12µs | **90.1±1.31µs** | **+1.33%** |