use crate::integer::Time; #[derive(Clone,Debug)] pub struct TimedInstruction{ pub time:Time, pub instruction:I, } impl TimedInstruction{ #[inline] pub fn set_time(self,new_time:Time)->TimedInstruction{ TimedInstruction{ time:new_time, instruction:self.instruction, } } } /// Ensure all emitted instructions are processed before consuming external instructions pub trait InstructionEmitter{ type TimeInner; fn next_instruction(&self,time_limit:Time)->Option>; } /// Apply an atomic state update pub trait InstructionConsumer{ type TimeInner; fn process_instruction(&mut self,instruction:TimedInstruction); } /// If the object produces its own instructions, allow exhaustively feeding them back in pub trait InstructionFeedback:InstructionEmitter+InstructionConsumer where Time:Copy, { #[inline] fn process_exhaustive(&mut self,time_limit:Time){ while let Some(instruction)=self.next_instruction(time_limit){ self.process_instruction(instruction); } } } impl InstructionFeedback for X where Time:Copy, X:InstructionEmitter+InstructionConsumer, {} //PROPER PRIVATE FIELDS!!! pub struct InstructionCollector{ time:Time, instruction:Option, } impl InstructionCollector where Time:Copy+PartialOrd, { #[inline] pub const fn new(time:Time)->Self{ Self{ time, instruction:None } } #[inline] pub const fn time(&self)->Time{ self.time } pub fn collect(&mut self,instruction:Option>){ if let Some(ins)=instruction{ if ins.timeOption>{ //STEAL INSTRUCTION AND DESTROY INSTRUCTIONCOLLECTOR self.instruction.map(|instruction|TimedInstruction{ time:self.time, instruction }) } }