Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cedar-policy/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- `PolicyId::new()` added to `PolicyId` (#587, resolving #551)
- `AsRef<str>` implementation for `PolicyId`. (#504, resolving #503)
- New API `template_links` for `Policy` to retrieve the linked values for a
template-linked policy. (#515, resolving #489)
Expand Down
11 changes: 9 additions & 2 deletions cedar-policy/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2691,18 +2691,25 @@ impl TemplateResourceConstraint {

/// Unique ids assigned to policies and templates.
///
/// A `PolicyId` can can be constructed using [`PolicyId::from_str`] or by
/// A [`PolicyId`] can can be constructed using [`PolicyId::from_str`] or by
/// calling `parse()` on a string. This currently always returns `Ok()`.
///
/// ```
/// # use cedar_policy::PolicyId;
/// let id : PolicyId = "my-id".parse().unwrap();
/// let id = PolicyId::new("my-id");
/// # assert_eq!(id.as_ref(), "my-id");
/// ```
#[repr(transparent)]
#[derive(Debug, PartialEq, Eq, Clone, Hash, Serialize, Deserialize, RefCast)]
pub struct PolicyId(ast::PolicyID);

impl PolicyId {
/// Construct a [`PolicyId`] from a source string
pub fn new(id: impl AsRef<str>) -> Self {
Self(ast::PolicyID::from_string(id.as_ref()))
}
}

impl FromStr for PolicyId {
type Err = ParseErrors;

Expand Down