-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8a20c9c
commit 9668f51
Showing
4 changed files
with
157 additions
and
0 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[package] | ||
name = "union_fields" | ||
version = "0.1.0" | ||
edition = "2018" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
#![allow(dead_code, unused_variables)] | ||
|
||
type TypeAlias = TargetStruct; | ||
|
||
type GenericTypeAlias<T> = T; | ||
|
||
trait TargetTrait {} | ||
|
||
#[derive(Copy, Clone)] | ||
struct TargetStruct; | ||
|
||
impl TargetTrait for TargetStruct {} | ||
|
||
#[derive(Copy, Clone)] | ||
struct GenericTargetStruct<T: Copy + TargetTrait> { | ||
t: T, | ||
} | ||
|
||
#[derive(Copy, Clone)] | ||
enum TargetEnum {} | ||
|
||
impl TargetTrait for TargetEnum {} | ||
|
||
#[derive(Copy, Clone)] | ||
enum GenericTargetEnum<T: Copy + TargetTrait> { | ||
T(T), | ||
} | ||
|
||
#[derive(Copy, Clone)] | ||
union TargetUnion { | ||
dummy: TargetStruct, | ||
} | ||
|
||
impl TargetTrait for TargetUnion {} | ||
|
||
#[derive(Copy, Clone)] | ||
union GenericTargetUnion<T: Copy + TargetTrait> { | ||
t: T, | ||
} | ||
|
||
pub union Union { | ||
// Unit types: | ||
unit_field: (), | ||
// Scalar types: | ||
bool_field: bool, | ||
char_field: char, | ||
int_field: isize, | ||
uint_field: usize, | ||
float_field: f64, | ||
// Str types: | ||
str_field: &'static str, | ||
// Alias types: | ||
type_alias_field: TypeAlias, | ||
// Adt types: | ||
struct_field: TargetStruct, | ||
enum_field: TargetEnum, | ||
union_field: TargetUnion, | ||
// Reference types: | ||
reference_field: &'static TargetStruct, | ||
array_reference_field: &'static [TargetStruct; 2], | ||
// Array types: | ||
array_field: [TargetStruct; 2], | ||
// Slice types: | ||
slice_field: &'static [TargetStruct], | ||
// Pointer types: | ||
const_ptr_field: *const TargetStruct, | ||
mut_ptr_field: *mut TargetStruct, | ||
// Tuple types: | ||
tuple_field: (TargetStruct,), | ||
// Generic alias types: | ||
generic_type_alias_field: GenericTypeAlias<TargetStruct>, | ||
// Generic adt types: | ||
generic_struct_field: GenericTargetStruct<TargetStruct>, | ||
generic_enum_field: GenericTargetEnum<TargetStruct>, | ||
generic_union_field: GenericTargetUnion<TargetStruct>, | ||
// Trait types: | ||
dyn_trait_field: &'static dyn TargetTrait, | ||
// Callable types: | ||
callable_field: fn(TargetStruct) -> TargetStruct, | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
--- | ||
source: tests/generate_graph.rs | ||
expression: output | ||
--- | ||
STDERR: | ||
|
||
STDOUT: | ||
digraph { | ||
|
||
graph [ | ||
label="union_fields", | ||
labelloc=t, | ||
|
||
pad=0.4, | ||
|
||
// Consider rendering the graph using a different layout algorithm, such as: | ||
// [dot, neato, twopi, circo, fdp, sfdp] | ||
layout=neato, | ||
overlap=false, | ||
splines="line", | ||
rankdir=LR, | ||
|
||
fontname="Helvetica", | ||
fontsize="36", | ||
]; | ||
|
||
node [ | ||
fontname="monospace", | ||
fontsize="10", | ||
shape="record", | ||
style="filled", | ||
]; | ||
|
||
edge [ | ||
fontname="monospace", | ||
fontsize="10", | ||
]; | ||
|
||
"union_fields" [label="crate|union_fields", fillcolor="#5397c8"]; // "crate" node | ||
"union_fields::GenericTargetEnum" [label="pub(crate) enum|union_fields::GenericTargetEnum", fillcolor="#f8c04c"]; // "enum" node | ||
"union_fields::GenericTargetStruct" [label="pub(crate) struct|union_fields::GenericTargetStruct", fillcolor="#f8c04c"]; // "struct" node | ||
"union_fields::GenericTargetUnion" [label="pub(crate) union|union_fields::GenericTargetUnion", fillcolor="#f8c04c"]; // "union" node | ||
"union_fields::TargetEnum" [label="pub(crate) enum|union_fields::TargetEnum", fillcolor="#f8c04c"]; // "enum" node | ||
"union_fields::TargetStruct" [label="pub(crate) struct|union_fields::TargetStruct", fillcolor="#f8c04c"]; // "struct" node | ||
"union_fields::TargetTrait" [label="pub(crate) trait|union_fields::TargetTrait", fillcolor="#f8c04c"]; // "trait" node | ||
"union_fields::TargetUnion" [label="pub(crate) union|union_fields::TargetUnion", fillcolor="#f8c04c"]; // "union" node | ||
"union_fields::Union" [label="pub union|union_fields::Union", fillcolor="#81c169"]; // "union" node | ||
|
||
"union_fields" -> "union_fields::GenericTargetEnum" [label="owns", color="#000000", style="solid"] [constraint=true]; // "owns" edge | ||
"union_fields" -> "union_fields::GenericTargetStruct" [label="owns", color="#000000", style="solid"] [constraint=true]; // "owns" edge | ||
"union_fields" -> "union_fields::GenericTargetUnion" [label="owns", color="#000000", style="solid"] [constraint=true]; // "owns" edge | ||
"union_fields" -> "union_fields::TargetEnum" [label="owns", color="#000000", style="solid"] [constraint=true]; // "owns" edge | ||
"union_fields" -> "union_fields::TargetStruct" [label="owns", color="#000000", style="solid"] [constraint=true]; // "owns" edge | ||
"union_fields" -> "union_fields::TargetTrait" [label="owns", color="#000000", style="solid"] [constraint=true]; // "owns" edge | ||
"union_fields" -> "union_fields::TargetUnion" [label="owns", color="#000000", style="solid"] [constraint=true]; // "owns" edge | ||
"union_fields" -> "union_fields::Union" [label="owns", color="#000000", style="solid"] [constraint=true]; // "owns" edge | ||
|
||
} | ||
|