-
Notifications
You must be signed in to change notification settings - Fork 1
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
not-elm
committed
Jul 1, 2024
1 parent
da7ecfe
commit 3300a14
Showing
11 changed files
with
219 additions
and
50 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
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
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
|
||
pub mod functions; | ||
pub mod fn_meta; | ||
|
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
impl/src/trait_item/functions.rs → impl/src/trait_meta/functions.rs
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,14 @@ | ||
#![allow(unused)] | ||
|
||
mod test01_associated_type; | ||
mod test02_associated_types_with_generics; | ||
mod test03_associated_types_with_lifetimes; | ||
|
||
#[cfg(test)] | ||
#[test] | ||
fn tests() { | ||
let t = trybuild::TestCases::new(); | ||
t.pass("tests/associated_type/test01_associated_type.rs"); | ||
t.pass("tests/associated_type/test02_associated_types_with_generics.rs"); | ||
t.pass("tests/associated_type/test03_associated_types_with_lifetimes.rs"); | ||
} |
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,52 @@ | ||
|
||
use std::ops::Add; | ||
use auto_delegate_impl::{delegate, Delegate}; | ||
|
||
|
||
#[delegate] | ||
trait Calc{ | ||
type Num: Add; | ||
|
||
fn calc(&self, x1: Self::Num, x2: Self::Num) -> Self::Num; | ||
} | ||
|
||
#[delegate] | ||
trait NoBound{ | ||
type Num; | ||
|
||
fn method(); | ||
} | ||
|
||
struct Usize; | ||
|
||
impl Calc for Usize { | ||
type Num = usize; | ||
|
||
fn calc(&self, x1: Self::Num, x2: Self::Num) -> Self::Num { | ||
x1 + x2 | ||
} | ||
} | ||
|
||
struct Isize; | ||
|
||
impl Calc for Isize { | ||
type Num = isize; | ||
|
||
fn calc(&self, x1: Self::Num, x2: Self::Num) -> Self::Num { | ||
x1 + x2 | ||
} | ||
} | ||
|
||
|
||
#[derive(Delegate)] | ||
struct Parent{ | ||
#[to(Calc)] | ||
child: Usize | ||
} | ||
|
||
fn main(){ | ||
let parent = Parent{ | ||
child: Usize | ||
}; | ||
assert_eq!(parent.calc(1, 2), 3); | ||
} |
33 changes: 33 additions & 0 deletions
33
tests/associated_type/test02_associated_types_with_generics.rs
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,33 @@ | ||
|
||
use std::ops::Add; | ||
use auto_delegate_impl::{delegate, Delegate}; | ||
|
||
|
||
#[delegate] | ||
trait Calc<Num: Add>{ | ||
type Out; | ||
|
||
fn calc(&self, x1: Num, x2: Num) -> Self::Out; | ||
} | ||
|
||
struct Usize; | ||
impl Calc<usize> for Usize{ | ||
type Out = u8; | ||
|
||
fn calc(&self, x1: usize, x2: usize) -> Self::Out { | ||
(x1 + x2) as u8 | ||
} | ||
} | ||
|
||
#[derive(Delegate)] | ||
struct Parent{ | ||
#[to(Calc)] | ||
child: Usize | ||
} | ||
|
||
fn main(){ | ||
let parent = Parent{ | ||
child: Usize | ||
}; | ||
assert_eq!(parent.calc(1, 2), 3); | ||
} |
Oops, something went wrong.