fn insert_before<W>(
        &mut self,
        end: T,
        duration: W,
        min_start: Option<T>,
        data: Rc<D>,
    ) -> Option<T>
    where
        T: Sub<W, Output = T>,
        W: Copy + Debug,
    {
        match self {
            Node::Leaf { .. } => None,
            Node::Intermediate { left, right, free } => {
                // If the end is inside the right child, try that first
                if free.end < end {
                    return_on_some!(right.insert_before(end, duration, min_start, Rc::clone(&data)))
                }
                // Second, try to insert it in the free range of the current node
                let end = min(end, free.end);
                if free.start <= end - duration
                    && min_start.map_or(true, |min_start| min_start <= end - duration)
                {
                    unchecked_insert(end - duration, end, Rc::clone(&data), right, free);
                    return Some(end - duration);
                }

                // If min_start is contained in free, don't bother checking the left child
                if min_start.map_or(true, |min_start| free.start <= min_start) {
                    return None;
                }
                // Last, try to insert it in the left child
                left.insert_before(end, duration, min_start, data)
            }
        }
    }
/// Tries to insert a node with the given `data` and `duration` as a descendant of this node.
/// It must be scheduled as close before `end` as possible, but it cannot be scheduled sooner
/// than `min_start`, when given.
///
/// Returns the start of the scheduling if it succeeded, otherwise None
Tries to insert a node with the given `data` and `duration` as a descendant of this node.
It must be scheduled as close before `end` as possible, but it cannot be scheduled sooner
than `min_start`, when given.

Returns the start of the scheduling if it succeeded, otherwise None
Tries to insert a node with the given ` data ` and ` duration ` as a descendant of this node . It must be scheduled as close before ` end ` as possible but it cannot be scheduled sooner than ` min_start ` when given . Returns the start of the scheduling if it succeeded otherwise None
fn insert_before<W>(
        &mut self,
        end: T,
        duration: W,
        min_start: Option<T>,
        data: Rc<D>,
    ) -> Option<T>
    where
        T: Sub<W, Output = T>,
        W: Copy + Debug,
    {
        match self {
            Node::Leaf { .. } => None,
            Node::Intermediate { left, right, free } => {
                // If the end is inside the right child, try that first
                if free.end < end {
                    return_on_some!(right.insert_before(end, duration, min_start, Rc::clone(&data)))
                }
                // Second, try to insert it in the free range of the current node
                let end = min(end, free.end);
                if free.start <= end - duration
                    && min_start.map_or(true, |min_start| min_start <= end - duration)
                {
                    unchecked_insert(end - duration, end, Rc::clone(&data), right, free);
                    return Some(end - duration);
                }
                // If min_start is contained in free, don't bother checking the left child
                if min_start.map_or(true, |min_start| free.start <= min_start) {
                    return None;
                }
                // Last, try to insert it in the left child
                left.insert_before(end, duration, min_start, data)
            }
        }
    }
fn insert_before < W > ( & mut self , end : T , duration : W , min_start : Option < T > , data : Rc < D > , ) -> Option < T > where T : Sub < W , Output = T > , W : Copy + Debug , { match self { Node :: Leaf { .. } => None , Node :: Intermediate { left , right , free } => { // If the end is inside the right child, try that first if free . end < end { return_on_some ! ( right insert_before ( end duration min_start Rc clone ( data ) ) ) } // Second, try to insert it in the free range of the current node let end = min ( end , free . end ) ; if free . start <= end - duration && min_start . map_or ( true , | min_start | min_start <= end - duration ) { unchecked_insert ( end - duration , end , Rc :: clone ( & data ) , right , free ) ; return Some ( end - duration ) ; } // If min_start is contained in free, don't bother checking the left child if min_start . map_or ( true , | min_start | free . start <= min_start ) { return None ; } // Last, try to insert it in the left child left . insert_before ( end , duration , min_start , data ) } } }
Tries to insert a node with the given `data` and `duration` as a descendant of this node.
Tries to insert a node with the given ` data ` and ` duration ` as a descendant of this node .
&mut self
end
T
duration
W
min_start
Option<T>
data
Rc<D>
&mut self
end
T
duration
W
min_start
Option<T>
data
Rc<D>