std: Modernize the local_data api

This commit brings the local_data api up to modern rust standards with a few key
improvements:

* The `pop` and `set` methods have been combined into one method, `replace`

* The `get_mut` method has been removed. All interior mutability should be done
  through `RefCell`.

* All functionality is now exposed as a method on the keys themselves. Instead
  of importing std::local_data, you now use "key.replace()" and "key.get()".

* All closures have been removed in favor of RAII functionality. This means that
  get() and get_mut() no long require closures, but rather return
  Option<SmartPointer> where the smart pointer takes care of relinquishing the
  borrow and also implements the necessary Deref traits

* The modify() function was removed to cut the local_data interface down to its
  bare essentials (similarly to how RefCell removed set/get).

[breaking-change]
This commit is contained in:
Alex Crichton
2014-04-28 20:36:08 -07:00
parent ef6daf9935
commit ab92ea526d
23 changed files with 444 additions and 661 deletions

View File

@@ -28,7 +28,6 @@ extern crate time;
extern crate log;
extern crate libc;
use std::local_data;
use std::io;
use std::io::{File, MemWriter};
use std::str;
@@ -276,7 +275,7 @@ fn rust_input(cratefile: &str, matches: &getopts::Matches) -> Output {
&cr)
}).unwrap();
info!("finished with rustc");
local_data::set(analysiskey, analysis);
analysiskey.replace(Some(analysis));
// Process all of the crate attributes, extracting plugin metadata along
// with the passes which we are supposed to run.