Skip to content

Commit

Permalink
style(hydro_deploy): use name_of! macro (#1429)
Browse files Browse the repository at this point in the history
  • Loading branch information
MingweiSamuel authored Aug 27, 2024
1 parent 82de6f5 commit 3fde68d
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 18 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

17 changes: 9 additions & 8 deletions hydro_deploy/core/src/hydroflow_crate/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::path::PathBuf;
use std::sync::Arc;

use nameof::name_of;
use tracing_options::TracingOptions;

use super::Host;
Expand Down Expand Up @@ -63,7 +64,7 @@ impl HydroflowCrate {
/// equivalent to `cargo run --bin <name>`.
pub fn bin(mut self, bin: impl Into<String>) -> Self {
if self.target != CrateTarget::Default {
panic!("target already set");
panic!("{} already set", name_of!(target in Self));
}

self.target = CrateTarget::Bin(bin.into());
Expand All @@ -74,7 +75,7 @@ impl HydroflowCrate {
/// equivalent to `cargo run --example <name>`.
pub fn example(mut self, example: impl Into<String>) -> Self {
if self.target != CrateTarget::Default {
panic!("target already set");
panic!("{} already set", name_of!(target in Self));
}

self.target = CrateTarget::Example(example.into());
Expand All @@ -85,7 +86,7 @@ impl HydroflowCrate {
/// Equivalent to `cargo run --profile <profile>`.
pub fn profile(mut self, profile: impl Into<String>) -> Self {
if self.profile.is_some() {
panic!("profile already set");
panic!("{} already set", name_of!(profile in Self));
}

self.profile = Some(profile.into());
Expand All @@ -94,7 +95,7 @@ impl HydroflowCrate {

pub fn rustflags(mut self, rustflags: impl Into<String>) -> Self {
if self.rustflags.is_some() {
panic!("rustflags already set");
panic!("{} already set", name_of!(rustflags in Self));
}

self.rustflags = Some(rustflags.into());
Expand All @@ -103,7 +104,7 @@ impl HydroflowCrate {

pub fn target_dir(mut self, target_dir: impl Into<PathBuf>) -> Self {
if self.target_dir.is_some() {
panic!("target_dir already set");
panic!("{} already set", name_of!(target_dir in Self));
}

self.target_dir = Some(target_dir.into());
Expand All @@ -117,7 +118,7 @@ impl HydroflowCrate {

pub fn features(mut self, features: impl IntoIterator<Item = impl Into<String>>) -> Self {
if self.features.is_some() {
panic!("features already set");
panic!("{} already set", name_of!(features in Self));
}

self.features = Some(features.into_iter().map(|s| s.into()).collect());
Expand All @@ -126,7 +127,7 @@ impl HydroflowCrate {

pub fn tracing(mut self, perf: impl Into<TracingOptions>) -> Self {
if self.tracing.is_some() {
panic!("tracing options are already set");
panic!("{} already set", name_of!(tracing in Self));
}

self.tracing = Some(perf.into());
Expand All @@ -142,7 +143,7 @@ impl HydroflowCrate {
/// Sets the display name for this service, which will be used in logging.
pub fn display_name(mut self, display_name: impl Into<String>) -> Self {
if self.display_name.is_some() {
panic!("display_name already set");
panic!("{} already set", name_of!(display_name in Self));
}

self.display_name = Some(display_name.into());
Expand Down
11 changes: 6 additions & 5 deletions hydro_deploy/hydroflow_plus_deploy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,21 @@ deploy = [ "hydro_deploy", "trybuild-internals-api", "toml", "prettyplease" ]
stageleft_devel = []

[dependencies]
stageleft = { path = "../../stageleft", version = "^0.3.0" }
hydroflow_plus = { path = "../../hydroflow_plus", version = "^0.8.0", features = [ "deploy_integration" ] }
nameof = "1.0.0"
serde = { version = "1.0.197", features = [ "derive" ] }
sha2 = "0.10.0"
stageleft = { path = "../../stageleft", version = "^0.3.0" }
syn = { version = "2.0.46", features = [ "parsing", "extra-traits" ] }
tokio = { version = "1.29.0", features = [ "full" ] }
serde = { version = "1.0.197", features = [ "derive" ] }

hydro_deploy = { path = "../core", version = "^0.8.0", optional = true }
trybuild-internals-api = { version = "1.0.99", optional = true }
toml = { version = "0.8.0", optional = true }
prettyplease = { version = "0.2.0", features = [ "verbatim" ], optional = true }
toml = { version = "0.8.0", optional = true }
trybuild-internals-api = { version = "1.0.99", optional = true }

# added to workaround `cargo smart-release` https://github.com/Byron/cargo-smart-release/issues/16
stageleft_tool = { path = "../../stageleft_tool", version = "^0.2.0", optional = true }
sha2 = "0.10.0"

[build-dependencies]
stageleft_tool = { path = "../../stageleft_tool", version = "^0.2.0" }
11 changes: 6 additions & 5 deletions hydro_deploy/hydroflow_plus_deploy/src/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use hydro_deploy::hydroflow_crate::HydroflowCrateService;
use hydro_deploy::{Deployment, Host, HydroflowCrate};
use hydroflow_plus::deploy::{ClusterSpec, Deploy, Node, ProcessSpec};
use hydroflow_plus::lang::graph::HydroflowGraph;
use nameof::name_of;
use sha2::{Digest, Sha256};
use stageleft::Quoted;
use tokio::sync::RwLock;
Expand Down Expand Up @@ -278,20 +279,20 @@ impl TrybuildHost {
}
}

pub fn display_name(self, name: impl Into<String>) -> Self {
pub fn display_name(self, display_name: impl Into<String>) -> Self {
if self.display_name.is_some() {
panic!("display_name already set");
panic!("{} already set", name_of!(display_name in Self));
}

Self {
display_name: Some(name.into()),
display_name: Some(display_name.into()),
..self
}
}

pub fn rustflags(self, rustflags: impl Into<String>) -> Self {
if self.rustflags.is_some() {
panic!("rustflags already set");
panic!("{} already set", name_of!(rustflags in Self));
}

Self {
Expand All @@ -302,7 +303,7 @@ impl TrybuildHost {

pub fn tracing(self, tracing: TracingOptions) -> Self {
if self.tracing.is_some() {
panic!("tracing already set");
panic!("{} already set", name_of!(tracing in Self));
}

Self {
Expand Down

0 comments on commit 3fde68d

Please sign in to comment.