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.
6 use std::convert::TryFrom;
8 use crate::file_info::NameType;
9 use crate::gen::naming_types::{KindOfType, NameKind};
11 impl TryFrom<i64> for NameKind {
14 fn try_from(kind: i64) -> Result<Self, String> {
15 // Must be kept in sync with naming_types.ml and namekind_to_i64
16 // name_type.ml is where the numerical values are defined, and NameType in rust is
17 // generated from it, and all other places including namkind_to_i64 just use it.
18 if kind == (NameType::Class as i64) {
19 Ok(NameKind::TypeKind(KindOfType::TClass))
20 } else if kind == (NameType::Typedef as i64) {
21 Ok(NameKind::TypeKind(KindOfType::TTypedef))
22 } else if kind == (NameType::RecordDef as i64) {
23 Ok(NameKind::TypeKind(KindOfType::TRecordDef))
24 } else if kind == (NameType::Fun as i64) {
26 } else if kind == (NameType::Const as i64) {
27 Ok(NameKind::ConstKind)
29 Err("oops".to_owned())