From 968460819919dd02af289578fa3f8d6b65f11f0f Mon Sep 17 00:00:00 2001 From: lur1an Date: Thu, 18 Jul 2024 22:28:06 +0200 Subject: [PATCH] update docs --- README.md | 24 +++++------------------- 1 file changed, 5 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index d1146ef..5a1f1b8 100644 --- a/README.md +++ b/README.md @@ -69,20 +69,13 @@ impl Actor for MyActor { struct Document; +#[derive(IntoStaticStr)] +#[strum(serialize_all = "snake_case")] pub enum DocumentPermission { Read, Write, } -impl Permission for DocumentPermission { - fn name(&self) -> &'static str { - match self { - DocumentPermission::Read => "read", - DocumentPermission::Write => "write", - } - } -} - impl Entity for Document { type Relations = DocumentRelation; type Id = String; @@ -92,26 +85,19 @@ impl Entity for Document { } } +#[derive(IntoStaticStr)] +#[strum(serialize_all = "snake_case")] pub enum DocumentRelation { Reader, Writer, } -impl Relation for DocumentRelation { - fn name(&self) -> &'static str { - match self { - DocumentRelation::Reader => "reader", - DocumentRelation::Writer => "writer", - } - } -} - impl Resource for Document { type Permissions = DocumentPermission; } ``` -> **_NOTE:_** Will be working on some `strum` integration to cut down on the quite obvious boilerplate that turns the enum variants into strings. +> **_NOTE:_** The boilerplate for `Relations` and `Permissions` is gone thanks to the `IntoStaticStr` macro from the `strum` crate, this crate also re-exports it. This type system now makes it impossible to check for a permission that doesn't exist, or create a relationship not supported for an entity.