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

Refactoring as per review #384

Merged
merged 1 commit into from
Mar 21, 2022
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
2 changes: 1 addition & 1 deletion fj-host/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ impl Model {
let src_path = path.join("src");

let lib_path = {
let file = HostPlatform::host_file_name(&name);
let file = HostPlatform::lib_file_name(&name);
let target_dir = target_dir.unwrap_or_else(|| path.join("target"));
target_dir.join("debug").join(file)
};
Expand Down
27 changes: 16 additions & 11 deletions fj-host/src/platform.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Represents platform trait
trait Platform {
fn file_name(name: &str) -> String;
pub trait Platform {
fn model_lib_file_name(&self, name: &str) -> String;
}

// Represents all platforms supported
// Represents all supported platforms

// Mac OS
struct Macos;
Expand All @@ -13,17 +13,19 @@ struct Windows;
struct Unix;

impl Platform for Windows {
fn file_name(name: &str) -> String {
fn model_lib_file_name(&self, name: &str) -> String {
format!("{}.dll", name)
}
}

impl Platform for Macos {
fn file_name(name: &str) -> String {
fn model_lib_file_name(&self, name: &str) -> String {
format!("lib{}.dylib", name)
}
}

impl Platform for Unix {
fn file_name(name: &str) -> String {
fn model_lib_file_name(&self, name: &str) -> String {
format!("lib{}.so", name)
}
}
Expand All @@ -32,14 +34,17 @@ impl Platform for Unix {
pub struct HostPlatform;

impl HostPlatform {
pub fn host_file_name(name: &str) -> String {
pub fn get_os() -> Box<dyn Platform> {
if cfg!(windows) {
Windows::file_name(name)
Box::new(Windows)
} else if cfg!(target_os = "macos") {
Macos::file_name(name)
Box::new(Macos)
} else {
//Unix
Unix::file_name(name)
Box::new(Unix)
}
}

pub fn lib_file_name(name: &str) -> String {
Self::get_os().model_lib_file_name(name)
}
}