fn step(
        &mut self,
        max_depth: u8,  // how many type constructors deep can we go?
        min_width: u8,  // what's the min width of tuples in Offer/Choose? (if > 2, no Split/Call)
        max_width: u8,  // what's the max width of tuples in Offer/Choose? (if < 2, no Split/Call)
        loops: u8,      // how many loops are we under (controls Continue)?
        productive: u8, // how many loops up is the nearest non-Loop type?
    ) -> bool {
        use Session::*;

        // Abort if the max depth is zero, because we must produce something of length >= 1
        if max_depth == 0 {
            return false;
        }

        match self {
            Done => {
                if max_depth <= 1 {
                    if loops > 0 && productive < loops {
                        *self = Continue(productive);
                    } else {
                        return false;
                    }
                } else {
                    *self = Recv(Box::new(Done));
                }
            }
            Recv(s) => {
                if !s.step(max_depth - 1, min_width, max_width, loops, 0) {
                    *self = Send(Box::new(Done));
                }
            }
            Send(s) => {
                if !s.step(max_depth - 1, min_width, max_width, loops, 0) {
                    *self = Loop(Box::new(Done));
                }
            }
            Loop(s) => {
                if !s.step(
                    max_depth - 1,
                    min_width,
                    max_width,
                    loops + 1,
                    productive + 1,
                ) {
                    if min_width <= 3 && 3 <= max_width {
                        *self = Split(Box::new(Done), Box::new(Done), Box::new(Done));
                    } else if min_width <= 2 && 2 <= min_width {
                        *self = Call(Box::new(Done), Box::new(Done));
                    } else {
                        let mut initial = Vec::with_capacity(max_width.into());
                        for _ in 0..min_width {
                            initial.push(Done);
                        }
                        *self = Choose(initial);
                    }
                }
            }
            Split(s, p, q) => {
                if !s.step(max_depth - 1, min_width, max_width, loops, 0)
                    && !p.step(max_depth - 1, min_width, max_width, loops, 0)
                    && !q.step(max_depth - 1, min_width, max_width, loops, 0)
                {
                    *self = Call(Box::new(Done), Box::new(Done));
                }
            }
            Call(s, p) => {
                if !s.step(max_depth - 1, min_width, max_width, loops, 0)
                    && !p.step(max_depth - 1, min_width, max_width, loops, 0)
                {
                    let mut initial = Vec::with_capacity(max_width.into());
                    for _ in 0..min_width {
                        initial.push(Done);
                    }
                    *self = Choose(initial);
                }
            }
            Choose(cs) => {
                for c in cs.iter_mut() {
                    if c.step(max_depth - 1, min_width, max_width, loops, 0) {
                        return true;
                    } else {
                        *c = Done;
                    }
                }
                if cs.len() < max_width.into() {
                    cs.push(Done);
                } else {
                    let mut initial = Vec::with_capacity(max_width.into());
                    for _ in 0..min_width {
                        initial.push(Done);
                    }
                    *self = Offer(initial);
                }
            }
            Offer(cs) => {
                for c in cs.iter_mut() {
                    if c.step(max_depth - 1, min_width, max_width, loops, 0) {
                        return true;
                    } else {
                        *c = Done;
                    }
                }
                if cs.len() < max_width.into() {
                    cs.push(Done);
                } else if loops > 0 && productive < loops {
                    *self = Continue(productive);
                } else {
                    return false;
                }
            }
            Continue(n) => {
                if *n + 1 < loops {
                    *n += 1;
                } else {
                    return false;
                }
            }
        };
        true
    }
/// Step this session to the next one in a sequence of enumerated sessions, or return `false` if
/// this is the last session in such a sequence. This is called within the `Iterator`
/// implementation for `SessionIter`.
Step this session to the next one in a sequence of enumerated sessions, or return `false` if
this is the last session in such a sequence. This is called within the `Iterator`
implementation for `SessionIter`.
Step this session to the next one in a sequence of enumerated sessions or return ` false ` if this is the last session in such a sequence . This is called within the ` Iterator ` implementation for ` SessionIter ` .
fn step(
        &mut self,
        max_depth: u8,  // how many type constructors deep can we go?
        min_width: u8,  // what's the min width of tuples in Offer/Choose? (if > 2, no Split/Call)
        max_width: u8,  // what's the max width of tuples in Offer/Choose? (if < 2, no Split/Call)
        loops: u8,      // how many loops are we under (controls Continue)?
        productive: u8, // how many loops up is the nearest non-Loop type?
    ) -> bool {
        use Session::*;
        // Abort if the max depth is zero, because we must produce something of length >= 1
        if max_depth == 0 {
            return false;
        }
        match self {
            Done => {
                if max_depth <= 1 {
                    if loops > 0 && productive < loops {
                        *self = Continue(productive);
                    } else {
                        return false;
                    }
                } else {
                    *self = Recv(Box::new(Done));
                }
            }
            Recv(s) => {
                if !s.step(max_depth - 1, min_width, max_width, loops, 0) {
                    *self = Send(Box::new(Done));
                }
            }
            Send(s) => {
                if !s.step(max_depth - 1, min_width, max_width, loops, 0) {
                    *self = Loop(Box::new(Done));
                }
            }
            Loop(s) => {
                if !s.step(
                    max_depth - 1,
                    min_width,
                    max_width,
                    loops + 1,
                    productive + 1,
                ) {
                    if min_width <= 3 && 3 <= max_width {
                        *self = Split(Box::new(Done), Box::new(Done), Box::new(Done));
                    } else if min_width <= 2 && 2 <= min_width {
                        *self = Call(Box::new(Done), Box::new(Done));
                    } else {
                        let mut initial = Vec::with_capacity(max_width.into());
                        for _ in 0..min_width {
                            initial.push(Done);
                        }
                        *self = Choose(initial);
                    }
                }
            }
            Split(s, p, q) => {
                if !s.step(max_depth - 1, min_width, max_width, loops, 0)
                    && !p.step(max_depth - 1, min_width, max_width, loops, 0)
                    && !q.step(max_depth - 1, min_width, max_width, loops, 0)
                {
                    *self = Call(Box::new(Done), Box::new(Done));
                }
            }
            Call(s, p) => {
                if !s.step(max_depth - 1, min_width, max_width, loops, 0)
                    && !p.step(max_depth - 1, min_width, max_width, loops, 0)
                {
                    let mut initial = Vec::with_capacity(max_width.into());
                    for _ in 0..min_width {
                        initial.push(Done);
                    }
                    *self = Choose(initial);
                }
            }
            Choose(cs) => {
                for c in cs.iter_mut() {
                    if c.step(max_depth - 1, min_width, max_width, loops, 0) {
                        return true;
                    } else {
                        *c = Done;
                    }
                }
                if cs.len() < max_width.into() {
                    cs.push(Done);
                } else {
                    let mut initial = Vec::with_capacity(max_width.into());
                    for _ in 0..min_width {
                        initial.push(Done);
                    }
                    *self = Offer(initial);
                }
            }
            Offer(cs) => {
                for c in cs.iter_mut() {
                    if c.step(max_depth - 1, min_width, max_width, loops, 0) {
                        return true;
                    } else {
                        *c = Done;
                    }
                }
                if cs.len() < max_width.into() {
                    cs.push(Done);
                } else if loops > 0 && productive < loops {
                    *self = Continue(productive);
                } else {
                    return false;
                }
            }
            Continue(n) => {
                if *n + 1 < loops {
                    *n += 1;
                } else {
                    return false;
                }
            }
        };
        true
    }
