1 // Copyright (c) Facebook, Inc. and its affiliates.
3 // This source code is licensed under the MIT license found in the
4 // LICENSE file in the "hack" directory of this source tree.
8 #[derive(Debug, Clone, Copy, PartialEq, Eq, std::cmp::Ord, std::cmp::PartialOrd)]
15 pub fn id(&self) -> &Id {
17 Label::Regular(id) => id,
18 Label::DefaultArg(id) => id,
22 pub fn map<F: FnOnce(&Id) -> Id>(&self, f: F) -> Label {
24 Label::Regular(id) => Label::Regular(f(id)),
25 Label::DefaultArg(id) => Label::DefaultArg(f(id)),
36 impl std::fmt::Display for Error {
37 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
38 let mut msg = "Label should be rewritten before this point".to_owned();
39 msg.push_str(match self {
41 Error::OptionMap => " (option_map)",
42 Error::Map => " (map)",
48 #[derive(Default, Debug)]
54 pub fn next_regular(&mut self) -> Label {
55 Label::Regular(self.get_next())
57 pub fn next_default_arg(&mut self) -> Label {
58 Label::DefaultArg(self.get_next())
61 fn get_next(&mut self) -> Id {
62 let curr_id = self.next_id;
63 self.next_id = curr_id + 1;
67 pub fn reset(&mut self) {