wick_stdlib/
lib.rs

1// !!START_LINTS
2// Wick lints
3// Do not change anything between the START_LINTS and END_LINTS line.
4// This is automatically generated. Add exceptions after this section.
5#![allow(unknown_lints)]
6#![deny(
7  clippy::await_holding_lock,
8  clippy::borrow_as_ptr,
9  clippy::branches_sharing_code,
10  clippy::cast_lossless,
11  clippy::clippy::collection_is_never_read,
12  clippy::cloned_instead_of_copied,
13  clippy::cognitive_complexity,
14  clippy::create_dir,
15  clippy::deref_by_slicing,
16  clippy::derivable_impls,
17  clippy::derive_partial_eq_without_eq,
18  clippy::equatable_if_let,
19  clippy::exhaustive_structs,
20  clippy::expect_used,
21  clippy::expl_impl_clone_on_copy,
22  clippy::explicit_deref_methods,
23  clippy::explicit_into_iter_loop,
24  clippy::explicit_iter_loop,
25  clippy::filetype_is_file,
26  clippy::flat_map_option,
27  clippy::format_push_string,
28  clippy::fn_params_excessive_bools,
29  clippy::future_not_send,
30  clippy::get_unwrap,
31  clippy::implicit_clone,
32  clippy::if_then_some_else_none,
33  clippy::impl_trait_in_params,
34  clippy::implicit_clone,
35  clippy::inefficient_to_string,
36  clippy::inherent_to_string,
37  clippy::iter_not_returning_iterator,
38  clippy::large_types_passed_by_value,
39  clippy::large_include_file,
40  clippy::let_and_return,
41  clippy::manual_assert,
42  clippy::manual_ok_or,
43  clippy::manual_split_once,
44  clippy::manual_let_else,
45  clippy::manual_string_new,
46  clippy::map_flatten,
47  clippy::map_unwrap_or,
48  clippy::missing_enforced_import_renames,
49  clippy::missing_assert_message,
50  clippy::missing_const_for_fn,
51  clippy::must_use_candidate,
52  clippy::mut_mut,
53  clippy::needless_for_each,
54  clippy::needless_option_as_deref,
55  clippy::needless_pass_by_value,
56  clippy::needless_collect,
57  clippy::needless_continue,
58  clippy::non_send_fields_in_send_ty,
59  clippy::nonstandard_macro_braces,
60  clippy::option_if_let_else,
61  clippy::option_option,
62  clippy::rc_mutex,
63  clippy::redundant_else,
64  clippy::same_name_method,
65  clippy::semicolon_if_nothing_returned,
66  clippy::str_to_string,
67  clippy::string_to_string,
68  clippy::too_many_lines,
69  clippy::trivially_copy_pass_by_ref,
70  clippy::trivial_regex,
71  clippy::try_err,
72  clippy::unnested_or_patterns,
73  clippy::unused_async,
74  clippy::unwrap_or_else_default,
75  clippy::useless_let_if_seq,
76  bad_style,
77  clashing_extern_declarations,
78  dead_code,
79  deprecated,
80  explicit_outlives_requirements,
81  improper_ctypes,
82  invalid_value,
83  missing_copy_implementations,
84  missing_debug_implementations,
85  mutable_transmutes,
86  no_mangle_generic_items,
87  non_shorthand_field_patterns,
88  overflowing_literals,
89  path_statements,
90  patterns_in_fns_without_body,
91  private_in_public,
92  trivial_bounds,
93  trivial_casts,
94  trivial_numeric_casts,
95  type_alias_bounds,
96  unconditional_recursion,
97  unreachable_pub,
98  unsafe_code,
99  unstable_features,
100  unused,
101  unused_allocation,
102  unused_comparisons,
103  unused_import_braces,
104  unused_parens,
105  unused_qualifications,
106  while_true,
107  missing_docs
108)]
109#![warn(clippy::exhaustive_enums)]
110#![allow(unused_attributes, clippy::derive_partial_eq_without_eq, clippy::box_default)]
111// !!END_LINTS
112// Add exceptions here
113#![allow(missing_docs)]
114
115mod macros;
116mod operations;
117
118use flow_component::{Component, RuntimeCallback};
119use seeded_random::Seed;
120use wick_interface_types::{component, ComponentSignature};
121use wick_packet::{Invocation, PacketStream, RuntimeConfig};
122use wick_rpc::dispatch;
123
124#[macro_use]
125extern crate tracing;
126
127#[derive(Clone, Debug, Copy)]
128#[non_exhaustive]
129pub struct Context {}
130
131#[derive(Debug)]
132#[must_use]
133pub struct Collection {
134  #[allow(unused)]
135  seed: Seed,
136  signature: ComponentSignature,
137}
138
139impl Collection {
140  pub fn new(seed: Seed) -> Self {
141    let sig = component! {
142        name: "wick-stdlib",
143        version: Some("0.1.0"),
144        operations: {
145          "core::error" => {
146
147            inputs: { "input" => "string" },
148            outputs: { "output" => "string" },
149          },
150          "core::log" => {
151
152            inputs: { "input" => "string" },
153            outputs: { "output" => "string" },
154          },
155          "core::panic" => {
156
157            inputs: { "input" => "string" },
158            outputs: { "output" => "string" },
159          },
160          "math::add" => {
161
162            inputs: { "left" => "u64", "right" => "u64" },
163            outputs: { "output" => "u64" },
164          },
165          "math::subtract" => {
166
167            inputs: { "left" => "u64", "right" => "u64" },
168            outputs: { "output" => "u64" },
169          },
170          "rand::bytes" => {
171
172            inputs: { "seed" => "u64", "length" => "u32" },
173            outputs: { "output" => "bytes" },
174          },
175          "rand::string" => {
176
177            inputs: { "seed" => "u64", "length" => "u32" },
178            outputs: { "output" => "string" },
179          },
180          "rand::uuid" => {
181
182            inputs: { "seed" => "u64" },
183            outputs: { "output" => "string" },
184          },
185          "string::concat" => {
186
187            inputs: { "left" => "string", "right" => "string" },
188            outputs: { "output" => "string" },
189          }
190        }
191    };
192    Self { seed, signature: sig }
193  }
194}
195
196impl Component for Collection {
197  fn handle(
198    &self,
199    invocation: Invocation,
200    _data: Option<RuntimeConfig>,
201    _callback: std::sync::Arc<RuntimeCallback>,
202  ) -> flow_component::BoxFuture<Result<PacketStream, flow_component::ComponentError>> {
203    let target = invocation.target().url();
204    trace!("stdlib invoke: {}", target);
205
206    Box::pin(async move {
207      let stream = dispatch!(invocation, {
208            "core::error" => operations::core::error::job,
209            "core::log" => operations::core::log::job,
210            "core::panic" => operations::core::panic::job,
211            "math::add" => operations::math::add::job,
212            "math::subtract" => operations::math::subtract::job,
213            "rand::bytes" => operations::rand::bytes::job,
214            "rand::string" => operations::rand::string::job,
215            "rand::uuid" => operations::rand::uuid::job,
216            "string::concat" => operations::string::concat::job,
217      });
218      Ok(stream)
219    })
220  }
221
222  fn signature(&self) -> &ComponentSignature {
223    &self.signature
224  }
225}