Lifetime names? Confused

⚓ Rust    📅 2026-04-12    👤 surdeus    👁️ 5      

surdeus

Info

This post is auto-generated from RSS feed The Rust Programming Language Forum - Latest topics. Source: Lifetime names? Confused

I am not getting anywhere reading the various 'lifetime' things.
I've tried the RUST BY EXAMPLE, and the Brown UNIV RUST Course
And things here. so I'll try here:

First background: Yes, I understand what a variable lifetime means, I understand that if something is allocated from the heap and if something points into that memory blob, if it is reallocated - that blob is no longer valid because the heap moved your buffer. Lifetime is also a lot like what I know as the "gen" and "kill" of a variable a long time ago. The GEN (or generation) of a variable is when it is first assigned, and the KILL is the last place it is used within the control flow.

But as much as I read - I do not see/understand the 'a, seems common, and other times it is 'a, 'b, 'c - these names seem arbitary- but - there are others like 'static - which sometimes is illegal to use because it is a reserved word..

So my problem is this:

a) I need to have a rust module that manages some compile time pre-allocated buffers in C, think of these as memory regions in "DMA SAFE" memory space. I have one called the ETH_INP_BUF, and the ETH_OUT_BUF, and the SPI_RD_BUF and the SPI_WR_BUFFER. - on my platform I must allocate these by way of tricks in the linker because the FPGA can only access certain memory regions. You might guess, I am doing low level OS stuff, and in my case it is all NO_STD, and I cannot use any allocation.

I want to have a create called a "ByteBuffer" - I would know it as a C struct, with three elements: (A) A pointer to memory (B) a capacity, and (C) a cursor - where I am writing or reading. In RUST - both (A) and (B) are effectively a reference to an array.

I created something in the playground here:

Rust Playground

Some confusion: RUSTC says I need to add 'a everywhere -but I do and then I get other errors.

The lifetime of the ByteBuffer2 will always be less then the buffer reference.
Each buffer is generally a global variable in DMA safe memory.

I can't allocate it - RUST does not understand the idea/concept of multiple heaps and allocating data from different heaps [Yes, I looked over the slab allocator it does not help]

Suggestions would be most helpful - I'm now 48 hours into trying numerous things and I am not making progress and seem to be going in circles.

3 posts - 2 participants

Read full topic

🏷️ Rust_feed