use std::io::IoError;
use syntax::ast;
-pub struct RPathConfig<'a> {
+pub struct RPathConfig<F, G> where
+ F: FnOnce() -> Path,
+ G: FnMut(&Path) -> Result<Path, IoError>,
+{
pub used_crates: Vec<(ast::CrateNum, Option<Path>)>,
pub out_filename: Path,
pub is_like_osx: bool,
pub has_rpath: bool,
- pub get_install_prefix_lib_path: ||:'a -> Path,
- pub realpath: |&Path|:'a -> Result<Path, IoError>
+ pub get_install_prefix_lib_path: F,
+ pub realpath: G,
}
-pub fn get_rpath_flags(config: RPathConfig) -> Vec<String> {
-
+pub fn get_rpath_flags<F, G>(config: RPathConfig<F, G>) -> Vec<String> where
+ F: FnOnce() -> Path,
+ G: FnMut(&Path) -> Result<Path, IoError>,
+{
// No rpath on windows
if !config.has_rpath {
return Vec::new();
return ret;
}
-fn get_rpaths(mut config: RPathConfig,
- libs: &[Path]) -> Vec<String> {
+fn get_rpaths<F, G>(mut config: RPathConfig<F, G>, libs: &[Path]) -> Vec<String> where
+ F: FnOnce() -> Path,
+ G: FnMut(&Path) -> Result<Path, IoError>,
+{
debug!("output: {}", config.out_filename.display());
debug!("libs:");
for libpath in libs.iter() {
return rpaths;
}
-fn get_rpaths_relative_to_output(config: &mut RPathConfig,
- libs: &[Path]) -> Vec<String> {
+fn get_rpaths_relative_to_output<F, G>(config: &mut RPathConfig<F, G>,
+ libs: &[Path]) -> Vec<String> where
+ F: FnOnce() -> Path,
+ G: FnMut(&Path) -> Result<Path, IoError>,
+{
libs.iter().map(|a| get_rpath_relative_to_output(config, a)).collect()
}
-fn get_rpath_relative_to_output(config: &mut RPathConfig,
- lib: &Path) -> String {
+fn get_rpath_relative_to_output<F, G>(config: &mut RPathConfig<F, G>, lib: &Path) -> String where
+ F: FnOnce() -> Path,
+ G: FnMut(&Path) -> Result<Path, IoError>,
+{
use std::os;
// Mac doesn't appear to support $ORIGIN
relative.as_str().expect("non-utf8 component in path"))
}
-fn get_install_prefix_rpath(config: RPathConfig) -> String {
+fn get_install_prefix_rpath<F, G>(config: RPathConfig<F, G>) -> String where
+ F: FnOnce() -> Path,
+ G: FnMut(&Path) -> Result<Path, IoError>,
+{
let path = (config.get_install_prefix_lib_path)();
let path = os::make_absolute(&path).unwrap();
// FIXME (#9639): This needs to handle non-utf8 paths
trait FixedBuffer {
/// Input a vector of bytes. If the buffer becomes full, process it with the provided
/// function and then clear the buffer.
- fn input(&mut self, input: &[u8], func: |&[u8]|);
+ fn input<F>(&mut self, input: &[u8], func: F) where
+ F: FnMut(&[u8]);
/// Reset the buffer.
fn reset(&mut self);
}
impl FixedBuffer for FixedBuffer64 {
- fn input(&mut self, input: &[u8], func: |&[u8]|) {
+ fn input<F>(&mut self, input: &[u8], mut func: F) where
+ F: FnMut(&[u8]),
+ {
let mut i = 0;
let size = self.size();
/// guaranteed to have exactly rem remaining bytes when it returns. If there are not at least
/// rem bytes available, the buffer will be zero padded, processed, cleared, and then filled
/// with zeros again until only rem bytes are remaining.
- fn standard_padding(&mut self, rem: uint, func: |&[u8]|);
+ fn standard_padding<F>(&mut self, rem: uint, func: F) where F: FnMut(&[u8]);
}
impl <T: FixedBuffer> StandardPadding for T {
- fn standard_padding(&mut self, rem: uint, func: |&[u8]|) {
+ fn standard_padding<F>(&mut self, rem: uint, mut func: F) where F: FnMut(&[u8]) {
let size = self.size();
self.next(1)[0] = 128;