Git Product home page Git Product logo

Comments (6)

ltfschoen avatar ltfschoen commented on July 26, 2024 1

Ok, I made changes to use lifetimes but I think your changes are better. If there's only one parameter for the function then we shouldn't need lifetimes anymore. Here are the changes I was going to make for your reference, they were just straight from the documentation. https://github.com/Drops-of-Diamond/diamond_drops/compare/notary...ltfschoen:notary?expand=1

let mut sid: &mut [u8; 32] = &mut [0; 32]; 
u256_to_bytes32(&self.shard_id, &mut sid);

...

let mut p: &mut [u8; 32] = &mut [0; 32];
u256_to_bytes32(&self.period, &mut p);

...

fn u256_to_bytes32<'a>(u256: &'a ethereum_types::U256, dst: &'a mut [u8; 32]) -> &'a [u8; 32] {
    for i in 0..32 {
        dst[i] = u256.byte(i);
    }
    dst
}

...

let mut sid_bytes: &mut [u8; 32] = &mut [0; 32];
u256_to_bytes32(&sid, &mut sid_bytes);

...

let mut period_bytes: &mut [u8; 32] = &mut [0; 32];
u256_to_bytes32(&period, &mut period_bytes);

from diamond_drops.

jamesray1 avatar jamesray1 commented on July 26, 2024

One improvement that I think it needs is to return dst, and not actually take dst as an input parameter.

from diamond_drops.

ChosunOne avatar ChosunOne commented on July 26, 2024

Yeah, if I can figure out a way to do that with the Rust ownership and lifetime rules I'll change it.

from diamond_drops.

ltfschoen avatar ltfschoen commented on July 26, 2024

Yeh I'll create a PR

Reference: https://doc.rust-lang.org/book/second-edition/ch10-03-lifetime-syntax.html

from diamond_drops.

ChosunOne avatar ChosunOne commented on July 26, 2024

Ok I've just pushed an update to make this return the bytes array instead of requiring two inputs. Further improvements are welcome

from diamond_drops.

jamesray1 avatar jamesray1 commented on July 26, 2024

Looks good now. I'll close this for now.

from diamond_drops.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.