gwr_components/
types.rs

1// Copyright (c) 2023 Graphcore Ltd. All rights reserved.
2
3//! Shared types.
4//!
5//! This file defines a number of common types used to connect blocks.
6
7use std::mem::size_of;
8
9use gwr_engine::traits::{SimObject, TotalBytes};
10use gwr_engine::types::SimError;
11use gwr_track::id::Unique;
12
13/// The `DataGenerator` is what a [source](crate::source) uses
14/// to generate data values to send.
15pub type DataGenerator<T> = Box<dyn Iterator<Item = T> + 'static>;
16
17/// The return value from a call to [get()](crate::types::GetResult)
18///
19/// It can either return a value or a [SimError].
20pub type GetResult<T> = Result<T, SimError>;
21
22#[derive(Clone, Debug)]
23pub struct Credit(pub usize);
24
25impl TotalBytes for Credit {
26    fn total_bytes(&self) -> usize {
27        size_of::<usize>()
28    }
29}
30
31impl Unique for Credit {
32    fn id(&self) -> gwr_track::Id {
33        gwr_track::Id(0)
34    }
35}
36
37impl std::fmt::Display for Credit {
38    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
39        write!(f, "credit {}", self.0)
40    }
41}
42
43impl SimObject for Credit {}