fn step ( & mut self , max_depth : u8 , // how many type constructors deep can we go? min_width : u8 , // what's the min width of tuples in Offer/Choose? (if > 2, no Split/Call) max_width : u8 , // what's the max width of tuples in Offer/Choose? (if < 2, no Split/Call) loops : u8 , // how many loops are we under (controls Continue)? productive : u8 , // how many loops up is the nearest non-Loop type? ) -> bool { use Session :: * ; // Abort if the max depth is zero, because we must produce something of length >= 1 if max_depth == 0 { return false ; } match self { Done => { if max_depth <= 1 { if loops > 0 && productive < loops { * self = Continue ( productive ) ; } else { return false ; } } else { * self = Recv ( Box :: new ( Done ) ) ; } } Recv ( s ) => { if ! s . step ( max_depth - 1 , min_width , max_width , loops , 0 ) { * self = Send ( Box :: new ( Done ) ) ; } } Send ( s ) => { if ! s . step ( max_depth - 1 , min_width , max_width , loops , 0 ) { * self = Loop ( Box :: new ( Done ) ) ; } } Loop ( s ) => { if ! s . step ( max_depth - 1 , min_width , max_width , loops + 1 , productive + 1 , ) { if min_width <= 3 && 3 <= max_width { * self = Split ( Box :: new ( Done ) , Box :: new ( Done ) , Box :: new ( Done ) ) ; } else if min_width <= 2 && 2 <= min_width { * self = Call ( Box :: new ( Done ) , Box :: new ( Done ) ) ; } else { let mut initial = Vec :: with_capacity ( max_width . into ( ) ) ; for _ in 0 .. min_width { initial . push ( Done ) ; } * self = Choose ( initial ) ; } } } Split ( s , p , q ) => { if ! s . step ( max_depth - 1 , min_width , max_width , loops , 0 ) && ! p . step ( max_depth - 1 , min_width , max_width , loops , 0 ) && ! q . step ( max_depth - 1 , min_width , max_width , loops , 0 ) { * self = Call ( Box :: new ( Done ) , Box :: new ( Done ) ) ; } } Call ( s , p ) => { if ! s . step ( max_depth - 1 , min_width , max_width , loops , 0 ) && ! p . step ( max_depth - 1 , min_width , max_width , loops , 0 ) { let mut initial = Vec :: with_capacity ( max_width . into ( ) ) ; for _ in 0 .. min_width { initial . push ( Done ) ; } * self = Choose ( initial ) ; } } Choose ( cs ) => { for c in cs . iter_mut ( ) { if c . step ( max_depth - 1 , min_width , max_width , loops , 0 ) { return true ; } else { * c = Done ; } } if cs . len ( ) < max_width . into ( ) { cs . push ( Done ) ; } else { let mut initial = Vec :: with_capacity ( max_width . into ( ) ) ; for _ in 0 .. min_width { initial . push ( Done ) ; } * self = Offer ( initial ) ; } } Offer ( cs ) => { for c in cs . iter_mut ( ) { if c . step ( max_depth - 1 , min_width , max_width , loops , 0 ) { return true ; } else { * c = Done ; } } if cs . len ( ) < max_width . into ( ) { cs . push ( Done ) ; } else if loops > 0 && productive < loops { * self = Continue ( productive ) ; } else { return false ; } } Continue ( n ) => { if * n + 1 < loops { * n += 1 ; } else { return false ; } } } ; true }
Step this session to the next one in a sequence of enumerated sessions, or return `false` if
this is the last session in such a sequence.
Step this session to the next one in a sequence of enumerated sessions or return ` false ` if this is the last session in such a sequence .
&mut self
max_depth
u8
min_width
u8
max_width
u8
loops
u8
productive
u8