example of using enum to be more explicit about data

This commit is contained in:
Chris Cochrun 2023-11-20 17:38:48 -06:00
parent 586db06b3a
commit adc8bc8c04
2 changed files with 34 additions and 1 deletions

View file

@ -62,6 +62,18 @@ mod image_model {
TitleRole,
}
impl FromStr for Role {
type Err = ();
fn from_str(input: &str) -> Result<Role, Self::Err> {
match input {
"id" => Ok(Role::IdRole),
"title" => Ok(Role::TitleRole),
"path" => Ok(Role::PathRole),
_ => Err(()),
}
}
}
// use crate::entities::{images, prelude::Images};
// use sea_orm::{ConnectionTrait, Database, DbBackend, DbErr, Statement, ActiveValue};
impl qobject::ImageModel {