omnisci/
completion_hints.rs1#![allow(unused_imports)]
6#![allow(unused_extern_crates)]
7#![cfg_attr(feature = "cargo-clippy", allow(clippy::too_many_arguments, clippy::type_complexity))]
8#![cfg_attr(rustfmt, rustfmt_skip)]
9
10extern crate thrift;
11
12use thrift::OrderedFloat;
13use std::cell::RefCell;
14use std::collections::{BTreeMap, BTreeSet};
15use std::convert::{From, TryFrom};
16use std::default::Default;
17use std::error::Error;
18use std::fmt;
19use std::fmt::{Display, Formatter};
20use std::rc::Rc;
21
22use thrift::{ApplicationError, ApplicationErrorKind, ProtocolError, ProtocolErrorKind, TThriftClient};
23use thrift::protocol::{TFieldIdentifier, TListIdentifier, TMapIdentifier, TMessageIdentifier, TMessageType, TInputProtocol, TOutputProtocol, TSetIdentifier, TStructIdentifier, TType};
24use thrift::protocol::field_id;
25use thrift::protocol::verify_expected_message_type;
26use thrift::protocol::verify_expected_sequence_number;
27use thrift::protocol::verify_expected_service_call;
28use thrift::protocol::verify_required_field_exists;
29use thrift::server::TProcessor;
30
31#[derive(Copy, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
32pub enum TCompletionHintType {
33 Column = 0,
34 Table = 1,
35 View = 2,
36 Schema = 3,
37 Catalog = 4,
38 Repository = 5,
39 Function = 6,
40 Keyword = 7,
41}
42
43impl TCompletionHintType {
44 pub fn write_to_out_protocol(&self, o_prot: &mut dyn TOutputProtocol) -> thrift::Result<()> {
45 o_prot.write_i32(*self as i32)
46 }
47 pub fn read_from_in_protocol(i_prot: &mut dyn TInputProtocol) -> thrift::Result<TCompletionHintType> {
48 let enum_value = i_prot.read_i32()?;
49 TCompletionHintType::try_from(enum_value) }
50}
51
52impl TryFrom<i32> for TCompletionHintType {
53 type Error = thrift::Error; fn try_from(i: i32) -> Result<Self, Self::Error> {
54 match i {
55 0 => Ok(TCompletionHintType::Column),
56 1 => Ok(TCompletionHintType::Table),
57 2 => Ok(TCompletionHintType::View),
58 3 => Ok(TCompletionHintType::Schema),
59 4 => Ok(TCompletionHintType::Catalog),
60 5 => Ok(TCompletionHintType::Repository),
61 6 => Ok(TCompletionHintType::Function),
62 7 => Ok(TCompletionHintType::Keyword),
63 _ => {
64 Err(
65 thrift::Error::Protocol(
66 ProtocolError::new(
67 ProtocolErrorKind::InvalidData,
68 format!("cannot convert enum constant {} to TCompletionHintType", i)
69 )
70 )
71 )
72 },
73 }
74 }
75}
76
77#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
82pub struct TCompletionHint {
83 pub type_: Option<TCompletionHintType>,
84 pub hints: Option<Vec<String>>,
85 pub replaced: Option<String>,
86}
87
88impl TCompletionHint {
89 pub fn new<F1, F2, F3>(type_: F1, hints: F2, replaced: F3) -> TCompletionHint where F1: Into<Option<TCompletionHintType>>, F2: Into<Option<Vec<String>>>, F3: Into<Option<String>> {
90 TCompletionHint {
91 type_: type_.into(),
92 hints: hints.into(),
93 replaced: replaced.into(),
94 }
95 }
96 pub fn read_from_in_protocol(i_prot: &mut dyn TInputProtocol) -> thrift::Result<TCompletionHint> {
97 i_prot.read_struct_begin()?;
98 let mut f_1: Option<TCompletionHintType> = None;
99 let mut f_2: Option<Vec<String>> = Some(Vec::new());
100 let mut f_3: Option<String> = Some("".to_owned());
101 loop {
102 let field_ident = i_prot.read_field_begin()?;
103 if field_ident.field_type == TType::Stop {
104 break;
105 }
106 let field_id = field_id(&field_ident)?;
107 match field_id {
108 1 => {
109 let val = TCompletionHintType::read_from_in_protocol(i_prot)?;
110 f_1 = Some(val);
111 },
112 2 => {
113 let list_ident = i_prot.read_list_begin()?;
114 let mut val: Vec<String> = Vec::with_capacity(list_ident.size as usize);
115 for _ in 0..list_ident.size {
116 let list_elem_0 = i_prot.read_string()?;
117 val.push(list_elem_0);
118 }
119 i_prot.read_list_end()?;
120 f_2 = Some(val);
121 },
122 3 => {
123 let val = i_prot.read_string()?;
124 f_3 = Some(val);
125 },
126 _ => {
127 i_prot.skip(field_ident.field_type)?;
128 },
129 };
130 i_prot.read_field_end()?;
131 }
132 i_prot.read_struct_end()?;
133 let ret = TCompletionHint {
134 type_: f_1,
135 hints: f_2,
136 replaced: f_3,
137 };
138 Ok(ret)
139 }
140 pub fn write_to_out_protocol(&self, o_prot: &mut dyn TOutputProtocol) -> thrift::Result<()> {
141 let struct_ident = TStructIdentifier::new("TCompletionHint");
142 o_prot.write_struct_begin(&struct_ident)?;
143 if let Some(ref fld_var) = self.type_ {
144 o_prot.write_field_begin(&TFieldIdentifier::new("type", TType::I32, 1))?;
145 fld_var.write_to_out_protocol(o_prot)?;
146 o_prot.write_field_end()?;
147 ()
148 } else {
149 ()
150 }
151 if let Some(ref fld_var) = self.hints {
152 o_prot.write_field_begin(&TFieldIdentifier::new("hints", TType::List, 2))?;
153 o_prot.write_list_begin(&TListIdentifier::new(TType::String, fld_var.len() as i32))?;
154 for e in fld_var {
155 o_prot.write_string(e)?;
156 o_prot.write_list_end()?;
157 }
158 o_prot.write_field_end()?;
159 ()
160 } else {
161 ()
162 }
163 if let Some(ref fld_var) = self.replaced {
164 o_prot.write_field_begin(&TFieldIdentifier::new("replaced", TType::String, 3))?;
165 o_prot.write_string(fld_var)?;
166 o_prot.write_field_end()?;
167 ()
168 } else {
169 ()
170 }
171 o_prot.write_field_stop()?;
172 o_prot.write_struct_end()
173 }
174}
175
176impl Default for TCompletionHint {
177 fn default() -> Self {
178 TCompletionHint{
179 type_: None,
180 hints: Some(Vec::new()),
181 replaced: Some("".to_owned()),
182 }
183 }
184}