Skip to main content

objects/object/
action_id.rs

1// SPDX-License-Identifier: Apache-2.0
2//! Action identifier.
3
4use serde::{Deserialize, Serialize};
5
6use super::ContentHash;
7
8/// Unique identifier for an action (derived from content).
9#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
10pub struct ActionId(ContentHash);
11
12impl ActionId {
13    /// Create from a content hash.
14    pub fn from_hash(hash: ContentHash) -> Self {
15        Self(hash)
16    }
17
18    /// Get the underlying hash.
19    pub fn as_hash(&self) -> &ContentHash {
20        &self.0
21    }
22}
23
24impl std::fmt::Display for ActionId {
25    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
26        write!(f, "{}", self.0.short())
27    }
28}