Skip to content

Instantly share code, notes, and snippets.

@SiegeLord
Last active December 22, 2015 00:49
Show Gist options
  • Select an option

  • Save SiegeLord/6392369 to your computer and use it in GitHub Desktop.

Select an option

Save SiegeLord/6392369 to your computer and use it in GitHub Desktop.
Arbitrary infix operators
fn main()
{
let a = NumType(7) /and/ (NumType(2) /and/ NumType(3));
println!("{}", *a);
}
struct NumType(int);
struct AndHelper
{
lhs: NumType
}
impl Div<AndHelper, AndHelper> for NumType
{
fn div(&self, _: &AndHelper) -> AndHelper
{
AndHelper{lhs: *self}
}
}
impl Div<NumType, NumType> for AndHelper
{
fn div(&self, e: &NumType) -> NumType
{
NumType(*self.lhs & **e)
}
}
static and: AndHelper = AndHelper{lhs: NumType(0)};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment