Skip to content

Instantly share code, notes, and snippets.

@Leonidas-from-XIV
Created April 13, 2014 17:00
Show Gist options
  • Select an option

  • Save Leonidas-from-XIV/10592610 to your computer and use it in GitHub Desktop.

Select an option

Save Leonidas-from-XIV/10592610 to your computer and use it in GitHub Desktop.
fn write_u64(to: &mut File, items: &Vec<u64>) {
let mut written: Vec<u8> = unsafe { cast::transmute(items) };
let written_len = written.len();
unsafe { written.set_len(written_len * 8)};
match to.write(written.as_slice()) {
Ok(_) => (),
Err(e) => fail!("writing failed: {}", e),
};
}
@Leonidas-from-XIV

Copy link
Copy Markdown
Author
sort.rs:30:12: 30:17 error: `files` does not live long enough
sort.rs:30      for f in files.mut_iter() {
                         ^~~~~
sort.rs:28:51: 39:3 note: reference must be valid for the anonymous lifetime #1 defined on the block at 28:50...
sort.rs:28  pub fn new(mut files: Vec<File>) -> PriorityFile {
sort.rs:29      let mut queue: PriorityQueue<Entry> = PriorityQueue::new();
sort.rs:30      for f in files.mut_iter() {
sort.rs:31          let number = match f.read_le_u64() {
sort.rs:32              Ok(num) => num,
sort.rs:33              Err(e) => fail!("failed to read u64 from file: {}", e),
           ...
sort.rs:28:51: 39:3 note: ...but borrowed value is only valid for the block at 28:50
sort.rs:28  pub fn new(mut files: Vec<File>) -> PriorityFile {
sort.rs:29      let mut queue: PriorityQueue<Entry> = PriorityQueue::new();
sort.rs:30      for f in files.mut_iter() {
sort.rs:31          let number = match f.read_le_u64() {
sort.rs:32              Ok(num) => num,
sort.rs:33              Err(e) => fail!("failed to read u64 from file: {}", e),

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment