| Crates.io | string-adapter |
| lib.rs | string-adapter |
| version | 1.1.0 |
| created_at | 2024-12-28 16:45:23.336024+00 |
| updated_at | 2024-12-28 16:45:23.336024+00 |
| description | String adapter for casbin-rs |
| homepage | https://github.com/casbin-rs/string-adapter |
| repository | https://github.com/casbin-rs/string-adapter |
| max_upload_size | |
| id | 1497610 |
| size | 61,817 |
String Adapter is a String adapter for casbin-rs. With this library, Casbin can load policy from String.
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"] }
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(())
}
async-std as the runtime.tokio as the runtime (default).