fn sum_circuit<S>()
    where
        S: Scheduler + 'static,
    {
        let actual_output: Rc<RefCell<Vec<isize>>> = Rc::new(RefCell::new(Vec::with_capacity(100)));
        let actual_output_clone = actual_output.clone();
        let root = Root::build_with_scheduler::<_, S>(|circuit| {
            TraceMonitor::new_panic_on_error().attach(circuit, "monitor");
            let mut n: isize = 0;
            let source = circuit.add_source(Generator::new(move || {
                let result = n;
                n += 1;
                result
            }));
            let integrator = source.integrate();
            integrator.inspect(|n| println!("{}", n));
            integrator.inspect(move |n| actual_output_clone.borrow_mut().push(*n));
        })
        .unwrap();

        for _ in 0..100 {
            root.step().unwrap();
        }

        let mut sum = 0;
        let mut expected_output: Vec<isize> = Vec::with_capacity(100);
        for i in 0..100 {
            sum += i;
            expected_output.push(sum);
        }
        assert_eq!(&expected_output, actual_output.borrow().deref());
    }
// Compute the sum of numbers from 0 to 99.
Compute the sum of numbers from 0 to 99.
Compute the sum of numbers from 0 to 99 .
fn sum_circuit<S>()
    where
        S: Scheduler + 'static,
    {
        let actual_output: Rc<RefCell<Vec<isize>>> = Rc::new(RefCell::new(Vec::with_capacity(100)));
        let actual_output_clone = actual_output.clone();
        let root = Root::build_with_scheduler::<_, S>(|circuit| {
            TraceMonitor::new_panic_on_error().attach(circuit, "monitor");
            let mut n: isize = 0;
            let source = circuit.add_source(Generator::new(move || {
                let result = n;
                n += 1;
                result
            }));
            let integrator = source.integrate();
            integrator.inspect(|n| println!("{}", n));
            integrator.inspect(move |n| actual_output_clone.borrow_mut().push(*n));
        })
        .unwrap();
        for _ in 0..100 {
            root.step().unwrap();
        }
        let mut sum = 0;
        let mut expected_output: Vec<isize> = Vec::with_capacity(100);
        for i in 0..100 {
            sum += i;
            expected_output.push(sum);
        }
        assert_eq!(&expected_output, actual_output.borrow().deref());
    }
fn sum_circuit < S > ( ) where S : Scheduler + ' static , { let actual_output : Rc < RefCell < Vec < isize > > > = Rc :: new ( RefCell :: new ( Vec :: with_capacity ( 100 ) ) ) ; let actual_output_clone = actual_output . clone ( ) ; let root = Root :: build_with_scheduler :: < _ , S > ( | circuit | { TraceMonitor :: new_panic_on_error ( ) . attach ( circuit , " " ) ; let mut n : isize = 0 ; let source = circuit . add_source ( Generator :: new ( move | | { let result = n ; n += 1 ; result } ) ) ; let integrator = source . integrate ( ) ; integrator . inspect ( | n | println ! ( " " n ) ) ; integrator . inspect ( move | n | actual_output_clone . borrow_mut ( ) . push ( * n ) ) ; } ) . unwrap ( ) ; for _ in 0 .. 100 { root . step ( ) . unwrap ( ) ; } let mut sum = 0 ; let mut expected_output : Vec < isize > = Vec :: with_capacity ( 100 ) ; for i in 0 .. 100 { sum += i ; expected_output . push ( sum ) ; } assert_eq ! ( expected_output actual_output borrow ( ) deref ( ) ) ; }
Compute the sum of numbers from 0 to 99.
Compute the sum of numbers from 0 to 99 .