Debian Codegraph @

src/tl/definition.rs

raw symbols SCIP
1 // Copyright 2020 - developers of the `grammers` project.
2 // Copyright 2022 - developers of the `tdlib-rs` project.
3 // Copyright 2024 - developers of the `tgt` and `tdlib-rs` projects.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::collectionsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/::HashMaprust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/HashMap#;
11 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/;
12 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/::FromStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/traits/FromStr#;
13
14 use craterust-analyzer cargo tdlib-rs-parser 1.4.0 crate/::errorsrust-analyzer cargo tdlib-rs-parser 1.4.0 errors/::{ParamParseErrorrust-analyzer cargo tdlib-rs-parser 1.4.0 errors/ParamParseError#, ParseErrorrust-analyzer cargo tdlib-rs-parser 1.4.0 errors/ParseError#};
15 use craterust-analyzer cargo tdlib-rs-parser 1.4.0 crate/::tlrust-analyzer cargo tdlib-rs-parser 1.4.0 tl/::{Categoryrust-analyzer cargo tdlib-rs-parser 1.4.0 tl/category/Category#, Parameterrust-analyzer cargo tdlib-rs-parser 1.4.0 tl/parameter/Parameter#, Typerust-analyzer cargo tdlib-rs-parser 1.4.0 tl/ty/Type#};
16
17 /// A [Type Language] definition.
18 ///
19 /// [Type Language]: https://core.telegram.org/mtproto/TL
20 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:)]
21 pub struct Definitionrust-analyzer cargo tdlib-rs-parser 1.4.0 tl/definition/Definition# {
22 /// The name of this definition. Also known as "predicate" or "method".
23 pub namerust-analyzer cargo tdlib-rs-parser 1.4.0 tl/definition/Definition#name.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#,
24
25 /// The description of this definition.
26 pub descriptionrust-analyzer cargo tdlib-rs-parser 1.4.0 tl/definition/Definition#description.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#,
27
28 /// A possibly-empty list of parameters this definition has.
29 pub paramsrust-analyzer cargo tdlib-rs-parser 1.4.0 tl/definition/Definition#params.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Parameterrust-analyzer cargo tdlib-rs-parser 1.4.0 tl/parameter/Parameter#>,
30
31 /// The type to which this definition belongs to.
32 pub tyrust-analyzer cargo tdlib-rs-parser 1.4.0 tl/definition/Definition#ty.: Typerust-analyzer cargo tdlib-rs-parser 1.4.0 tl/ty/Type#,
33
34 /// The category to which this definition belongs to.
35 pub categoryrust-analyzer cargo tdlib-rs-parser 1.4.0 tl/definition/Definition#category.: Categoryrust-analyzer cargo tdlib-rs-parser 1.4.0 tl/category/Category#,
36 }
37
38 impl fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display# for Definitionrust-analyzer cargo tdlib-rs-parser 1.4.0 tl/definition/Definition# {
39 fn fmtrust-analyzer cargo tdlib-rs-parser 1.4.0 tl/definition/impl#[Definition][Display]fmt().(&self, f: &mut fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#<'_>) -> fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# {
40 writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "{}", self.namerust-analyzer cargo tdlib-rs-parser 1.4.0 tl/definition/Definition#name.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
41
42 for param in self.paramsrust-analyzer cargo tdlib-rs-parser 1.4.0 tl/definition/Definition#params..iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().() {
43 writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, " {param}")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
44 }
45 writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, " = {}", self.tyrust-analyzer cargo tdlib-rs-parser 1.4.0 tl/definition/Definition#ty.)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
46 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
47 }
48 }
49
50 impl FromStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/traits/FromStr# for Definitionrust-analyzer cargo tdlib-rs-parser 1.4.0 tl/definition/Definition# {
51 type Errrust-analyzer cargo tdlib-rs-parser 1.4.0 tl/definition/impl#[Definition][FromStr]Err# = ParseErrorrust-analyzer cargo tdlib-rs-parser 1.4.0 errors/ParseError#;
52
53 /// Parses a [Type Language] definition.
54 ///
55 /// # Examples
56 ///
57 /// ```
58 /// use tdlib_rs_parser::tl::Definition;
59 ///
60 /// assert!("sendMessage chat_id:int message:string = Message".parse::<Definition>().is_ok());
61 /// ```
62 ///
63 /// [Type Language]: https://core.telegram.org/mtproto/TL
64 fn from_strrust-analyzer cargo tdlib-rs-parser 1.4.0 tl/definition/impl#[Definition][FromStr]from_str().(definition: &str) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo tdlib-rs-parser 1.4.0 tl/definition/impl#[Definition][FromStr], Selfrust-analyzer cargo tdlib-rs-parser 1.4.0 tl/definition/impl#[Definition][FromStr]::Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/traits/FromStr#Err#> {
65 if definition.trimrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]trim().().is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]is_empty().() {
66 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(ParseErrorrust-analyzer cargo tdlib-rs-parser 1.4.0 errors/ParseError#::Emptyrust-analyzer cargo tdlib-rs-parser 1.4.0 errors/ParseError#Empty#);
67 }
68
69 let (definition, mut docs) = {
70 let mut docs = HashMaprust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/HashMap#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V>`]new().();
71 let mut comments_end = 0;
72
73 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(start) = definition.rfindrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]rfind().("//")
74 && let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(end) = definition[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().start..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()..findrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]find().('\n')
75 {
76 comments_end = start rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().end;
77 }
78
79 let mut offset = 0;
80 while let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(start) = definition[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().offset..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()..findrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]find().('@') {
81 let start = start rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().offset;
82 let end = if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(end) = definition[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().start rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().1..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()..findrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]find().('@') {
83 start rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().1 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().end
84 } else {
85 comments_end
86 };
87
88 let comment = definition[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().start rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().1..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#end]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()..replacerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str]replace().("//-", "");
89 let comment = comment.replacerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str]replace().("//", "").trimrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]trim().().to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().();
90 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((name, content)) = comment.split_oncerust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]split_once().(' ') {
91 docs.insertrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]insert().(name.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), content.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().());
92 } else {
93 docs.insertrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]insert().(comment, Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]new().());
94 }
95
96 offset = end;
97 }
98
99 (&definition[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().comments_end..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()., docs)
100 };
101
102 // Parse `(left = ty)`
103 let (left, ty) = {
104 let mut it = definition.splitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]split().('=');
105 let ls = it.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/iter/impl#[`Split<'a, P>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(); // split() always return at least one
106 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(t) = it.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/iter/impl#[`Split<'a, P>`][Iterator]next().() {
107 (ls.trimrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]trim().(), t.trimrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]trim().())
108 } else {
109 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(ParseErrorrust-analyzer cargo tdlib-rs-parser 1.4.0 errors/ParseError#::MissingTyperust-analyzer cargo tdlib-rs-parser 1.4.0 errors/ParseError#MissingType#);
110 }
111 };
112
113 let ty = Typerust-analyzer cargo tdlib-rs-parser 1.4.0 tl/ty/Type#::from_strrust-analyzer cargo tdlib-rs-parser 1.4.0 tl/ty/impl#[Type][FromStr]from_str().(ty).map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|_| ParseErrorrust-analyzer cargo tdlib-rs-parser 1.4.0 errors/ParseError#::MissingTyperust-analyzer cargo tdlib-rs-parser 1.4.0 errors/ParseError#MissingType#)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
114
115 // Parse `name middle`
116 let (name, middle) = {
117 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(pos) = left.findrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]find().(' ') {
118 (left[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeTo#pos]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()..trimrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]trim().(), left[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().pos..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()..trimrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]trim().())
119 } else {
120 (left.trimrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]trim().(), "")
121 }
122 };
123 if name.is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]is_empty().() {
124 return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(ParseErrorrust-analyzer cargo tdlib-rs-parser 1.4.0 errors/ParseError#::MissingNamerust-analyzer cargo tdlib-rs-parser 1.4.0 errors/ParseError#MissingName#);
125 }
126
127 // Parse `description`
128 let description = docs.removerust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]remove().("description").unwrap_or_defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or_default().();
129
130 // Parse `middle`
131 let params = middle
132 .split_whitespacerust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]split_whitespace().()
133 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(Parameterrust-analyzer cargo tdlib-rs-parser 1.4.0 tl/parameter/Parameter#::from_strrust-analyzer cargo tdlib-rs-parser 1.4.0 tl/parameter/impl#[Parameter][FromStr]from_str().)
134 .filter_maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter_map().(|p| {
135 let mut result = match p {
136 // Any parameter that's okay should just be passed as-is.
137 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(p) => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(p)),
138
139 // Unimplenented parameters are unimplemented definitions.
140 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(ParamParseErrorrust-analyzer cargo tdlib-rs-parser 1.4.0 errors/ParamParseError#::NotImplementedrust-analyzer cargo tdlib-rs-parser 1.4.0 errors/ParamParseError#NotImplemented#) => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(ParseErrorrust-analyzer cargo tdlib-rs-parser 1.4.0 errors/ParseError#::NotImplementedrust-analyzer cargo tdlib-rs-parser 1.4.0 errors/ParseError#NotImplemented#)),
141
142 // Any error should just become a `ParseError`
143 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(x) => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(ParseErrorrust-analyzer cargo tdlib-rs-parser 1.4.0 errors/ParseError#::InvalidParamrust-analyzer cargo tdlib-rs-parser 1.4.0 errors/ParseError#InvalidParam#(x))),
144 };
145
146 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(ref mut param)) = result {
147 let name = if param.namerust-analyzer cargo tdlib-rs-parser 1.4.0 tl/parameter/Parameter#name. rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]eq().==rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]eq(). rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]eq()."description" {
148 "param_description"
149 } else {
150 &param.namerust-analyzer cargo tdlib-rs-parser 1.4.0 tl/parameter/Parameter#name.
151 };
152
153 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(description) = docs.removerust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]remove().(name) {
154 param.descriptionrust-analyzer cargo tdlib-rs-parser 1.4.0 tl/parameter/Parameter#description. = description;
155 }
156 }
157
158 result
159 })
160 .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<_, ParseErrorrust-analyzer cargo tdlib-rs-parser 1.4.0 errors/ParseError#>>()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
161
162 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Definitionrust-analyzer cargo tdlib-rs-parser 1.4.0 tl/definition/Definition# {
163 namerust-analyzer cargo tdlib-rs-parser 1.4.0 tl/definition/Definition#name.: name.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(),
164 descriptionrust-analyzer cargo tdlib-rs-parser 1.4.0 tl/definition/Definition#description.,
165 paramsrust-analyzer cargo tdlib-rs-parser 1.4.0 tl/definition/Definition#params.,
166 tyrust-analyzer cargo tdlib-rs-parser 1.4.0 tl/definition/Definition#ty.,
167 categoryrust-analyzer cargo tdlib-rs-parser 1.4.0 tl/definition/Definition#category.: Categoryrust-analyzer cargo tdlib-rs-parser 1.4.0 tl/category/Category#::Typesrust-analyzer cargo tdlib-rs-parser 1.4.0 tl/category/Category#Types#,
168 })
169 }
170 }
171
172 #[cfg(test)]
173 mod testsrust-analyzer cargo tdlib-rs-parser 1.4.0 tl/definition/tests/ {
174 use superrust-analyzer cargo tdlib-rs-parser 1.4.0 tl/definition/::*;
175
176 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
177 fn parse_empty_defrust-analyzer cargo tdlib-rs-parser 1.4.0 tl/definition/tests/parse_empty_def().() {
178 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(Definitionrust-analyzer cargo tdlib-rs-parser 1.4.0 tl/definition/Definition#::from_strrust-analyzer cargo tdlib-rs-parser 1.4.0 tl/definition/impl#[Definition][FromStr]from_str().(""), Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(ParseErrorrust-analyzer cargo tdlib-rs-parser 1.4.0 errors/ParseError#::Emptyrust-analyzer cargo tdlib-rs-parser 1.4.0 errors/ParseError#Empty#));
179 }
180
181 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
182 fn parse_no_namerust-analyzer cargo tdlib-rs-parser 1.4.0 tl/definition/tests/parse_no_name().() {
183 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(Definitionrust-analyzer cargo tdlib-rs-parser 1.4.0 tl/definition/Definition#::from_strrust-analyzer cargo tdlib-rs-parser 1.4.0 tl/definition/impl#[Definition][FromStr]from_str().(" = foo"), Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(ParseErrorrust-analyzer cargo tdlib-rs-parser 1.4.0 errors/ParseError#::MissingNamerust-analyzer cargo tdlib-rs-parser 1.4.0 errors/ParseError#MissingName#));
184 }
185
186 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
187 fn parse_no_typerust-analyzer cargo tdlib-rs-parser 1.4.0 tl/definition/tests/parse_no_type().() {
188 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(Definitionrust-analyzer cargo tdlib-rs-parser 1.4.0 tl/definition/Definition#::from_strrust-analyzer cargo tdlib-rs-parser 1.4.0 tl/definition/impl#[Definition][FromStr]from_str().("foo"), Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(ParseErrorrust-analyzer cargo tdlib-rs-parser 1.4.0 errors/ParseError#::MissingTyperust-analyzer cargo tdlib-rs-parser 1.4.0 errors/ParseError#MissingType#));
189 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(Definitionrust-analyzer cargo tdlib-rs-parser 1.4.0 tl/definition/Definition#::from_strrust-analyzer cargo tdlib-rs-parser 1.4.0 tl/definition/impl#[Definition][FromStr]from_str().("foo = "), Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(ParseErrorrust-analyzer cargo tdlib-rs-parser 1.4.0 errors/ParseError#::MissingTyperust-analyzer cargo tdlib-rs-parser 1.4.0 errors/ParseError#MissingType#));
190 }
191
192 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
193 fn parse_unimplementedrust-analyzer cargo tdlib-rs-parser 1.4.0 tl/definition/tests/parse_unimplemented().() {
194 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
195 Definitionrust-analyzer cargo tdlib-rs-parser 1.4.0 tl/definition/Definition#::from_strrust-analyzer cargo tdlib-rs-parser 1.4.0 tl/definition/impl#[Definition][FromStr]from_str().("int ? = Int"),
196 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(ParseErrorrust-analyzer cargo tdlib-rs-parser 1.4.0 errors/ParseError#::NotImplementedrust-analyzer cargo tdlib-rs-parser 1.4.0 errors/ParseError#NotImplemented#)
197 );
198 }
199
200 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
201 fn parse_valid_definitionrust-analyzer cargo tdlib-rs-parser 1.4.0 tl/definition/tests/parse_valid_definition().() {
202 let def = Definitionrust-analyzer cargo tdlib-rs-parser 1.4.0 tl/definition/Definition#::from_strrust-analyzer cargo tdlib-rs-parser 1.4.0 tl/definition/impl#[Definition][FromStr]from_str().("a=d").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
203 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(def.namerust-analyzer cargo tdlib-rs-parser 1.4.0 tl/definition/Definition#name., "a");
204 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(def.paramsrust-analyzer cargo tdlib-rs-parser 1.4.0 tl/definition/Definition#params..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 0);
205 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
206 def.tyrust-analyzer cargo tdlib-rs-parser 1.4.0 tl/definition/Definition#ty.,
207 Typerust-analyzer cargo tdlib-rs-parser 1.4.0 tl/ty/Type# {
208 namerust-analyzer cargo tdlib-rs-parser 1.4.0 tl/ty/Type#name.: "d".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(),
209 barerust-analyzer cargo tdlib-rs-parser 1.4.0 tl/ty/Type#bare.: true,
210 generic_argrust-analyzer cargo tdlib-rs-parser 1.4.0 tl/ty/Type#generic_arg.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
211 }
212 );
213
214 let def = Definitionrust-analyzer cargo tdlib-rs-parser 1.4.0 tl/definition/Definition#::from_strrust-analyzer cargo tdlib-rs-parser 1.4.0 tl/definition/impl#[Definition][FromStr]from_str().("a=d<e>").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
215 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(def.namerust-analyzer cargo tdlib-rs-parser 1.4.0 tl/definition/Definition#name., "a");
216 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(def.paramsrust-analyzer cargo tdlib-rs-parser 1.4.0 tl/definition/Definition#params..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 0);
217 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
218 def.tyrust-analyzer cargo tdlib-rs-parser 1.4.0 tl/definition/Definition#ty.,
219 Typerust-analyzer cargo tdlib-rs-parser 1.4.0 tl/ty/Type# {
220 namerust-analyzer cargo tdlib-rs-parser 1.4.0 tl/ty/Type#name.: "d".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(),
221 barerust-analyzer cargo tdlib-rs-parser 1.4.0 tl/ty/Type#bare.: true,
222 generic_argrust-analyzer cargo tdlib-rs-parser 1.4.0 tl/ty/Type#generic_arg.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T>`]new().("e".parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().())),
223 }
224 );
225
226 let def = Definitionrust-analyzer cargo tdlib-rs-parser 1.4.0 tl/definition/Definition#::from_strrust-analyzer cargo tdlib-rs-parser 1.4.0 tl/definition/impl#[Definition][FromStr]from_str().("a b:c = d").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
227 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(def.namerust-analyzer cargo tdlib-rs-parser 1.4.0 tl/definition/Definition#name., "a");
228 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(def.paramsrust-analyzer cargo tdlib-rs-parser 1.4.0 tl/definition/Definition#params..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 1);
229 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
230 def.tyrust-analyzer cargo tdlib-rs-parser 1.4.0 tl/definition/Definition#ty.,
231 Typerust-analyzer cargo tdlib-rs-parser 1.4.0 tl/ty/Type# {
232 namerust-analyzer cargo tdlib-rs-parser 1.4.0 tl/ty/Type#name.: "d".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(),
233 barerust-analyzer cargo tdlib-rs-parser 1.4.0 tl/ty/Type#bare.: true,
234 generic_argrust-analyzer cargo tdlib-rs-parser 1.4.0 tl/ty/Type#generic_arg.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
235 }
236 );
237 }
238
239 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
240 fn parse_multiline_definitionrust-analyzer cargo tdlib-rs-parser 1.4.0 tl/definition/tests/parse_multiline_definition().() {
241 let def = "
242 first lol:param
243 = t;
244 ";
245
246 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(Definitionrust-analyzer cargo tdlib-rs-parser 1.4.0 tl/definition/Definition#::from_strrust-analyzer cargo tdlib-rs-parser 1.4.0 tl/definition/impl#[Definition][FromStr]from_str().(def).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().().namerust-analyzer cargo tdlib-rs-parser 1.4.0 tl/definition/Definition#name., "first");
247
248 let def = "
249 second
250 lol:String
251 = t;
252 ";
253
254 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(Definitionrust-analyzer cargo tdlib-rs-parser 1.4.0 tl/definition/Definition#::from_strrust-analyzer cargo tdlib-rs-parser 1.4.0 tl/definition/impl#[Definition][FromStr]from_str().(def).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().().namerust-analyzer cargo tdlib-rs-parser 1.4.0 tl/definition/Definition#name., "second");
255
256 let def = "
257 third
258
259 lol:String
260
261 =
262 t;
263 ";
264
265 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(Definitionrust-analyzer cargo tdlib-rs-parser 1.4.0 tl/definition/Definition#::from_strrust-analyzer cargo tdlib-rs-parser 1.4.0 tl/definition/impl#[Definition][FromStr]from_str().(def).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().().namerust-analyzer cargo tdlib-rs-parser 1.4.0 tl/definition/Definition#name., "third");
266 }
267
268 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
269 fn parse_completerust-analyzer cargo tdlib-rs-parser 1.4.0 tl/definition/tests/parse_complete().() {
270 let def = "
271 //@description This is a test description
272 name pname:Vector<X> = Type";
273 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
274 Definitionrust-analyzer cargo tdlib-rs-parser 1.4.0 tl/definition/Definition#::from_strrust-analyzer cargo tdlib-rs-parser 1.4.0 tl/definition/impl#[Definition][FromStr]from_str().(def),
275 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Definitionrust-analyzer cargo tdlib-rs-parser 1.4.0 tl/definition/Definition# {
276 namerust-analyzer cargo tdlib-rs-parser 1.4.0 tl/definition/Definition#name.: "name".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(),
277 descriptionrust-analyzer cargo tdlib-rs-parser 1.4.0 tl/definition/Definition#description.: "This is a test description".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(),
278 paramsrust-analyzer cargo tdlib-rs-parser 1.4.0 tl/definition/Definition#params.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![Parameterrust-analyzer cargo tdlib-rs-parser 1.4.0 tl/parameter/Parameter# {
279 namerust-analyzer cargo tdlib-rs-parser 1.4.0 tl/parameter/Parameter#name.: "pname".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(),
280 tyrust-analyzer cargo tdlib-rs-parser 1.4.0 tl/parameter/Parameter#ty.: Typerust-analyzer cargo tdlib-rs-parser 1.4.0 tl/ty/Type# {
281 namerust-analyzer cargo tdlib-rs-parser 1.4.0 tl/ty/Type#name.: "Vector".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(),
282 barerust-analyzer cargo tdlib-rs-parser 1.4.0 tl/ty/Type#bare.: false,
283 generic_argrust-analyzer cargo tdlib-rs-parser 1.4.0 tl/ty/Type#generic_arg.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/impl#[`Box<T>`]new().(Typerust-analyzer cargo tdlib-rs-parser 1.4.0 tl/ty/Type# {
284 namerust-analyzer cargo tdlib-rs-parser 1.4.0 tl/ty/Type#name.: "X".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(),
285 barerust-analyzer cargo tdlib-rs-parser 1.4.0 tl/ty/Type#bare.: false,
286 generic_argrust-analyzer cargo tdlib-rs-parser 1.4.0 tl/ty/Type#generic_arg.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
287 })),
288 },
289 descriptionrust-analyzer cargo tdlib-rs-parser 1.4.0 tl/parameter/Parameter#description.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]new().(),
290 },],
291 tyrust-analyzer cargo tdlib-rs-parser 1.4.0 tl/definition/Definition#ty.: Typerust-analyzer cargo tdlib-rs-parser 1.4.0 tl/ty/Type# {
292 namerust-analyzer cargo tdlib-rs-parser 1.4.0 tl/ty/Type#name.: "Type".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(),
293 barerust-analyzer cargo tdlib-rs-parser 1.4.0 tl/ty/Type#bare.: false,
294 generic_argrust-analyzer cargo tdlib-rs-parser 1.4.0 tl/ty/Type#generic_arg.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
295 },
296 categoryrust-analyzer cargo tdlib-rs-parser 1.4.0 tl/definition/Definition#category.: Categoryrust-analyzer cargo tdlib-rs-parser 1.4.0 tl/category/Category#::Typesrust-analyzer cargo tdlib-rs-parser 1.4.0 tl/category/Category#Types#,
297 })
298 );
299 }
300
301 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
302 fn test_to_stringrust-analyzer cargo tdlib-rs-parser 1.4.0 tl/definition/tests/test_to_string().() {
303 let def = "name pname:Vector<X> = Type";
304 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(Definitionrust-analyzer cargo tdlib-rs-parser 1.4.0 tl/definition/Definition#::from_strrust-analyzer cargo tdlib-rs-parser 1.4.0 tl/definition/impl#[Definition][FromStr]from_str().(def).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().().to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), def);
305 }
306 }