use std::borrow::Cow;
use std::ffi::OsString;
use std::fmt;
use std::path::Path;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum StackKind {
Runtime,
Framework,
Tool,
Database,
Service,
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct StackLabel {
text: Cow<'static, str>,
kind: StackKind,
}
impl StackLabel {
#[must_use]
pub fn new(text: impl Into<Cow<'static, str>>, kind: StackKind) -> Self {
Self {
text: text.into(),
kind,
}
}
#[must_use]
pub const fn from_static(text: &'static str, kind: StackKind) -> Self {
Self {
text: Cow::Borrowed(text),
kind,
}
}
#[must_use]
pub fn as_str(&self) -> &str {
&self.text
}
#[must_use]
pub const fn kind(&self) -> StackKind {
self.kind
}
#[must_use]
pub fn into_cow(self) -> Cow<'static, str> {
self.text
}
}
impl fmt::Display for StackLabel {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(&self.text)
}
}
impl AsRef<str> for StackLabel {
fn as_ref(&self) -> &str {
&self.text
}
}
impl PartialEq<str> for StackLabel {
fn eq(&self, other: &str) -> bool {
self.text == other
}
}
impl PartialEq<&str> for StackLabel {
fn eq(&self, other: &&str) -> bool {
self.text == *other
}
}
impl PartialEq<StackLabel> for str {
fn eq(&self, other: &StackLabel) -> bool {
self == other.text
}
}
impl PartialEq<StackLabel> for &str {
fn eq(&self, other: &StackLabel) -> bool {
*self == other.text
}
}
impl From<StackLabel> for Cow<'static, str> {
fn from(label: StackLabel) -> Self {
label.text
}
}
impl From<StackLabel> for String {
fn from(label: StackLabel) -> Self {
label.text.into_owned()
}
}
#[derive(Debug, Clone, Copy, Default)]
#[non_exhaustive]
pub struct ProjectInput<'a> {
pub(crate) cwd: Option<&'a Path>,
pub(crate) exe: Option<&'a Path>,
pub(crate) cmd: &'a [OsString],
}
impl<'a> ProjectInput<'a> {
#[must_use]
pub const fn new() -> Self {
Self {
cwd: None,
exe: None,
cmd: &[],
}
}
#[must_use]
pub fn cwd(mut self, cwd: impl Into<Option<&'a Path>>) -> Self {
self.cwd = cwd.into();
self
}
#[must_use]
pub fn exe(mut self, exe: impl Into<Option<&'a Path>>) -> Self {
self.exe = exe.into();
self
}
#[must_use]
pub const fn cmd(mut self, cmd: &'a [OsString]) -> Self {
self.cmd = cmd;
self
}
}
#[derive(Debug, Clone, Copy, Default)]
#[non_exhaustive]
pub struct StackInput<'a> {
pub(crate) image: Option<&'a str>,
pub(crate) project_root: Option<&'a Path>,
pub(crate) process_name: &'a str,
pub(crate) exe_name: Option<&'a str>,
pub(crate) exe_path: Option<&'a Path>,
}
impl<'a> StackInput<'a> {
#[must_use]
pub const fn new(process_name: &'a str) -> Self {
Self {
image: None,
project_root: None,
process_name,
exe_name: None,
exe_path: None,
}
}
#[must_use]
pub fn image(mut self, image: impl Into<Option<&'a str>>) -> Self {
self.image = image.into();
self
}
#[must_use]
pub fn project_root(mut self, project_root: impl Into<Option<&'a Path>>) -> Self {
self.project_root = project_root.into();
self
}
#[must_use]
pub fn exe_name(mut self, exe_name: impl Into<Option<&'a str>>) -> Self {
self.exe_name = exe_name.into();
self
}
#[must_use]
pub fn exe_path(mut self, exe_path: impl Into<Option<&'a Path>>) -> Self {
self.exe_path = exe_path.into();
self
}
}