-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
glendc
committed
Apr 18, 2024
1 parent
f69dd87
commit 98aaf50
Showing
8 changed files
with
153 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
venndb-usage/tests/compiles/derive_struct_with_validator.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
use venndb::VennDB; | ||
|
||
#[derive(Debug, VennDB)] | ||
#[venndb(validator = sealed::employee_validator)] | ||
struct Employee { | ||
pub id: u32, | ||
pub name: String, | ||
pub is_manager: bool, | ||
pub is_admin: bool, | ||
pub is_active: bool, | ||
pub department: Department, | ||
} | ||
|
||
#[derive(Debug)] | ||
pub enum Department { | ||
Engineering, | ||
Sales, | ||
Marketing, | ||
HR, | ||
} | ||
|
||
mod sealed { | ||
use super::Employee; | ||
|
||
pub(super) fn employee_validator(employee: &Employee) -> bool { | ||
employee.id > 0 && !employee.name.is_empty() | ||
} | ||
} | ||
|
||
fn main() { | ||
let _ = EmployeeDB::new(); | ||
} |
28 changes: 28 additions & 0 deletions
28
venndb-usage/tests/fails/derive_struct_with_validator_str.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
use venndb::VennDB; | ||
|
||
#[derive(Debug, VennDB)] | ||
#[venndb(validator = "employee_validator")] | ||
struct Employee { | ||
pub id: u32, | ||
pub name: String, | ||
pub is_manager: bool, | ||
pub is_admin: bool, | ||
pub is_active: bool, | ||
pub department: Department, | ||
} | ||
|
||
#[derive(Debug)] | ||
pub enum Department { | ||
Engineering, | ||
Sales, | ||
Marketing, | ||
HR, | ||
} | ||
|
||
fn employee_validator(employee: &Employee) -> bool { | ||
employee.id > 0 && !employee.name.is_empty() | ||
} | ||
|
||
fn main() { | ||
let _ = EmployeeDB::new(); | ||
} |
5 changes: 5 additions & 0 deletions
5
venndb-usage/tests/fails/derive_struct_with_validator_str.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
error: Expected path attribute, found "employee_validator" attribute (literal) | ||
--> tests/fails/derive_struct_with_validator_str.rs:4:22 | ||
| | ||
4 | #[venndb(validator = "employee_validator")] | ||
| ^^^^^^^^^^^^^^^^^^^^ |