lifetime Questions

3

Solved

I have following code and don't know how to get it working: fn new_int<'a>() -> &'a isize { &5 } fn main() { let x = new_int(); } Or another attempt: fn new_int<'a>() ...
Kumasi asked 23/1, 2015 at 11:15

1

Solved

I'm learning Rust from the Book and I was tackling the exercises at the end of chapter 8, but I'm hitting a wall with the one about converting words into Pig Latin. I wanted to see specifically if ...
Ike asked 28/7, 2020 at 10:18

2

Solved

Background I know that the borrow checker disallows more than one mutable borrows. For example, the code below is invalid: fn main() { let mut x = 42; let a = &mut x; let b = &mut x; pr...
Marlin asked 9/7, 2020 at 14:35

1

Solved

Given the following Rust program: struct Value<'v>(&'v ()); struct Container {} impl Container { fn get<'v>(&'v self) -> Value<'v> { todo!() } fn set<'v>(&...
Racehorse asked 30/6, 2020 at 14:1

1

I am looking for a way to ensure a struct outlives the parameter given to a method of that struct. Even if the struct doesn't hold a reference to that data after leaving the method. This is for wr...
Sleepless asked 14/6, 2020 at 15:7

1

Solved

I'm currently following along with https://raytracing.github.io/books/RayTracingInOneWeekend.html but I'm implementing everything in Rust. Here's a excerpt from my vector implementation: type Scal...
Selestina asked 17/5, 2020 at 15:49

2

Solved

I was implementing linked lists by following along too many linked lists. When trying to implement iter_mut(), I did it myself and made the following code: type Link<T> = Option<Box<Nod...
Eclat asked 17/5, 2020 at 4:58

2

Solved

I have a general struct with settings and an extra variable setting that I want to tune and play around with. For all possible values in an integer range, I want to start a (scoped) thread with th...
Peacock asked 19/10, 2019 at 0:52

6

Solved

The following code reads space-delimited records from stdin, and writes comma-delimited records to stdout. Even with optimized builds it's rather slow (about twice as slow as using, say, awk). use...
Jarvis asked 9/10, 2016 at 17:27

2

Solved

I'm implementing a stack-like structure, where the structure holds a mutable reference to a slice. struct StackLike<'a, X> { data: &'a mut [X], } I'd like to be able to pop the last ...
Entangle asked 15/4, 2020 at 7:12

1

Solved

I have a PyQt5 application that shows a small list. It allows the user to copy list items. When the user copies a list item, it uses delayed rendering to place a reference to the item onto the clip...
Characharabanc asked 14/4, 2020 at 15:57

1

Solved

I want to write the following function: fn foo<'a, 'b, 'c>(rr1: &'a mut &'c mut u32, rr2: &'b mut &'c mut u32) { *rr1 = *rr2; } But the compiler complains: error[E0623]: ...
Tetzel asked 13/4, 2020 at 19:36

1

Solved

I've been thinking about why interior mutability in Rust in most cases requires runtime checks (e.g. RefCell). It looks like I've found a safe alternative without a runtime cost. I've called the ty...
Katinakatine asked 11/4, 2020 at 15:47

1

Solved

Does a call to a trivial destructor end the lifetime of an object? I read this and this but didn't find a good explanation. These threads state that a trivial destructor call has no effect and code...
Rewarding asked 6/4, 2020 at 19:22

2

Solved

I have these structs: #[derive(Debug, Serialize, Deserialize)] pub struct GGConf<'a> { #[serde(alias = "ssh")] #[serde(rename = "ssh")] #[serde(default)] #[serde(borrow)] pub ssh_config...
Furmenty asked 22/3, 2020 at 15:22

1

Solved

I have a struct that lazily load data into an inner vector (but for the example this is ommited). Then I am implementing IntoIterator and Iterator for the IntoIterator type: struct EntryOwned(u32);...
Isallobar asked 21/3, 2020 at 13:8

1

Solved

I am trying to compile the following seemingly straightforward code, but I'm getting an error: use std::io::Error; #[derive(Debug)] struct NetworkConfig { bind: String, node_key_file: String, } ...
Grosso asked 15/3, 2020 at 1:6

1

Solved

In the C++20 standard, it is said that array types are implicit lifetime type. Does it mean that an array to a non implicit lifetime type can be implicitly created? The implicit creation of such an...
Hildegardhildegarde asked 11/3, 2020 at 7:39

3

Solved

I'm trying to sort a Vec<String> using a key function that returns references to the strings in the vector. A contrived example is to use the identity function as key function (which of cours...
Dudgeon asked 5/11, 2017 at 13:13

1

I am trying to define a recursive struct similar to a linked list for a tree traversal. A node has some data and access to its parent. The child node should borrow its parent mutably to ensure excl...
Tshirt asked 11/2, 2020 at 21:43

2

Solved

I've recently come across a borrow checker message I've never seen before which I'm trying to understand. Here is the code to reproduce it (simplified, real-life example was more complex) - playgro...
Cabalism asked 26/1, 2020 at 23:8

1

Solved

So I'm following this tutorial to build a rogue-like and I've decided to start using the specs dispatcher to make registering and executing systems a bit easier. To do that I've added a Dispatcher...
Elegancy asked 23/1, 2020 at 13:55

0

This is actually an offshoot of this SO question. Consider the following code: trait Trait<'b> { fn func(&'b self) {} } struct Struct {} impl<'s> Trait<'s> for Struct {}...
Legofmutton asked 12/1, 2020 at 6:36

1

Solved

[basic.scope.pdecl]/1 of the C++20 standard draft had the following (non-normative) example in a note (partial quote from before the merge of pull request 3580, see answer to this question): unsig...
Executor asked 22/12, 2019 at 7:54

2

The "undead" clause I call the undead clause the C++ rule that after the destruction of an object, if a new object is created at the same address, it can sometimes be considered the same object as...
Olericulture asked 12/12, 2019 at 6:31

© 2022 - 2024 — McMap. All rights reserved.