Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use process Macro to realize tail Recursive Optimization ability in Rust

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article will explain in detail how to use process macros in Rust to achieve tail recursive optimization, the content of the article is of high quality, so the editor shares it for you to do a reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.

Release: RustCrypto: p256 and k256 v0.2.0: pure Rust NIST Pmur256 and secp256k1 curve algorithm

This version implements the following two curve algorithms in Rust. P256: NIST Pmur256

□ GitHub: https://github.com/RustCrypto/elliptic-curves/tree/master/p256

□ crates.io: https://crates.io/crates/p256

□ docs.rs: https://docs.rs/p256/

K256: secp256k1 (as used by Bitcoin, Ethereum, etc) □ GitHub: https://github.com/RustCrypto/elliptic-curves/tree/master/k256

□ crates.io: https://crates.io/crates/k256

□ docs.rs: https://docs.rs/k256/

Tco: the idea of tail recursive optimization with procedure macros is very strange-using attribute macros to optimize tail recursive calls. It looks like this: # [tco::rewrite] fn fac_with_acc (n: U128, acc: U128)-> u128 {if n > 1 {fac_with_acc (n-1, acc * n)} else {acc}} the optimized code is: fn fac_with_acc (n: U128, acc: U128)-> u128 {let mut n = n; let mut acc = acc '_ _ tco_loop: loop {return {if n > 1 {{let _ tco_0 = (n-1, acc * n); n = _ _ tco_0.0; acc = _ _ tco_0.1; continue' _ tco_loop }} else {acc};}}

On how to use process macros in Rust to achieve the tail recursive optimization ability is shared here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report