Rip out legacy reactivity from the typechecker and HackC
[hiphop-php.git] / hphp / hack / src / oxidized_by_ref / manual / prop_flags.rs
blob7b60dc62a963bf950615591c2c7be5cdf4033052
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::TryInto;
8 use bitflags::bitflags;
10 // NB: Keep the values of these flags in sync with shallow_decl_defs.ml.
12 bitflags! {
13     pub struct PropFlags: u8 {
14         const ABSTRACT    = 1 << 0;
15         const CONST       = 1 << 1;
16         const LATEINIT    = 1 << 2;
17         const LSB         = 1 << 3;
18         const NEEDS_INIT  = 1 << 4;
19         const PHP_STD_LIB = 1 << 5;
20         const READONLY    = 1 << 6;
21     }
24 impl ocamlrep::ToOcamlRep for PropFlags {
25     fn to_ocamlrep<'a, A: ocamlrep::Allocator>(&self, _alloc: &'a A) -> ocamlrep::OpaqueValue<'a> {
26         ocamlrep::OpaqueValue::int(self.bits() as isize)
27     }
30 impl ocamlrep::FromOcamlRep for PropFlags {
31     fn from_ocamlrep(value: ocamlrep::Value<'_>) -> Result<Self, ocamlrep::FromError> {
32         let int_value = ocamlrep::from::expect_int(value)?;
33         Ok(Self::from_bits_truncate(int_value.try_into()?))
34     }
37 impl<'a> ocamlrep::FromOcamlRepIn<'a> for PropFlags {
38     fn from_ocamlrep_in(
39         value: ocamlrep::Value<'_>,
40         _alloc: &'a bumpalo::Bump,
41     ) -> Result<Self, ocamlrep::FromError> {
42         use ocamlrep::FromOcamlRep;
43         Self::from_ocamlrep(value)
44     }
47 impl no_pos_hash::NoPosHash for PropFlags {
48     fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
49         std::hash::Hash::hash(self, state);
50     }
53 impl serde::Serialize for PropFlags {
54     fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
55         serializer.serialize_u8(self.bits())
56     }
59 impl<'de> serde::Deserialize<'de> for PropFlags {
60     fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
61         struct Visitor;
62         impl<'de> serde::de::Visitor<'de> for Visitor {
63             type Value = PropFlags;
65             fn expecting(&self, formatter: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
66                 write!(formatter, "a u8 for PropFlags")
67             }
68             fn visit_u8<E: serde::de::Error>(self, value: u8) -> Result<Self::Value, E> {
69                 Ok(Self::Value::from_bits_truncate(value))
70             }
71         }
72         deserializer.deserialize_u8(Visitor)
73     }