pub trait Output: std::fmt::Debug {
fn family(&self) -> &'static str;
fn get_declared_dependencies(&self) -> Vec<String>;
}
#[derive(Debug)]
pub struct BinaryOutput(pub String);
impl BinaryOutput {
pub fn new(name: &str) -> Self {
BinaryOutput(name.to_owned())
}
}
impl Output for BinaryOutput {
fn family(&self) -> &'static str {
"binary"
}
fn get_declared_dependencies(&self) -> Vec<String> {
vec![]
}
}
#[derive(Debug)]
pub struct PythonPackageOutput {
pub name: String,
pub version: Option<String>,
}
impl PythonPackageOutput {
pub fn new(name: &str, version: Option<&str>) -> Self {
PythonPackageOutput {
name: name.to_owned(),
version: version.map(|s| s.to_owned()),
}
}
}
impl Output for PythonPackageOutput {
fn family(&self) -> &'static str {
"python-package"
}
fn get_declared_dependencies(&self) -> Vec<String> {
vec![]
}
}
#[derive(Debug)]
pub struct PythonExtensionOutput {
pub name: String,
}
impl PythonExtensionOutput {
pub fn new(name: &str) -> Self {
PythonExtensionOutput {
name: name.to_owned(),
}
}
}
impl Output for PythonExtensionOutput {
fn family(&self) -> &'static str {
"python-extension"
}
fn get_declared_dependencies(&self) -> Vec<String> {
vec![]
}
}
#[derive(Debug)]
pub struct RPackageOutput {
pub name: String,
}
impl RPackageOutput {
pub fn new(name: &str) -> Self {
RPackageOutput {
name: name.to_owned(),
}
}
}
impl Output for RPackageOutput {
fn family(&self) -> &'static str {
"r-package"
}
fn get_declared_dependencies(&self) -> Vec<String> {
vec![]
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_binary_output() {
let output = BinaryOutput::new("mybin");
assert_eq!(output.0, "mybin");
assert_eq!(output.family(), "binary");
assert_eq!(output.get_declared_dependencies(), Vec::<String>::new());
}
#[test]
fn test_python_package_output() {
let output = PythonPackageOutput::new("requests", Some("2.0"));
assert_eq!(output.name, "requests");
assert_eq!(output.version.as_deref(), Some("2.0"));
assert_eq!(output.family(), "python-package");
assert_eq!(output.get_declared_dependencies(), Vec::<String>::new());
}
#[test]
fn test_python_package_output_without_version() {
let output = PythonPackageOutput::new("requests", None);
assert_eq!(output.version, None);
}
#[test]
fn test_r_package_output() {
let output = RPackageOutput::new("ggplot2");
assert_eq!(output.name, "ggplot2");
assert_eq!(output.family(), "r-package");
assert_eq!(output.get_declared_dependencies(), Vec::<String>::new());
}
}