railsgun/
lib.rs

1//! # RailsGun
2//!
3//! RailsGun or Railgun, call it how you want it.
4//! This crate add a lot of small but valuable functionality to the existing
5//! Rail paradigm in rust.
6//!
7//! If you are used to using rails in rust, you know what it's all about! If
8//! its the first time you hear about it, I would highly suggest you read
9//! the following [Railway Oriented Programming](https://fsharpforfunandprofit.com/rop/);
10//! In short its a programming style that I have found over multiple projects
11//! and services to reduce the errors.
12//!
13//! This crate supplies you with some extra missing tools and simplifications
14//! as follows:
15//!
16//! ## rail-tap, tap_err, tap_ref, tap_err_ref
17//! This is an excellent little trait that adds the ability to "rail-tap" the contents.
18//! This means that you can get a copy/clone of the original content that
19//! you can use for analysis or other destructive operations without
20//! actually touching the original.
21//!
22//! > Note:
23//! > `tap_ref` and `tap_err_ref` unfortunatly
24//! > is just a reference so destructive actions should not be taken.
25//!
26//! ## merge, merge2, merge3, merge4
27//!
28//! This is for merging multiple results. If you have worked with rails
29//! before you have probably tried the following:
30//!
31//! ```rust
32//! use railsgun::Merge;
33//!
34//! fn func_xyz(x: u32, y: u32, z: u32) -> Result<u32,u32> {
35//!     Ok( x + y + z)
36//! }
37//!
38//! let x = Ok(1);
39//! let y = Ok(2);
40//! let z = Ok(3);
41//!
42//! x.and_then(|var_x|
43//!     y.and_then(|var_y|
44//!         z.and_then(|var_z|
45//!             func_xyz(var_x, var_y, var_z)
46//!         )
47//!     )
48//! ).ok();
49//! ```
50//! This is a hideous method of combining three results, you could
51//! split it out into multiple functions, but at times that is very
52//! excessive. Merge supplies you with superior functionality for this.
53//! ```rust
54//! use railsgun::Merge;
55//!
56//! fn func_xyz(x: u32, y: u32, z: u32) -> Result<u32,u32> {
57//!     Ok( x + y + z)
58//! }
59//!
60//! # async fn run() -> () {
61//! let x = Ok(1);
62//! let y = Ok(2);
63//! let z = Ok(3);
64//! x.merge2(y, z, |var_x, var_y, var_z| func_xyz(var_x, var_y, var_z)).ok();
65//! # }
66//! ```
67//! As you can see, this simplifies the rail significantly and makes
68//! it more readable/maintainable.
69//!
70//! # Todo
71//! There is a significant need for more documentation on the trait and others
72//! as this library has been in my private stack for a long time and did get the
73//! doc-care it needed.
74//! 1. rail-tap needs doc
75//! 2. merge needs doc
76//! 3. Implement `BlockInPlace` for `AsyncResult`
77//! 4. More unit tests are needed.
78//!
79//! Please open a ticket for more ideas!
80//!
81//! # Contribution
82//! Feel free to contribute to the project. Currently, the project is hosted
83//! on both [GitHub](https://github.com/nebula-technologies/Railgun) and
84//! my private [GitLab](https://gitlab.nebula.technology/rust/railsgun).
85//! The main repository is the GitLab repository, where all of the pipelines
86//! and all of my projects exist.
87//!
88//! # License
89//! The MIT License (MIT)
90//!
91//! Copyright © 2021 <copyright holders>
92//!
93//! Permission is hereby granted, free of charge, to any person obtaining a copy of this Software
94//! and associated documentation files (the “Software”), to deal in the Software without restriction,
95//! including without limitation the rights to use, copy, modify, merge, publish, distribute,
96//! sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
97//! furnished to do so, subject to the following conditions:
98//!
99//! The above copyright notice and this permission notice shall be included in all copies or
100//! substantial portions of the Software.
101//!
102//! THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
103//! BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
104//! NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
105//! DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
106//! OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
107#[macro_use]
108extern crate tokio;
109#[cfg(feature = "rail-merge")]
110pub mod rail_merge;
111#[cfg(feature = "rail-tap")]
112pub mod rail_tap;
113pub mod futures;
114#[cfg(feature = "option-extended")]
115pub mod option_extended;
116pub mod iterators;
117
118#[cfg(feature = "future-result")]
119pub use futures::future_result::{IntoFuture, FutureResult};
120
121#[cfg(feature = "map-iter")]
122pub use iterators::map_iterator::ResultMapIterator;
123
124#[cfg(feature = "rail-merge")]
125pub use rail_merge::Merge;
126#[cfg(feature = "rail-merge")]
127pub use rail_merge::MergeOption;
128
129#[cfg(feature = "rail-tap")]
130pub use rail_tap::{Tap, TapErr, TapErrRef, TapRef, ThreadTap, ThreadTapErr};
131
132#[cfg(feature = "option-extended")]
133pub use option_extended::{OptionsExtended, IntoOption};