Skip to content

Commit d4d4f68

Browse files
Fix arbitrary impl
Signed-off-by: John Kastner <[email protected]>
1 parent 5bc3f4e commit d4d4f68

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

cedar-policy-core/src/ast/entity.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ impl std::fmt::Display for EntityType {
6464

6565
/// Unique ID for an entity. These represent entities in the AST.
6666
#[derive(Serialize, Deserialize, Debug, Clone)]
67-
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
6867
pub struct EntityUID {
6968
/// Typename of the entity
7069
ty: EntityType,
@@ -216,6 +215,17 @@ impl FromNormalizedStr for EntityUID {
216215
}
217216
}
218217

218+
#[cfg(feature = "arbitrary")]
219+
impl<'a> arbitrary::Arbitrary<'a> for EntityUID {
220+
fn arbitrary(u: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result<Self> {
221+
Ok(Self {
222+
ty: u.arbitrary()?,
223+
eid: u.arbitrary()?,
224+
loc: None,
225+
})
226+
}
227+
}
228+
219229
/// EID type is just a SmolStr for now
220230
#[derive(Serialize, Deserialize, PartialEq, Eq, Debug, Clone, Hash, PartialOrd, Ord)]
221231
pub struct Eid(SmolStr);

cedar-policy-core/src/ast/name.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ use super::PrincipalOrResource;
3030
/// The name can include namespaces.
3131
/// Clone is O(1).
3232
#[derive(Debug, Clone)]
33-
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
3433
pub struct Name {
3534
/// Basename
3635
pub(crate) id: Id,
@@ -218,6 +217,17 @@ impl FromNormalizedStr for Name {
218217
}
219218
}
220219

220+
#[cfg(feature = "arbitrary")]
221+
impl<'a> arbitrary::Arbitrary<'a> for Name {
222+
fn arbitrary(u: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result<Self> {
223+
Ok(Self {
224+
id: u.arbitrary()?,
225+
path: u.arbitrary()?,
226+
loc: None,
227+
})
228+
}
229+
}
230+
221231
struct NameVisitor;
222232

223233
impl<'de> serde::de::Visitor<'de> for NameVisitor {

0 commit comments

Comments
 (0)