pub struct Role { /* private fields */ }Expand description
A role (participant) in the choreography
Roles represent the different participants in a distributed protocol.
They can be simple (e.g., Client, Server) or parameterized
(e.g., Worker[0], Worker[N] where the parameter can be a constant or variable).
§Examples
use quote::format_ident;
use telltale_runtime::{Role, RoleParam};
// Simple role
let client = Role::new(format_ident!("Client")).unwrap();
// Static parameterized role
let worker = Role::with_param(format_ident!("Worker"), RoleParam::Static(3)).unwrap();
// Dynamic role
let dynamic_worker = Role::with_param(format_ident!("Worker"), RoleParam::Runtime).unwrap();Implementations§
Source§impl Role
impl Role
Sourcepub fn new(name: Ident) -> Result<Role, RoleValidationError>
pub fn new(name: Ident) -> Result<Role, RoleValidationError>
Create a new simple role with the given name
Sourcepub fn with_param(
name: Ident,
param: RoleParam,
) -> Result<Role, RoleValidationError>
pub fn with_param( name: Ident, param: RoleParam, ) -> Result<Role, RoleValidationError>
Create a role with a parameter (e.g., Worker[3], Worker[N], Worker[*])
Sourcepub fn with_index(
name: Ident,
index: RoleIndex,
) -> Result<Role, RoleValidationError>
pub fn with_index( name: Ident, index: RoleIndex, ) -> Result<Role, RoleValidationError>
Create a role reference with an index (e.g., Worker[0], Worker[i], Worker[*])
Sourcepub fn with_param_and_index(
name: Ident,
param: RoleParam,
index: RoleIndex,
) -> Result<Role, RoleValidationError>
pub fn with_param_and_index( name: Ident, param: RoleParam, index: RoleIndex, ) -> Result<Role, RoleValidationError>
Create a role reference with both param and index
Sourcepub fn indexed(name: Ident, index: usize) -> Result<Role, RoleValidationError>
pub fn indexed(name: Ident, index: usize) -> Result<Role, RoleValidationError>
Create a new indexed role (e.g., Worker with index 0)
Sourcepub fn parameterized(
name: Ident,
param: TokenStream,
) -> Result<Role, RoleValidationError>
pub fn parameterized( name: Ident, param: TokenStream, ) -> Result<Role, RoleValidationError>
Create a parameterized role with symbolic parameter (e.g., Worker[N])
Sourcepub fn array(name: Ident, size: usize) -> Result<Role, RoleValidationError>
pub fn array(name: Ident, size: usize) -> Result<Role, RoleValidationError>
Create a role array with a concrete size (e.g., Worker[3])
Sourcepub fn array_size(&self) -> Option<&TokenStream>
pub fn array_size(&self) -> Option<&TokenStream>
Get the array size token if it exists.
Sourcepub fn is_indexed(&self) -> bool
pub fn is_indexed(&self) -> bool
Check if this role has an index
Sourcepub fn is_parameterized(&self) -> bool
pub fn is_parameterized(&self) -> bool
Check if this role is parameterized (has either index or param)
Sourcepub fn is_array(&self) -> bool
pub fn is_array(&self) -> bool
Check if this is a role array (declared with size like Worker[N])
Sourcepub fn is_dynamic(&self) -> bool
pub fn is_dynamic(&self) -> bool
Check if this role has dynamic parameterization (runtime count)
Sourcepub fn is_symbolic(&self) -> bool
pub fn is_symbolic(&self) -> bool
Check if this role has symbolic parameterization
Sourcepub fn is_wildcard(&self) -> bool
pub fn is_wildcard(&self) -> bool
Check if this role reference uses a wildcard index
Sourcepub fn get_static_count(&self) -> Option<u32>
pub fn get_static_count(&self) -> Option<u32>
Get the static count for static parameterized roles
Sourcepub fn get_symbolic_name(&self) -> Option<&str>
pub fn get_symbolic_name(&self) -> Option<&str>
Get the symbolic name for symbolic parameterized roles
Sourcepub fn matches_family(&self, family: &Role) -> bool
pub fn matches_family(&self, family: &Role) -> bool
Check if this role instance matches the given role family
For parameterized roles, this checks if the base name matches, ignoring specific indices. For example:
Worker[0]matchesWorker[N]Worker[i]matchesWorker[N]Worker[1]matchesWorker[3](ifWorker[3]is the array declaration)Clientonly matchesClient(exact match for non-parameterized)
Sourcepub fn validate(&self) -> Result<(), RoleValidationError>
pub fn validate(&self) -> Result<(), RoleValidationError>
Validate this role for security and safety constraints
Sourcepub fn safe_static(name: Ident, count: u32) -> Result<Role, RoleValidationError>
pub fn safe_static(name: Ident, count: u32) -> Result<Role, RoleValidationError>
Create a safe static role with overflow checking
Sourcepub fn safe_indexed(
name: Ident,
index: u32,
) -> Result<Role, RoleValidationError>
pub fn safe_indexed( name: Ident, index: u32, ) -> Result<Role, RoleValidationError>
Create a safe indexed role with overflow checking
Sourcepub fn safe_range(
name: Ident,
start: u32,
end: u32,
) -> Result<Role, RoleValidationError>
pub fn safe_range( name: Ident, start: u32, end: u32, ) -> Result<Role, RoleValidationError>
Create a safe range role with overflow checking
Trait Implementations§
impl Eq for Role
Auto Trait Implementations§
impl Freeze for Role
impl RefUnwindSafe for Role
impl !Send for Role
impl !Sync for Role
impl Unpin for Role
impl UnsafeUnpin for Role
impl UnwindSafe for Role
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CheckedAs for T
impl<T> CheckedAs for T
Source§fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
Source§impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
Source§fn checked_cast_from(src: Src) -> Option<Dst>
fn checked_cast_from(src: Src) -> Option<Dst>
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.