pub fn install_dylibs<T: AsRef<Path> + ?Sized>(
    from: &T,
    filter: Option<DyLibNameFilter<'_>>,
    target_dir: Option<&Path>,
) -> io::Result<()> {
    use DyLibNameFilter::*;

    let extension = if let Some(Extension(extension)) = filter {
        ".".to_string() + extension
    } else if let Some(FileName(_)) = filter {
        String::new()
    } else {
        get_dylib_extension().expect("Couldn't detect dylib extension").to_string()
    };

    let target_dir = if let Some(target_dir) = target_dir {
        PathBuf::from(target_dir)
    } else {
        get_target_dir()?
    };

    for entry in fs::read_dir(from)?  {
        let entry_path = entry?.path();
        if let Some(file_name) = entry_path.file_name() {
            if let Some(file_name) = file_name.to_str() {
                let matches = if let Some(FileName(target_fname)) = filter {
                    target_fname == file_name
                } else if let Some(Extension(_)) = filter {
                    file_name.ends_with(extension.as_str())
                } else if let Some(LibName(lib_name)) = filter {
                    file_name == lib_name.to_string() + &extension || file_name == "lib".to_string() + lib_name + &extension
                } else {
                    file_name.ends_with(extension.as_str())
                };

                if matches {
                    fs::copy(entry_path.as_path(), target_dir.join(file_name).as_path())?;
                }
            }
        }
    }
    Ok(())
}
/// Install all dynamic libs from a directory to the target directory.
/// 
/// The `dylib` argument can be used to specify the criteria a file needs to match to be installed (See [DyLibNameFilter](DyLibNameFilter) docs).
/// Default behavior is to install every library with an extension that matches the target platform's dylib extension.
/// `target_dir` can be left empty to attempt to automatically find the target executable directory.
/// 
/// To just install all of the dynamic libraries from a folder, do:
/// 
/// ```
/// # fn run() -> std::io::Result<()> {
/// # let path_to_dylib_folder = std::path::Path::new(".");
/// librarian::install_dylibs(path_to_dylib_folder, None, None)?;
/// // The application should now have all the dynamic libraries in the same folder as the executable
/// # Ok(())
/// # }
/// ```
Install all dynamic libs from a directory to the target directory.
The `dylib` argument can be used to specify the criteria a file needs to match to be installed (See [DyLibNameFilter](DyLibNameFilter) docs).
Default behavior is to install every library with an extension that matches the target platform's dylib extension.
`target_dir` can be left empty to attempt to automatically find the target executable directory.

To just install all of the dynamic libraries from a folder, do.


Install all dynamic libs from a directory to the target directory . The ` dylib ` argument can be used to specify the criteria a file needs to match to be installed ( See [ DyLibNameFilter ] ( DyLibNameFilter ) docs ) . Default behavior is to install every library with an extension that matches the target platform ' s dylib extension . ` target_dir ` can be left empty to attempt to automatically find the target executable directory . To just install all of the dynamic libraries from a folder do .
pub fn install_dylibs<T: AsRef<Path> + ?Sized>(
    from: &T,
    filter: Option<DyLibNameFilter<'_>>,
    target_dir: Option<&Path>,
) -> io::Result<()> {
    use DyLibNameFilter::*;
    let extension = if let Some(Extension(extension)) = filter {
        ".".to_string() + extension
    } else if let Some(FileName(_)) = filter {
        String::new()
    } else {
        get_dylib_extension().expect("Couldn't detect dylib extension").to_string()
    };
    let target_dir = if let Some(target_dir) = target_dir {
        PathBuf::from(target_dir)
    } else {
        get_target_dir()?
    };
    for entry in fs::read_dir(from)?  {
        let entry_path = entry?.path();
        if let Some(file_name) = entry_path.file_name() {
            if let Some(file_name) = file_name.to_str() {
                let matches = if let Some(FileName(target_fname)) = filter {
                    target_fname == file_name
                } else if let Some(Extension(_)) = filter {
                    file_name.ends_with(extension.as_str())
                } else if let Some(LibName(lib_name)) = filter {
                    file_name == lib_name.to_string() + &extension || file_name == "lib".to_string() + lib_name + &extension
                } else {
                    file_name.ends_with(extension.as_str())
                };
                if matches {
                    fs::copy(entry_path.as_path(), target_dir.join(file_name).as_path())?;
                }
            }
        }
    }
    Ok(())
}
pub fn install_dylibs < T : AsRef < Path > + ? Sized > ( from : & T , filter : Option < DyLibNameFilter < ' _ > > , target_dir : Option < & Path > , ) -> io :: Result < ( ) > { use DyLibNameFilter :: * ; let extension = if let Some ( Extension ( extension ) ) = filter { " " . to_string ( ) + extension } else if let Some ( FileName ( _ ) ) = filter { String :: new ( ) } else { get_dylib_extension ( ) . expect ( " " ) . to_string ( ) } ; let target_dir = if let Some ( target_dir ) = target_dir { PathBuf :: from ( target_dir ) } else { get_target_dir ( ) ? } ; for entry in fs :: read_dir ( from ) ? { let entry_path = entry ? . path ( ) ; if let Some ( file_name ) = entry_path . file_name ( ) { if let Some ( file_name ) = file_name . to_str ( ) { let matches = if let Some ( FileName ( target_fname ) ) = filter { target_fname == file_name } else if let Some ( Extension ( _ ) ) = filter { file_name . ends_with ( extension . as_str ( ) ) } else if let Some ( LibName ( lib_name ) ) = filter { file_name == lib_name . to_string ( ) + & extension || file_name == " " . to_string ( ) + lib_name + & extension } else { file_name . ends_with ( extension . as_str ( ) ) } ; if matches { fs :: copy ( entry_path . as_path ( ) , target_dir . join ( file_name ) . as_path ( ) ) ? ; } } } } Ok ( ( ) ) }
Install all dynamic libs from a directory to the target directory.
Install all dynamic libs from a directory to the target directory .
from
&T
filter
Option<DyLibNameFilter<'_>>
target_dir
Option<&Path>
from
&T
filter
Option<DyLibNameFilter<'_>>
target_dir
Option<&Path>
fn run() -> std::io::result<()> {
None
let path_to_dylib_folder = std::path::path::new(".");
:install_dylibs(path_to_dylib_folder, None, None)?;
The application should now have all the dynamic libraries in the same folder as the executable
: install_dylibs ( path_to_dylib_folder None None ) ? ; The application should now have all the dynamic libraries in the same folder as the executable
ok(())
None
}
None