1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
use crate::{dependency::Requirement, store::id::PackageId};
use std::{collections::HashSet, fmt::Debug, hint::unreachable_unchecked};

#[derive(Debug, PartialEq, Eq, Clone)]
pub enum Step<'a> {
    Resolved(PackageId),
    Choice(HashSet<PackageId>),
    Unresolved(&'a Requirement),
}

impl<'a> Step<'a> {
    pub unsafe fn as_choice_unchecked(&self) -> &HashSet<PackageId> {
        match &self {
            Self::Choice(set) => set,
            _ => unreachable_unchecked(),
        }
    }

    pub unsafe fn as_resolved_unchecked(&self) -> PackageId {
        match self {
            Self::Resolved(id) => *id,
            _ => unreachable_unchecked(),
        }
    }

    pub unsafe fn as_unresolved_unchecked(&self) -> &'a Requirement {
        match &self {
            Self::Unresolved(req) => req,
            _ => unreachable_unchecked(),
        }
    }

    pub fn as_resolved(&self) -> Option<PackageId> {
        match self {
            Step::Resolved(id) => Some(*id),
            _ => None,
        }
    }

    pub fn is_resolved(&self) -> bool {
        if let Step::Resolved(_) = self {
            true
        } else {
            false
        }
    }

    pub fn as_unresolved(&self) -> Option<&Requirement> {
        match self {
            Step::Unresolved(req) => Some(req),
            _ => None,
        }
    }

    pub fn is_unresolved(&self) -> bool {
        if let Step::Unresolved(_) = self {
            true
        } else {
            false
        }
    }
}