Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
Merge pull request #59 from gavofyork/gav
Browse files Browse the repository at this point in the history
Assign-operators for Uint.
  • Loading branch information
arkpar committed Jan 16, 2016
2 parents 9d75452 + 0c2869d commit a04d5c2
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![feature(op_assign_traits)]
#![feature(augmented_assignments)]
#![feature(associated_consts)]
#![feature(wrapping)]
//! Ethcore-util library
Expand Down
2 changes: 1 addition & 1 deletion src/network/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ impl<Message> IoHandler<NetworkIoMessage<Message>> for Host<Message> where Messa
self.add_node("enode://de471bccee3d042261d52e9bff31458daecc406142b401d4cd848f677479f73104b9fdeb090af9583d3391b7f10cb2ba9e26865dd5fca4fcdc0fb1e3b723c786@54.94.239.50:30303"); // BR
self.add_node("enode://1118980bf48b0a3640bdba04e0fe78b1add18e1cd99bf22d53daac1fd9972ad650df52176e7c7d89d1114cfef2bc23a2959aa54998a46afcf7d91809f0855082@52.74.57.123:30303"); // SG
// ETH/DEV cpp-ethereum (poc-9.ethdev.com)
self.add_node("enode://979b7fa28feeb35a4741660a16076f1943202cb72b6af70d327f053e248bab9ba81760f39d0701ef1d8f89cc1fbd2cacba0710a12cd5314d5e0c9021aa3637f9@5.1.83.226:30303");
self.add_node("enode://979b7fa28feeb35a4741660a16076f1943202cb72b6af70d327f053e248bab9ba81760f39d0701ef1d8f89cc1fbd2cacba0710a12cd5314d5e0c9021aa3637f9@5.1.83.226:30303");
}

fn stream_hup<'s>(&'s mut self, io: &mut IoContext<'s, NetworkIoMessage<Message>>, stream: StreamToken) {
Expand Down
2 changes: 0 additions & 2 deletions src/tinykeccak.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

/** libkeccak-tiny
Expand Down
93 changes: 93 additions & 0 deletions src/uint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,68 @@ macro_rules! construct_uint {
}
}

// TODO: optimise and traitify.

impl<'a> AddAssign<&'a $name> for $name {
fn add_assign(&mut self, other: &'a Self) {
*self = self.add(*other);
}
}

impl<'a> SubAssign<&'a $name> for $name {
fn sub_assign(&mut self, other: &'a Self) {
*self = self.sub(*other);
}
}

impl<'a> MulAssign<&'a $name> for $name {
fn mul_assign(&mut self, other: &'a Self) {
*self = self.mul(*other);
}
}

impl<'a> DivAssign<&'a $name> for $name {
fn div_assign(&mut self, other: &'a Self) {
*self = self.div(*other);
}
}

impl<'a> RemAssign<&'a $name> for $name {
fn rem_assign(&mut self, other: &'a Self) {
*self = self.rem(*other);
}
}

impl AddAssign<$name> for $name {
fn add_assign(&mut self, other: Self) {
*self = self.add(other);
}
}

impl SubAssign<$name> for $name {
fn sub_assign(&mut self, other: Self) {
*self = self.sub(other);
}
}

impl MulAssign<$name> for $name {
fn mul_assign(&mut self, other: Self) {
*self = self.mul(other);
}
}

impl DivAssign<$name> for $name {
fn div_assign(&mut self, other: Self) {
*self = self.div(other);
}
}

impl RemAssign<$name> for $name {
fn rem_assign(&mut self, other: Self) {
*self = self.rem(other);
}
}

impl BitAnd<$name> for $name {
type Output = $name;

Expand Down Expand Up @@ -855,6 +917,37 @@ mod tests {
use std::str::FromStr;
use std::num::wrapping::OverflowingOps;

#[test]
pub fn assign_ops() {
let x: U256 = x!(69);
let y: U256 = x!(42);
{
let mut z = x;
z += y;
assert_eq!(z, x + y);
}
{
let mut z = x;
z -= y;
assert_eq!(z, x - y);
}
{
let mut z = x;
z *= y;
assert_eq!(z, x * y);
}
{
let mut z = x;
z /= y;
assert_eq!(z, x / y);
}
{
let mut z = x;
z %= y;
assert_eq!(z, x % y);
}
}

#[test]
pub fn uint256_from() {
let e = U256([10, 0, 0, 0]);
Expand Down

0 comments on commit a04d5c2

Please sign in to comment.