@@ -54,7 +54,7 @@ use std::str::FromStr;
54
54
55
55
/// Entity datatype
56
56
#[ repr( transparent) ]
57
- #[ derive( Debug , Clone , PartialEq , Eq , RefCast ) ]
57
+ #[ derive( Debug , Clone , PartialEq , Eq , RefCast , Hash ) ]
58
58
pub struct Entity ( ast:: Entity ) ;
59
59
60
60
impl Entity {
@@ -97,6 +97,16 @@ impl Entity {
97
97
) ?) )
98
98
}
99
99
100
+ /// Create a new `Entity` with this Uid, parents, and no attributes.
101
+ /// This is the same as `Self::new` except the attributes are empty, and therefore it can
102
+ /// return `Self` instead of `Result<Self>`
103
+ pub fn new_empty_attrs ( uid : EntityUid , parents : HashSet < EntityUid > ) -> Self {
104
+ Self ( ast:: Entity :: new_empty_attrs (
105
+ uid. into ( ) ,
106
+ parents. into_iter ( ) . map ( EntityUid :: into) . collect ( ) ,
107
+ ) )
108
+ }
109
+
100
110
/// Create a new `Entity` with no attributes.
101
111
///
102
112
/// Unlike [`Entity::new()`], this constructor cannot error.
@@ -338,6 +348,10 @@ impl Entities {
338
348
/// error if attributes have the wrong types (e.g., string instead of
339
349
/// integer), or if required attributes are missing or superfluous
340
350
/// attributes are provided.
351
+ /// ## Errors
352
+ /// - [`EntitiesError::Duplicate`] if there are any duplicate entities in `entities`
353
+ /// - [`EntitiesError::InvalidEntity`] if `schema` is not none and any entities do not conform
354
+ /// to the schema
341
355
pub fn from_entities (
342
356
entities : impl IntoIterator < Item = Entity > ,
343
357
schema : Option < & Schema > ,
@@ -364,6 +378,10 @@ impl Entities {
364
378
///
365
379
/// Re-computing the transitive closure can be expensive, so it is advised
366
380
/// to not call this method in a loop.
381
+ /// ## Errors
382
+ /// - [`EntitiesError::Duplicate`] if there are any duplicate entities in `entities`
383
+ /// - [`EntitiesError::InvalidEntity`] if `schema` is not none and any entities do not conform
384
+ /// to the schema
367
385
pub fn add_entities (
368
386
self ,
369
387
entities : impl IntoIterator < Item = Entity > ,
@@ -394,6 +412,11 @@ impl Entities {
394
412
///
395
413
/// Re-computing the transitive closure can be expensive, so it is advised
396
414
/// to not call this method in a loop.
415
+ /// ## Errors
416
+ /// - [`EntitiesError::Duplicate`] if there are any duplicate entities in `entities`
417
+ /// - [`EntitiesError::InvalidEntity`] if `schema` is not none and any entities do not conform
418
+ /// to the schema
419
+ /// - [`EntitiesError::Deserialization`] if there are errors while parsing the json
397
420
pub fn add_entities_from_json_str (
398
421
self ,
399
422
json : & str ,
@@ -427,6 +450,11 @@ impl Entities {
427
450
///
428
451
/// Re-computing the transitive closure can be expensive, so it is advised
429
452
/// to not call this method in a loop.
453
+ /// ## Errors
454
+ /// - [`EntitiesError::Duplicate`] if there are any duplicate entities in `entities`
455
+ /// - [`EntitiesError::InvalidEntity`] if `schema` is not none and any entities do not conform
456
+ /// to the schema
457
+ /// - [`EntitiesError::Deserialization`] if there are errors while parsing the json
430
458
pub fn add_entities_from_json_value (
431
459
self ,
432
460
json : serde_json:: Value ,
@@ -460,6 +488,12 @@ impl Entities {
460
488
///
461
489
/// Re-computing the transitive closure can be expensive, so it is advised
462
490
/// to not call this method in a loop.
491
+ ///
492
+ /// ## Errors
493
+ /// - [`EntitiesError::Duplicate`] if there are any duplicate entities in `entities`
494
+ /// - [`EntitiesError::InvalidEntity`] if `schema` is not none and any entities do not conform
495
+ /// to the schema
496
+ /// - [`EntitiesError::Deserialization`] if there are errors while parsing the json
463
497
pub fn add_entities_from_json_file (
464
498
self ,
465
499
json : impl std:: io:: Read ,
@@ -497,6 +531,12 @@ impl Entities {
497
531
/// instead of integer), or if required attributes are missing or
498
532
/// superfluous attributes are provided.
499
533
///
534
+ /// ## Errors
535
+ /// - [`EntitiesError::Duplicate`] if there are any duplicate entities in `entities`
536
+ /// - [`EntitiesError::InvalidEntity`] if `schema` is not none and any entities do not conform
537
+ /// to the schema
538
+ /// - [`EntitiesError::Deserialization`] if there are errors while parsing the json
539
+ ///
500
540
/// ```
501
541
/// # use cedar_policy::{Entities, EntityId, EntityTypeName, EntityUid, EvalResult, Request,PolicySet};
502
542
/// # use std::str::FromStr;
@@ -552,6 +592,12 @@ impl Entities {
552
592
/// instead of integer), or if required attributes are missing or
553
593
/// superfluous attributes are provided.
554
594
///
595
+ /// ## Errors
596
+ /// - [`EntitiesError::Duplicate`] if there are any duplicate entities in `entities`
597
+ /// - [`EntitiesError::InvalidEntity`]if `schema` is not none and any entities do not conform
598
+ /// to the schema
599
+ /// - [`EntitiesError::Deserialization`] if there are errors while parsing the json
600
+ ///
555
601
/// ```
556
602
/// # use cedar_policy::{Entities, EntityId, EntityTypeName, EntityUid, EvalResult, Request,PolicySet};
557
603
/// let data =serde_json::json!(
@@ -603,6 +649,12 @@ impl Entities {
603
649
/// instance, it will error if attributes have the wrong types (e.g., string
604
650
/// instead of integer), or if required attributes are missing or
605
651
/// superfluous attributes are provided.
652
+ ///
653
+ /// ## Errors
654
+ /// - [`EntitiesError::Duplicate`] if there are any duplicate entities in `entities`
655
+ /// - [`EntitiesError::InvalidEntity`] if `schema` is not none and any entities do not conform
656
+ /// to the schema
657
+ /// - [`EntitiesError::Deserialization`] if there are errors while parsing the json
606
658
pub fn from_json_file (
607
659
json : impl std:: io:: Read ,
608
660
schema : Option < & Schema > ,
@@ -1485,7 +1537,7 @@ impl Schema {
1485
1537
1486
1538
/// Returns an iterator over every entity type that can be a principal for `action` in this schema
1487
1539
///
1488
- /// # Errors
1540
+ /// ## Errors
1489
1541
///
1490
1542
/// Returns [`None`] if `action` is not found in the schema
1491
1543
pub fn principals_for_action (
@@ -1499,7 +1551,7 @@ impl Schema {
1499
1551
1500
1552
/// Returns an iterator over every entity type that can be a resource for `action` in this schema
1501
1553
///
1502
- /// # Errors
1554
+ /// ## Errors
1503
1555
///
1504
1556
/// Returns [`None`] if `action` is not found in the schema
1505
1557
pub fn resources_for_action (
@@ -1513,7 +1565,7 @@ impl Schema {
1513
1565
1514
1566
/// Returns an iterator over all the entity types that can be an ancestor of `ty`
1515
1567
///
1516
- /// # Errors
1568
+ /// ## Errors
1517
1569
///
1518
1570
/// Returns [`None`] if the `ty` is not found in the schema
1519
1571
pub fn ancestors < ' a > (
0 commit comments