diff --git a/src/lib.rs b/src/lib.rs index 05b93ee..9a6461e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -34,9 +34,10 @@ mod unit_integration_tests; mod temp; mod type_; mod trait_simple_vs_enum; -mod trait_when_to_use_dyn_dispatch; -mod trait_object_vs_struct_obj; +mod traits_when_to_use_dyn_dispatch; +mod traits_object_vs_struct_obj; mod traits; +mod traits_associated_constants; mod traits_associated_type_vs_generics; mod traits_default_type_parameter; mod traits_return_impl; // todo: incomplete diff --git a/src/traits_associated_constants.rs b/src/traits_associated_constants.rs new file mode 100644 index 0000000..ba2a3bf --- /dev/null +++ b/src/traits_associated_constants.rs @@ -0,0 +1,18 @@ +// https://doc.rust-lang.org/reference/items/associated-items.html#associated-constants + +trait MyTrait { + const MY_CONST: u8; // Associated Constant + fn bar(); +} + +struct Foo; + +impl MyTrait for Foo { + const MY_CONST: u8 = 42; + fn bar() {} +} + +#[test] +fn ex1() { + assert_eq!(Foo::MY_CONST, 42); +} diff --git a/src/trait_object_vs_struct_obj.rs b/src/traits_object_vs_struct_obj.rs similarity index 100% rename from src/trait_object_vs_struct_obj.rs rename to src/traits_object_vs_struct_obj.rs diff --git a/src/trait_when_to_use_dyn_dispatch.rs b/src/traits_when_to_use_dyn_dispatch.rs similarity index 100% rename from src/trait_when_to_use_dyn_dispatch.rs rename to src/traits_when_to_use_dyn_dispatch.rs