starlark/environment.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//! Types representing Starlark modules ([`Module`] and [`FrozenModule`]) and global variables ([`Globals`]).
19//!
20//! Global functions and values are stored in [`Globals`], which are typically
21//! built using [`GlobalsBuilder`].
22//! User executions store their values in a [`Module`], which have to be converted to a
23//! [`FrozenModule`] using [`freeze`](Module::freeze) before they can be `load()`'d as a dependency.
24
25mod globals;
26mod methods;
27mod module_dump;
28mod modules;
29pub(crate) mod names;
30pub(crate) mod slots;
31
32pub use globals::*;
33pub use methods::*;
34pub use modules::*;
35use thiserror::Error;
36
37#[derive(Debug, Error)]
38enum EnvironmentError {
39 /// Cannot import private symbol, i.e. underscore prefixed
40 #[error("Cannot import private symbol `{0}`")]
41 CannotImportPrivateSymbol(String),
42 #[error("Module has no symbol `{0}`")]
43 ModuleHasNoSymbol(String),
44 #[error("Module has no symbol `{0}`, did you mean `{1}`?")]
45 ModuleHasNoSymbolDidYouMean(String, String),
46 #[error("Module symbol `{0}` is not exported")]
47 ModuleSymbolIsNotExported(String),
48}