*/
#[repr(u8)]
pub enum c_void {
- priv variant1,
- priv variant2
+ __variant1,
+ __variant2,
}
pub enum FILE {}
pub enum fpos_t {}
/// for Generating Gamma Variables" *ACM Trans. Math. Softw.* 26, 3
/// (September 2000),
/// 363-372. DOI:[10.1145/358407.358414](http://doi.acm.org/10.1145/358407.358414)
-pub enum Gamma {
- priv Large(GammaLargeShape),
- priv One(Exp),
- priv Small(GammaSmallShape)
+pub struct Gamma {
+ repr: GammaRepr,
+}
+
+enum GammaRepr {
+ Large(GammaLargeShape),
+ One(Exp),
+ Small(GammaSmallShape)
}
// These two helpers could be made public, but saving the
assert!(shape > 0.0, "Gamma::new called with shape <= 0");
assert!(scale > 0.0, "Gamma::new called with scale <= 0");
- match shape {
+ let repr = match shape {
1.0 => One(Exp::new(1.0 / scale)),
0.0 .. 1.0 => Small(GammaSmallShape::new_raw(shape, scale)),
_ => Large(GammaLargeShape::new_raw(shape, scale))
- }
+ };
+ Gamma { repr: repr }
}
}
impl IndependentSample<f64> for Gamma {
fn ind_sample<R: Rng>(&self, rng: &mut R) -> f64 {
- match *self {
+ match self.repr {
Small(ref g) => g.ind_sample(rng),
One(ref g) => g.ind_sample(rng),
Large(ref g) => g.ind_sample(rng),
/// let v = chi.ind_sample(&mut rand::task_rng());
/// println!("{} is from a χ²(11) distribution", v)
/// ```
-pub enum ChiSquared {
+pub struct ChiSquared {
+ repr: ChiSquaredRepr,
+}
+
+enum ChiSquaredRepr {
// k == 1, Gamma(alpha, ..) is particularly slow for alpha < 1,
// e.g. when alpha = 1/2 as it would be for this case, so special-
// casing and using the definition of N(0,1)^2 is faster.
- priv DoFExactlyOne,
- priv DoFAnythingElse(Gamma)
+ DoFExactlyOne,
+ DoFAnythingElse(Gamma),
}
impl ChiSquared {
/// Create a new chi-squared distribution with degrees-of-freedom
/// `k`. Fails if `k < 0`.
pub fn new(k: f64) -> ChiSquared {
- if k == 1.0 {
+ let repr = if k == 1.0 {
DoFExactlyOne
} else {
assert!(k > 0.0, "ChiSquared::new called with `k` < 0");
DoFAnythingElse(Gamma::new(0.5 * k, 2.0))
- }
+ };
+ ChiSquared { repr: repr }
}
}
impl Sample<f64> for ChiSquared {
}
impl IndependentSample<f64> for ChiSquared {
fn ind_sample<R: Rng>(&self, rng: &mut R) -> f64 {
- match *self {
+ match self.repr {
DoFExactlyOne => {
// k == 1 => N(0,1)^2
let StandardNormal(norm) = rng.gen::<StandardNormal>();
}
}
-pub enum FunctionDebugContext {
- priv FunctionDebugContext(~FunctionDebugContextData),
- priv DebugInfoDisabled,
- priv FunctionWithoutDebugInfo,
+pub struct FunctionDebugContext {
+ repr: FunctionDebugContextRepr,
+}
+
+enum FunctionDebugContextRepr {
+ FunctionDebugContext(~FunctionDebugContextData),
+ DebugInfoDisabled,
+ FunctionWithoutDebugInfo,
}
impl FunctionDebugContext {
fn get_ref<'a>(&'a self, cx: &CrateContext, span: Span) -> &'a FunctionDebugContextData {
- match *self {
+ match self.repr {
FunctionDebugContext(~ref data) => data,
DebugInfoDisabled => {
cx.sess().span_bug(span, FunctionDebugContext::debuginfo_disabled_message());
pub fn set_source_location(fcx: &FunctionContext,
node_id: ast::NodeId,
span: Span) {
- match fcx.debug_context {
+ match fcx.debug_context.repr {
DebugInfoDisabled => return,
FunctionWithoutDebugInfo => {
set_debug_location(fcx.ccx, UnknownLocation);
/// and must therefore be called before the first real statement/expression of the function is
/// translated.
pub fn start_emitting_source_locations(fcx: &FunctionContext) {
- match fcx.debug_context {
+ match fcx.debug_context.repr {
FunctionDebugContext(~ref data) => {
data.source_locations_enabled.set(true)
},
param_substs: Option<@param_substs>,
llfn: ValueRef) -> FunctionDebugContext {
if cx.sess().opts.debuginfo == NoDebugInfo {
- return DebugInfoDisabled;
+ return FunctionDebugContext { repr: DebugInfoDisabled };
}
// Clear the debug location so we don't assign them in the function prelude. Do this here
set_debug_location(cx, UnknownLocation);
if fn_ast_id == -1 {
- return FunctionWithoutDebugInfo;
+ return FunctionDebugContext { repr: FunctionWithoutDebugInfo };
}
let empty_generics = ast::Generics { lifetimes: Vec::new(), ty_params: OwnedSlice::empty() };
ast_map::NodeForeignItem(..) |
ast_map::NodeVariant(..) |
ast_map::NodeStructCtor(..) => {
- return FunctionWithoutDebugInfo;
+ return FunctionDebugContext { repr: FunctionWithoutDebugInfo };
}
_ => cx.sess().bug(format!("create_function_debug_context: \
unexpected sort of node: {:?}", fnitem))
// This can be the case for functions inlined from another crate
if span == codemap::DUMMY_SP {
- return FunctionWithoutDebugInfo;
+ return FunctionDebugContext { repr: FunctionWithoutDebugInfo };
}
let loc = span_start(cx, span);
fn_metadata,
&mut *fn_debug_context.scope_map.borrow_mut());
- return FunctionDebugContext(fn_debug_context);
+ return FunctionDebugContext { repr: FunctionDebugContext(fn_debug_context) };
fn get_function_signature(cx: &CrateContext,
fn_ast_id: ast::NodeId,
}
fn fn_should_be_ignored(fcx: &FunctionContext) -> bool {
- match fcx.debug_context {
+ match fcx.debug_context.repr {
FunctionDebugContext(_) => false,
_ => true
}
use std::vec;
/// A vector type optimized for cases where the size is almost always 0 or 1
-pub enum SmallVector<T> {
- priv Zero,
- priv One(T),
- priv Many(Vec<T> ),
+pub struct SmallVector<T> {
+ repr: SmallVectorRepr<T>,
+}
+
+enum SmallVectorRepr<T> {
+ Zero,
+ One(T),
+ Many(Vec<T> ),
}
impl<T> Container for SmallVector<T> {
fn len(&self) -> uint {
- match *self {
+ match self.repr {
Zero => 0,
One(..) => 1,
Many(ref vals) => vals.len()
impl<T> FromIterator<T> for SmallVector<T> {
fn from_iter<I: Iterator<T>>(iter: I) -> SmallVector<T> {
- let mut v = Zero;
+ let mut v = SmallVector::zero();
v.extend(iter);
v
}
impl<T> SmallVector<T> {
pub fn zero() -> SmallVector<T> {
- Zero
+ SmallVector { repr: Zero }
}
pub fn one(v: T) -> SmallVector<T> {
- One(v)
+ SmallVector { repr: One(v) }
}
- pub fn many(vs: Vec<T> ) -> SmallVector<T> {
- Many(vs)
+ pub fn many(vs: Vec<T>) -> SmallVector<T> {
+ SmallVector { repr: Many(vs) }
}
pub fn push(&mut self, v: T) {
- match *self {
- Zero => *self = One(v),
+ match self.repr {
+ Zero => self.repr = One(v),
One(..) => {
- let one = mem::replace(self, Zero);
+ let one = mem::replace(&mut self.repr, Zero);
match one {
- One(v1) => mem::replace(self, Many(vec!(v1, v))),
+ One(v1) => mem::replace(&mut self.repr, Many(vec!(v1, v))),
_ => unreachable!()
};
}
}
pub fn get<'a>(&'a self, idx: uint) -> &'a T {
- match *self {
+ match self.repr {
One(ref v) if idx == 0 => v,
Many(ref vs) => vs.get(idx),
_ => fail!("out of bounds access")
}
pub fn expect_one(self, err: &'static str) -> T {
- match self {
+ match self.repr {
One(v) => v,
Many(v) => {
if v.len() == 1 {
}
pub fn move_iter(self) -> MoveItems<T> {
- match self {
+ let repr = match self.repr {
Zero => ZeroIterator,
One(v) => OneIterator(v),
Many(vs) => ManyIterator(vs.move_iter())
- }
+ };
+ MoveItems { repr: repr }
}
}
-pub enum MoveItems<T> {
- priv ZeroIterator,
- priv OneIterator(T),
- priv ManyIterator(vec::MoveItems<T>),
+pub struct MoveItems<T> {
+ repr: MoveItemsRepr<T>,
+}
+
+enum MoveItemsRepr<T> {
+ ZeroIterator,
+ OneIterator(T),
+ ManyIterator(vec::MoveItems<T>),
}
impl<T> Iterator<T> for MoveItems<T> {
fn next(&mut self) -> Option<T> {
- match *self {
+ match self.repr {
ZeroIterator => None,
OneIterator(..) => {
let mut replacement = ZeroIterator;
- mem::swap(self, &mut replacement);
+ mem::swap(&mut self.repr, &mut replacement);
match replacement {
OneIterator(v) => Some(v),
_ => unreachable!()
}
fn size_hint(&self) -> (uint, Option<uint>) {
- match *self {
+ match self.repr {
ZeroIterator => (0, Some(0)),
OneIterator(..) => (1, Some(1)),
ManyIterator(ref inner) => inner.size_hint()