FILENAME 3/4 - delete the old get_fun_path etc.
[hiphop-php.git] / hphp / hack / src / oxidized / manual / naming_types_impl.rs
blob60d99652823c20377ebcdd4a175fc8a1f141975c
1 // Copyright (c) Facebook, Inc. and its affiliates.
2 //
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 {
12     type Error = String;
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) {
25             Ok(NameKind::FunKind)
26         } else if kind == (NameType::Const as i64) {
27             Ok(NameKind::ConstKind)
28         } else {
29             Err("oops".to_owned())
30         }
31     }