String adapter for Casbin-RS (Rust)

Clone this repo:

Branches

Tags

  1. 44bed6b feat: add docs for StringAdapter::new() (#4) by LiuliFox · 1 year, 3 months ago master
  2. 5e911a6 chore: fix email address typo (#5) by LiuliFox · 1 year, 3 months ago
  3. 2b51956 feat: bump version to 1.1.0 by Yang Luo · 1 year, 3 months ago v1.1.0
  4. 496e0c0 fix: remove lock file, improve gitignore by Yang Luo · 1 year, 3 months ago
  5. 6332432 feat: add auto release and Codecov coverage ci & remove duplicate code (#3) by LiuliFox · 1 year, 3 months ago

string-adapter

Crates.io Docs CI codecov

String Adapter is a String adapter for casbin-rs. With this library, Casbin can load policy from String.

Install

Add the following to Cargo.toml:

string-adapter = { version = "1.1.0", default-features = false, features = ["runtime-tokio"]}
tokio = { version = "1.42.0", features = ["macros"] }

Example

use casbin::{CoreApi, DefaultModel, Enforcer, Result};
use string_adapter::StringAdapter;

#[tokio::main]
async fn main() -> Result<()> {
    let m = DefaultModel::from_file("examples/rbac_model.conf").await?;

    let a = StringAdapter::new(
        r#"
        p, alice, data1, read
        p, bob, data2, write
        p, data2_admin, data2, read
        p, data2_admin, data2, write
        g, alice, data2_admin
        "#,
    );

    let e = Enforcer::new(m, a).await?;

    Ok(())
}

Features

  • runtime-async-std: Use async-std as the runtime.
  • runtime-tokio: Use tokio as the runtime (default).