What is the difference between a __weak and a __block reference?

From the docs about __block __block variables live in storage that is shared between the lexical scope of the variable and all blocks and block copies declared or created within the variable’s lexical scope. Thus, the storage will survive the destruction of the stack frame if any copies of the blocks declared within the frame … Read more

How to keep git from changing file ownership

If it suffices to preserve the group, you can set the setgid flag on the directories. See http://en.wikipedia.org/wiki/Setuid Setting the setgid permission on a directory (“chmod g+s”) causes new files and subdirectories created within it to inherit its group ID, rather than the primary group ID of the user who created the file (the owner … Read more

Type mismatches resolving a closure that takes arguments by reference

The short version is that there’s a difference between the lifetimes that are inferred if the closure is written inline or stored as a variable. Write the closure inline and remove all the extraneous types: fn test(points: &[Point]) -> (&Point, f32) { let init = points.first().expect(“No initial”); fold(&points, (init, 0.), |(q, max_d), p| { let … Read more

Convert Vec into a slice of &str in Rust?

You can create a function that accepts both &[String] and &[&str] using the AsRef trait: fn test<T: AsRef<str>>(inp: &[T]) { for x in inp { print!(“{} “, x.as_ref()) } println!(“”); } fn main() { let vref = vec![“Hello”, “world!”]; let vown = vec![“May the Force”.to_owned(), “be with you.”.to_owned()]; test(&vref); test(&vown); }