wick_component/
lib.rs

1#![doc(html_logo_url = "https://avatars.githubusercontent.com/u/104781277?s=96&v=4")]
2#![doc = include_str!("../README.md")]
3// !!START_LINTS
4// Wick lints
5// Do not change anything between the START_LINTS and END_LINTS line.
6// This is automatically generated. Add exceptions after this section.
7#![allow(unknown_lints)]
8#![deny(
9  clippy::await_holding_lock,
10  clippy::borrow_as_ptr,
11  clippy::branches_sharing_code,
12  clippy::cast_lossless,
13  clippy::clippy::collection_is_never_read,
14  clippy::cloned_instead_of_copied,
15  clippy::cognitive_complexity,
16  clippy::create_dir,
17  clippy::deref_by_slicing,
18  clippy::derivable_impls,
19  clippy::derive_partial_eq_without_eq,
20  clippy::equatable_if_let,
21  clippy::exhaustive_structs,
22  clippy::expect_used,
23  clippy::expl_impl_clone_on_copy,
24  clippy::explicit_deref_methods,
25  clippy::explicit_into_iter_loop,
26  clippy::explicit_iter_loop,
27  clippy::filetype_is_file,
28  clippy::flat_map_option,
29  clippy::format_push_string,
30  clippy::fn_params_excessive_bools,
31  clippy::future_not_send,
32  clippy::get_unwrap,
33  clippy::implicit_clone,
34  clippy::if_then_some_else_none,
35  clippy::impl_trait_in_params,
36  clippy::implicit_clone,
37  clippy::inefficient_to_string,
38  clippy::inherent_to_string,
39  clippy::iter_not_returning_iterator,
40  clippy::large_types_passed_by_value,
41  clippy::large_include_file,
42  clippy::let_and_return,
43  clippy::manual_assert,
44  clippy::manual_ok_or,
45  clippy::manual_split_once,
46  clippy::manual_let_else,
47  clippy::manual_string_new,
48  clippy::map_flatten,
49  clippy::map_unwrap_or,
50  clippy::missing_enforced_import_renames,
51  clippy::missing_assert_message,
52  clippy::missing_const_for_fn,
53  clippy::must_use_candidate,
54  clippy::mut_mut,
55  clippy::needless_for_each,
56  clippy::needless_option_as_deref,
57  clippy::needless_pass_by_value,
58  clippy::needless_collect,
59  clippy::needless_continue,
60  clippy::non_send_fields_in_send_ty,
61  clippy::nonstandard_macro_braces,
62  clippy::option_if_let_else,
63  clippy::option_option,
64  clippy::rc_mutex,
65  clippy::redundant_else,
66  clippy::same_name_method,
67  clippy::semicolon_if_nothing_returned,
68  clippy::str_to_string,
69  clippy::string_to_string,
70  clippy::too_many_lines,
71  clippy::trivially_copy_pass_by_ref,
72  clippy::trivial_regex,
73  clippy::try_err,
74  clippy::unnested_or_patterns,
75  clippy::unused_async,
76  clippy::unwrap_or_else_default,
77  clippy::useless_let_if_seq,
78  bad_style,
79  clashing_extern_declarations,
80  dead_code,
81  deprecated,
82  explicit_outlives_requirements,
83  improper_ctypes,
84  invalid_value,
85  missing_copy_implementations,
86  missing_debug_implementations,
87  mutable_transmutes,
88  no_mangle_generic_items,
89  non_shorthand_field_patterns,
90  overflowing_literals,
91  path_statements,
92  patterns_in_fns_without_body,
93  private_in_public,
94  trivial_bounds,
95  trivial_casts,
96  trivial_numeric_casts,
97  type_alias_bounds,
98  unconditional_recursion,
99  unreachable_pub,
100  unsafe_code,
101  unstable_features,
102  unused,
103  unused_allocation,
104  unused_comparisons,
105  unused_import_braces,
106  unused_parens,
107  unused_qualifications,
108  while_true,
109  missing_docs
110)]
111#![warn(clippy::exhaustive_enums)]
112#![allow(unused_attributes, clippy::derive_partial_eq_without_eq, clippy::box_default)]
113// !!END_LINTS
114// Add exceptions here
115#![allow()]
116
117/// A module implementing custom serializers/deserializers for wick types.
118pub mod serde_util;
119
120//
121//
122/// Macros used by wick components and generated code.
123pub mod macros;
124//
125//
126/// Re-export of the complete [bytes] module.
127#[cfg(feature = "bytes")]
128pub use bytes;
129//
130//
131/// Re-exported methods used for `datetime` types.
132#[cfg(feature = "datetime")]
133pub mod datetime {
134  /// Re-export of the chrono crate.
135  pub use chrono;
136  pub use chrono::format::strftime;
137  pub use chrono::offset::TimeZone;
138  pub use chrono::serde::ts_milliseconds;
139  pub use chrono::{DateTime as ChronoDateTime, Utc};
140  pub use wick_packet::{date_from_millis, serde, DateTime};
141}
142//
143//
144/// Re-export of serde_json utilities;
145pub use serde_json::{from_slice, from_str, from_value, json, to_value, Map, Value};
146//
147//
148/// Re-export of tokio_stream utilities;
149pub use tokio_stream::{empty, iter as iter_raw, once as once_raw, Stream, StreamExt};
150//
151//
152/// Re-export of wasmrs_guest.
153#[cfg(target_family = "wasm")]
154pub use wasmrs_guest;
155//
156//
157/// Re-export of wasmrs_rx traits and core types.
158pub use wasmrs_rx::{Flux, FluxChannel, Observable, Observer};
159//
160//
161/// Old export name for `wick_packet`
162#[cfg(deprecated)]
163pub use wick_packet as packet;
164//
165//
166/// Re-export of [wick_packet::Base64Bytes] as [Bytes].
167pub use wick_packet::{Base64Bytes as Bytes, BoxStream, Packet, PacketExt, PacketSender, Port, VPacket, ValuePort};
168//
169//
170/// Other re-exported crates;
171pub use {flow_component, paste, wasmrs, wasmrs_codec, wasmrs_runtime as runtime, wasmrs_rx, wick_packet};
172
173//
174//
175/// Generic boxed-error type.
176pub type BoxError = Box<dyn std::error::Error + Send + Sync + 'static>;
177
178//
179//
180/// A re-export of the `anyhow::Error` type.
181pub type AnyError = anyhow::Error;
182pub use anyhow;
183
184//
185//
186/// A stream of `Result<T, AnyError>`.
187pub type WickStream<T> = wasmrs_rx::BoxFlux<T, AnyError>;
188
189/// Create a stream of `Result<T, AnyError>` that yields one value and ends.
190///
191/// # Example
192///
193/// ```
194/// # use wick_component::prelude::*;
195///
196/// let mut stream = once(42);
197/// assert_eq!(stream.next().await, Some(Ok(42)));
198/// assert_eq!(stream.next().await, None);
199/// ```
200///
201pub fn once<T>(value: T) -> impl Stream<Item = Result<T, AnyError>> {
202  tokio_stream::once(Ok(value))
203}
204
205/// Create a stream of `Result<T, AnyError>` from an iterator of type T.
206///
207/// This is a convenience function for creating a Result/TryStream from an iterator of `Ok` values.
208///
209/// # Example
210///
211/// ```
212/// # use wick_component::prelude::*;
213///
214/// let mut stream = iter(vec![1, 2, 3]);
215/// assert_eq!(stream.next().await, Some(Ok(1)));
216/// assert_eq!(stream.next().await, Some(Ok(2)));
217/// assert_eq!(stream.next().await, Some(Ok(3)));
218/// assert_eq!(stream.next().await, None);
219/// ```
220///
221pub fn iter<I, O>(i: I) -> impl Stream<Item = Result<O, AnyError>>
222where
223  I: IntoIterator<Item = O>,
224{
225  tokio_stream::iter(i.into_iter().map(|i| Ok(i)))
226}
227
228mod adapters;
229/// Functions and macros for common operation types.
230pub use adapters::*;
231
232mod outputs;
233pub use outputs::{Broadcast, SingleOutput};
234//
235//
236/// The proc macro to automatically implement common operaton types.
237pub use wick_operation::operation;
238
239/// Useful userland utilities that can be exported via `use wick_component::prelude::*`
240#[cfg(deprecated = "Use `wick_component::*` instead")]
241#[doc(hidden)]
242pub mod prelude {
243  pub use super::*;
244}