Skip to content

Commit

Permalink
Adding trait associated-constants
Browse files Browse the repository at this point in the history
  • Loading branch information
simsekgokhan committed Dec 26, 2023
1 parent f933889 commit fcd63ad
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions src/traits_associated_constants.rs
Original file line number Diff line number Diff line change
@@ -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);
}
File renamed without changes.
File renamed without changes.

0 comments on commit fcd63ad

Please sign in to comment.