metadeus

u/metadeus


r/rust•

I'm working on a project that generates lots of Rust code (> 5MB). The problem is that I'm not able to compile it, as rustc uses too much memory (> 5GB) and gets killed by Linux kernel. Also, compile times are unacceptable (> 5 min).

This is very disappointing, as I have the same generated code for Ruby and Python and they both can handle it without any problems, but I really want to use Rust in production.

What can I do about it?

I already tried:

  • make a separate crate for generated code
  • opt-level = 0
  • explicitly provide all the types
  • generate simpler code

I can, of course, split crate into smaller ones, but then I will end up having 20-30 crates and I'm not sure it will

1424

r/rust•

Hi! Why there are NonZero* types, but no NonMax* types? From my point of view, NonZero used mainly as an index in a collection. In this case", you have to -1, +1 it on every use.

Is it maybe, possible to introduce an InvalidValue trait which can be used to define your own "special" value for arbitrary type? Something similar I'm using here: https://docs.rs/obj-pool/0.2.0/src/obj_pool/invalid_value.rs.html#4-6

And for this special trait, we could implement compiler support to optimize memory footprint of Option<T> where T: InvalidValue.

2315

r/rust•

I have a lot of functions and methods which return either Option or Result, is there a naming convention for such functions? I need to distinguish them as there often two variants of the same function -- one returning Option (which is cheap) and one returning Result (which could be very expensive). For now, I'm using this:

fn mm(&self) -> Option<FragModelRef>;

fn mm_or_err(&self) -> Res<FragModelRef> {
    self.mm().ok_or_else(|| diag_err!("can't find metamodel"))
}

But I want to get rid of the _or_err()? on every line of my sources. So I consider something like:

fn mm_opt(&self) -> Option<FragModelRef>;

fn mm(&self) -
417

r/rust•

Hi all, I don't yet know if this idea is stupid or not, maybe I'm just missing something.

What if we could specify kind of an "auto" where "impl" or "dyn" expected so we could let the compiler decide to use static dispatch or dynamic dispatch. The compiler knows more details on performance and at the same time, it knows how many actual types implement such trait.

For instance, in case of a method parameter it could decide to use static dispatch if there are only two types which could be used as arguments, but in case we add more types it could go dynamic to lower the memory footprint and achieve fewer cache misses.

35

r/rust•
pub struct ModelInfo {
    pub obj_reg: ObjReg, // <- struct typre
    pub metainfo: Box<MetaInfoProvider>, // <- box of a trait
    pub obj_pool: ObjPool, // <- struct type
    pub str_int: StrInt, // <- struct type
}
impl ModelInfo {
pub fn merge(mut self, o: Self) -> Self {
    let Self { mut str_int, mut obj_reg, mut metainfo, mut obj_pool } = o;
    for (sym, s) in str_int.into_iter() { // into_iter consumes self
    }
    self
}
}

How is this even possible?

error[E0507]: cannot move out of borrowed content
    |
201 |         for (sym, s) in str_int.into_iter() {
    |                        
29

You've reached the end of this feed.