-
Notifications
You must be signed in to change notification settings - Fork 13
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
Showing
2 changed files
with
50 additions
and
1 deletion.
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,46 @@ | ||
extern crate ambassador; | ||
|
||
use ambassador::{delegatable_trait, Delegate}; | ||
|
||
trait StaticFn { | ||
fn call() -> bool; | ||
} | ||
|
||
struct StaticTrue; | ||
struct StaticFalse; | ||
|
||
impl StaticFn for StaticTrue { | ||
fn call() -> bool { | ||
true | ||
} | ||
} | ||
|
||
impl StaticFn for StaticFalse { | ||
fn call() -> bool { | ||
false | ||
} | ||
} | ||
|
||
#[delegatable_trait] | ||
pub trait StaticCall { | ||
fn call<C: StaticFn>(&self) -> bool; | ||
} | ||
|
||
pub struct BaseCaller; | ||
|
||
impl StaticCall for BaseCaller { | ||
fn call<C: StaticFn>(&self) -> bool { | ||
C::call() | ||
} | ||
} | ||
|
||
#[derive(Delegate)] | ||
#[delegate(StaticCall)] | ||
pub struct WrappedCaller(BaseCaller); | ||
|
||
fn main() { | ||
let c = WrappedCaller(BaseCaller); | ||
// Verify that the generic type is correctly passed through without relying on type inference. | ||
assert!(c.call::<StaticTrue>()); | ||
assert!(!c.call::<StaticFalse>()); | ||
} |