|
17 | 17 |
|
18 | 18 | use std::collections::HashMap;
|
19 | 19 |
|
| 20 | +use allocative::Allocative; |
20 | 21 | use starlark_derive::starlark_module;
|
| 22 | +use starlark_derive::starlark_value; |
| 23 | +use starlark_derive::NoSerialize; |
| 24 | +use starlark_derive::ProvidesStaticType; |
21 | 25 | use starlark_map::small_map::SmallMap;
|
22 | 26 |
|
23 | 27 | use crate as starlark;
|
24 |
| -use crate::assert; |
| 28 | +use crate::assert::Assert; |
25 | 29 | use crate::docs::DocItem;
|
26 | 30 | use crate::docs::DocMember;
|
27 | 31 | use crate::environment::GlobalsBuilder;
|
28 | 32 | use crate::eval::Arguments;
|
29 | 33 | use crate::eval::Evaluator;
|
30 |
| -use crate::typing::Ty; |
31 | 34 | use crate::values::none::NoneType;
|
32 |
| -use crate::values::type_repr::StarlarkTypeRepr; |
| 35 | +use crate::values::starlark_value_as_type::StarlarkValueAsType; |
33 | 36 | use crate::values::Heap;
|
| 37 | +use crate::values::StarlarkValue; |
34 | 38 | use crate::values::StringValue;
|
35 | 39 | use crate::values::Value;
|
36 | 40 | use crate::values::ValueOfUnchecked;
|
37 | 41 |
|
| 42 | +#[derive( |
| 43 | + Debug, |
| 44 | + derive_more::Display, |
| 45 | + Allocative, |
| 46 | + NoSerialize, |
| 47 | + ProvidesStaticType |
| 48 | +)] |
| 49 | +#[display(fmt = "input")] |
38 | 50 | struct InputTypeRepr;
|
| 51 | +#[derive( |
| 52 | + Debug, |
| 53 | + derive_more::Display, |
| 54 | + Allocative, |
| 55 | + NoSerialize, |
| 56 | + ProvidesStaticType |
| 57 | +)] |
| 58 | +#[display(fmt = "output")] |
39 | 59 | struct OutputTypeRepr;
|
40 | 60 |
|
41 |
| -impl StarlarkTypeRepr for InputTypeRepr { |
42 |
| - fn starlark_type_repr() -> Ty { |
43 |
| - Ty::name_static("input") |
44 |
| - } |
45 |
| -} |
46 |
| -impl StarlarkTypeRepr for OutputTypeRepr { |
47 |
| - fn starlark_type_repr() -> Ty { |
48 |
| - Ty::name_static("output") |
49 |
| - } |
50 |
| -} |
| 61 | +#[starlark_value(type = "input")] |
| 62 | +impl<'v> StarlarkValue<'v> for InputTypeRepr {} |
| 63 | + |
| 64 | +#[starlark_value(type = "output")] |
| 65 | +impl<'v> StarlarkValue<'v> for OutputTypeRepr {} |
51 | 66 |
|
52 | 67 | #[starlark_module]
|
53 | 68 | #[allow(unused_variables)] // Since this is for a test
|
54 | 69 | fn globals(builder: &mut GlobalsBuilder) {
|
| 70 | + const Input: StarlarkValueAsType<InputTypeRepr> = StarlarkValueAsType::new(); |
| 71 | + const Output: StarlarkValueAsType<OutputTypeRepr> = StarlarkValueAsType::new(); |
| 72 | + |
55 | 73 | fn simple(
|
56 | 74 | arg_int: i32,
|
57 | 75 | arg_bool: bool,
|
@@ -97,18 +115,18 @@ fn globals(builder: &mut GlobalsBuilder) {
|
97 | 115 | #[test]
|
98 | 116 | fn test_rustdoc() {
|
99 | 117 | let got = GlobalsBuilder::new().with(globals).build();
|
100 |
| - let expected = assert::pass_module( |
101 |
| - r#" |
| 118 | + let mut a = Assert::new(); |
| 119 | + a.globals_add(globals); |
| 120 | + let expected = a.pass_module(r#" |
102 | 121 | # @starlark-rust: allow_string_literals_in_type_expr
|
103 | 122 |
|
104 | 123 | def args_kwargs(*args, **kwargs: typing.Any) -> None: pass
|
105 |
| -def custom_types(arg1: str, arg2: "input") -> "output": pass |
| 124 | +def custom_types(arg1: str, arg2: Input) -> Output: pass |
106 | 125 | def default_arg(arg1 = "_", arg2: typing.Any = None) -> list[str]: pass
|
107 | 126 | def pos_named(arg1: int, *, arg2: int) -> int: pass
|
108 | 127 | def simple(arg_int: int, arg_bool: bool, arg_vec: list[str], arg_dict: dict[str, (bool, int)]) -> None: pass
|
109 | 128 | def with_arguments(*args, **kwargs) -> int: pass
|
110 |
| -"#, |
111 |
| - ); |
| 129 | +"#); |
112 | 130 |
|
113 | 131 | fn unpack(x: DocItem) -> HashMap<String, DocItem> {
|
114 | 132 | match x {
|
|
0 commit comments