starlark/stdlib/
internal.rs

1/*
2 * Copyright 2018 The Starlark in Rust Authors.
3 * Copyright (c) Facebook, Inc. and its affiliates.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 *     https://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18//! Expose starlark-rust internals in starlark.
19//!
20//! None of this code is meant to be used in production. Can be changed any time.
21
22use starlark_derive::starlark_module;
23
24use crate as starlark;
25use crate::environment::GlobalsBuilder;
26use crate::typing::Ty;
27use crate::values::Value;
28
29#[starlark_module]
30fn starlark_rust_internal_members(globals: &mut GlobalsBuilder) {
31    fn ty_of_value_debug(value: Value) -> anyhow::Result<String> {
32        Ok(format!("{:?}", Ty::of_value(value)))
33    }
34}
35
36pub(crate) fn register_internal(globals: &mut GlobalsBuilder) {
37    globals.namespace_no_docs("starlark_rust_internal", |s| {
38        starlark_rust_internal_members(s)
39    });
40}
41
42#[cfg(test)]
43mod tests {
44    use crate::assert;
45
46    #[test]
47    fn test_ty_of_value_debug() {
48        assert::pass("print(starlark_rust_internal.ty_of_value_debug(1))");
49    }
50}