Created
September 28, 2015 20:19
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum Option<T> { | |
None, | |
Some(T) | |
} | |
// desugars to | |
enum Option<T> { | |
None {..}, | |
Some {..} | |
} | |
struct Option<T>::None; | |
struct Option<T>::Some(T); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum Mode { | |
enum ByRef { | |
Mutable, | |
Immutable | |
} | |
ByValue | |
} | |
// desugars to | |
enum Mode { | |
enum ByRef {..} | |
ByValue {..} | |
} | |
enum Mode::ByRef { | |
Mutable {..}, | |
Immutable {..} | |
} | |
struct Mode::ByValue; | |
struct Mode::ByRef::Mutable; | |
struct Mode::ByRef::Immutable; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Ty<'tcx> = &'tcx TypeData<'tcx>; | |
enum TypeData<'tcx> { | |
// Common fields: | |
id: u32, | |
flags: u32, | |
..., | |
// Variants: | |
Int { }, | |
Uint { }, | |
Ref { referent_ty: Ty<'tcx> }, | |
... | |
} | |
// desugars to | |
enum TypeData<'tcx> { | |
// Common fields: | |
id: u32, | |
flags: u32, | |
..., | |
// Variants: | |
Int {..}, | |
Uint {..}, | |
Ref {..}, | |
... | |
} | |
struct TypeData<'tcx>::Int {} | |
struct TypeData<'tcx>::Uint {} | |
struct TypeData<'tcx>::Ref { | |
referent_ty: Ty<'tcx> | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Ty<'tcx> = &'tcx TypeData<'tcx>; | |
enum TypeData<'tcx> { | |
..., | |
// No indirection anymore. What's more, the type `FnPointer` | |
// serves as a refinement type automatically. | |
FnPointer { | |
unsafety: Unsafety, | |
abi: Abi, | |
signature: Signature, | |
} | |
} | |
// This prevents mutation of the tag after "unsizing" from | |
// variant to enum type (&TypeData::FnPointer -> &TypeData), | |
// so the size of each variant can be smaller than the enum. | |
// It also may allow individual variants to be unsized, but | |
// that could be odd to deal with. | |
impl !Sized for TypeData {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum Node { | |
// where this node is positioned after layout | |
position: Rectangle, | |
... | |
enum Element {..} | |
} | |
impl !Sized for Node {} | |
enum Node::Element { | |
... | |
// These could be simply named Text and Paragraph. | |
TextElement {..}, | |
ParagraphElement {..} | |
} | |
struct Node::Element::TextElement { | |
... | |
} | |
struct Node::Element::ParagraphElement { | |
... | |
} | |
// Alternatively, T: Unsize<Node> could be used. | |
fn intersects<T: VariantOf<Node>>(box: Rectangle, elements: &[Rc<T>]) -> Vec<Rc<T>> { | |
... | |
} | |
trait TextAPIs: VariantOf<HTMLElement> { | |
fn maxLength(&self) -> usize; | |
.. | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment