|
|
Subscribe / Log in / New account

size_of and align_of

size_of and align_of

Posted Jul 29, 2024 2:58 UTC (Mon) by NYKevin (subscriber, #129325)
In reply to: size_of and align_of by tialaramex
Parent article: Rust 1.80.0 released

I don't see why. You can just write this:

fn make_small_bigint(value: i64) -> BigNum{
// Do whatever simple logic you need here.
}

// Can also have e.g. make_small_rational(numerator, denominator), etc.

// Global scope:
static OnceLock<BigNum> FOUR = OnceLock::new();

// Callsite:
let four = FOUR.get_or_init(|| make_small_bigint(4));

LazyLock just means you can write let four = *FOUR; instead of let four = FOUR.get_or_init(|| make_small_bigint(4));. You still have to write the function make_small_bigint() either way, because you will need to pass exactly the same lambda to the LazyLock at construction time.


to post comments

size_of and align_of

Posted Aug 1, 2024 15:02 UTC (Thu) by tialaramex (subscriber, #21167) [Link]

Yeah, exactly. You're correct that it's not *impossible* or even *actually difficult*, it's just messy and annoying and that's not enough improvement over my current situation, whereas Lazy is cleaner.

Don't worry, I was never under the impression it was *impossible* even when I started (long before 1.70) I was just expecting to need a third party crate to make this tidy and now probably I won't.

There's a lot more work to do to properly approach the vision from the Java API but in a nicer language, but I think I'm closing on the point where it's a useful alternative to tools like the Unix "basic calculator" bc or the typical GUI calculator on your desktop OS.


Copyright © 2025, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds