Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GH-544 - removing wrap_to_ok() and wrap_to_error() #246

Merged
merged 5 commits into from
Mar 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions masq/src/terminal/terminal_interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use crate::terminal::secondary_infrastructure::{
use linefeed::{Interface, Signal};
use masq_lib::command::StdStreams;
use masq_lib::constants::MASQ_PROMPT;
use masq_lib::utils::WrapResult;
use std::sync::Arc;

#[cfg(not(test))]
Expand Down Expand Up @@ -65,8 +64,9 @@ impl TerminalWrapper {
if std::env::var(prod_cfg::MASQ_TEST_INTEGRATION_KEY)
.eq(&Ok(prod_cfg::MASQ_TEST_INTEGRATION_VALUE.to_string()))
{
TerminalWrapper::new(Arc::new(prod_cfg::IntegrationTestTerminal::default()))
.wrap_to_ok()
Ok(TerminalWrapper::new(Arc::new(
prod_cfg::IntegrationTestTerminal::default(),
)))
} else {
//we have no positive test aimed at this (only negative and as an integration test)
Self::configure_interface_generic(Box::new(prod_cfg::DefaultTerminal::new))
Expand All @@ -80,11 +80,10 @@ impl TerminalWrapper {
F: FnOnce() -> std::io::Result<TerminalType>,
TerminalType: linefeed::Terminal + 'static,
{
Self::new(Arc::new(interface_configurator(
Ok(Self::new(Arc::new(interface_configurator(
terminal_creator_of_certain_type,
Box::new(Interface::with_term),
)?))
.wrap_to_ok()
)?)))
}
}

Expand All @@ -109,7 +108,7 @@ where

set_all_settable_parameters(interface.as_mut())?;

TerminalReal::new(interface).wrap_to_ok()
Ok(TerminalReal::new(interface))
}

fn set_all_settable_parameters<I>(interface: &mut I) -> Result<(), String>
Expand Down
3 changes: 1 addition & 2 deletions masq/src/test_utils/mocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ use masq_lib::command::StdStreams;
use masq_lib::constants::DEFAULT_UI_PORT;
use masq_lib::test_utils::fake_stream_holder::{ByteArrayWriter, ByteArrayWriterInner};
use masq_lib::ui_gateway::MessageBody;
use masq_lib::utils::WrapResult;
use std::cell::RefCell;
use std::fmt::Arguments;
use std::io::{Read, Write};
Expand Down Expand Up @@ -624,7 +623,7 @@ impl InterfaceWrapper for InterfaceRawMock {
if let Err(err) = taken_result {
Err(err)
} else {
(taken_result.unwrap() as Box<dyn WriterLock + 'static>).wrap_to_ok()
Ok(taken_result.unwrap() as Box<dyn WriterLock + 'static>)
}
}

Expand Down
3 changes: 1 addition & 2 deletions masq_lib/src/multi_config.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) 2019, MASQ (https://masq.ai) and/or its affiliates. All rights reserved.

use crate::shared_schema::{ConfiguratorError, ParamError};
use crate::utils::WrapResult;
#[allow(unused_imports)]
use clap::{value_t, values_t};
use clap::{App, ArgMatches};
Expand Down Expand Up @@ -78,7 +77,7 @@ impl<'a> MultiConfig<'a> {
_ => return Err(Self::make_configurator_error(e)),
},
};
MultiConfig { arg_matches }.wrap_to_ok()
Ok(MultiConfig { arg_matches })
}

pub fn make_configurator_error(e: clap::Error) -> ConfiguratorError {
Expand Down
19 changes: 0 additions & 19 deletions masq_lib/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,25 +314,6 @@ fn expect_value_panic(subject: &str, found: Option<&dyn fmt::Debug>) -> ! {
)
}

pub trait WrapResult {
fn wrap_to_ok<E>(self) -> Result<Self, E>
where
Self: Sized;
fn wrap_to_err<T>(self) -> Result<T, Self>
where
Self: Sized;
}

impl<T> WrapResult for T {
fn wrap_to_ok<E>(self) -> Result<Self, E> {
Ok(self)
}

fn wrap_to_err<V>(self) -> Result<V, Self> {
Err(self)
}
}

pub fn type_name_of<T>(_examined: T) -> &'static str {
std::any::type_name::<T>()
}
Expand Down
7 changes: 3 additions & 4 deletions node/src/database/db_migrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::sub_lib::cryptde::PlainData;
use crate::sub_lib::neighborhood::{RatePack, DEFAULT_RATE_PACK};
use itertools::Itertools;
use masq_lib::logger::Logger;
use masq_lib::utils::{ExpectValue, WrapResult};
use masq_lib::utils::ExpectValue;
use rusqlite::{params_from_iter, Error, Row, ToSql, Transaction};
use std::fmt::{Debug, Display, Formatter};
use tiny_hderive::bip32::ExtendedPrivKey;
Expand Down Expand Up @@ -96,11 +96,10 @@ impl<'a> DBMigrationUtilitiesReal<'a> {
conn: &'b mut dyn ConnectionWrapper,
db_migrator_configuration: DBMigratorInnerConfiguration,
) -> rusqlite::Result<Self> {
Self {
Ok(Self {
root_transaction: Some(conn.transaction()?),
db_migrator_configuration,
}
.wrap_to_ok()
})
}

fn root_transaction_ref(&self) -> &Transaction<'a> {
Expand Down
4 changes: 2 additions & 2 deletions node/src/node_configurator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use masq_lib::multi_config::{merge, CommandLineVcl, EnvironmentVcl, MultiConfig,
use masq_lib::shared_schema::{
chain_arg, config_file_arg, data_directory_arg, real_user_arg, ConfiguratorError,
};
use masq_lib::utils::{localhost, ExpectValue, WrapResult};
use masq_lib::utils::{localhost, ExpectValue};
use std::net::{SocketAddr, TcpListener};
use std::path::{Path, PathBuf};

Expand Down Expand Up @@ -60,7 +60,7 @@ pub fn determine_config_file_path(
real_user_data_directory_opt_and_chain(dirs_wrapper, &multi_config);
let directory =
data_directory_from_context(dirs_wrapper, &real_user, &data_directory_opt, chain);
(directory.join(config_file_path), user_specified).wrap_to_ok()
Ok((directory.join(config_file_path), user_specified))
}

pub fn initialize_database(
Expand Down
3 changes: 1 addition & 2 deletions node/src/node_configurator/node_configurator_standard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ use crate::sub_lib::utils::make_new_multi_config;
use crate::tls_discriminator_factory::TlsDiscriminatorFactory;
use masq_lib::constants::{DEFAULT_UI_PORT, HTTP_PORT, TLS_PORT};
use masq_lib::multi_config::{CommandLineVcl, ConfigFileVcl, EnvironmentVcl};
use masq_lib::utils::WrapResult;
use std::str::FromStr;

pub struct NodeConfiguratorStandardPrivileged {
Expand Down Expand Up @@ -160,7 +159,7 @@ pub fn server_initializer_collected_params<'a>(
.map(|dir| dir.to_path_buf())
.expectv("data_directory");
let real_user = real_user_from_multi_config_or_populate(&multi_config, dirs_wrapper);
GatheredParams::new(multi_config, data_directory, real_user).wrap_to_ok()
Ok(GatheredParams::new(multi_config, data_directory, real_user))
}

pub fn establish_port_configurations(config: &mut BootstrapperConfig) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use masq_lib::logger::Logger;
use masq_lib::multi_config::MultiConfig;
use masq_lib::shared_schema::{ConfiguratorError, ParamError};
use masq_lib::test_utils::utils::TEST_DEFAULT_CHAIN;
use masq_lib::utils::{AutomapProtocol, ExpectValue, WrapResult};
use masq_lib::utils::{AutomapProtocol, ExpectValue};
use rustc_hex::FromHex;
use std::net::{IpAddr, Ipv4Addr};
use std::str::FromStr;
Expand Down Expand Up @@ -400,7 +400,7 @@ fn validate_descriptors_from_user(
))
}
}
Err(e) => ParamError::new("neighbors", &e).wrap_to_err()
Err(e) => Err(ParamError::new("neighbors", &e))
}
})
.collect_vec()
Expand Down
2 changes: 1 addition & 1 deletion port_exposer/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.