lifetime Questions

3

Solved

Given the following struct and impl: use std::slice::Iter; use std::cell::RefCell; struct Foo { bar: RefCell<Vec<u32>>, } impl Foo { pub fn iter(&self) -> Iter<u32> { ...
Uncork asked 5/11, 2015 at 9:58

1

Solved

The following code produces the lifetime errors below despite the fact that the V instance in question is owned. use std::collections::hash_map::HashMap; use std::cmp::Eq; use std::hash::Hash; tra...
Kesha asked 23/12, 2021 at 7:40

1

This is my first project in Rust, and I think I'm missing something simple. I'm attempting to create a simple Web API daemon that will receive POSTs of JSON, parse the JSON, and send an email usi...
Allpowerful asked 24/11, 2019 at 1:36

7

Solved

How to set session lifetime in PHP? I Want to set it to forever as long as the request is exist. The request is AJAX. My PHP code that handle AJAX request is: // AJAX.php <?php session_start(...
Whitson asked 15/6, 2011 at 15:18

2

Solved

Actually I started with Blazor and EF Core. At registering the DbContext i get stucked. The DbContext can be registerd with AddDbContext or with AddDbContextFactory. But what´s the difference? buil...
Lamellirostral asked 6/12, 2021 at 14:39

2

I've been trying to find a good explanation of Rust lifetimes. I get the idea that they are our way of telling the compiler which variables have to outlive which, so it can verify that references a...
Deaden asked 2/12, 2021 at 19:13

2

Solved

I'm still trying to understand Rust ownership and lifetimes, and I'm confused by this piece of code: struct Foo { x: String, } fn get_x<'a, 'b>(a: &'a Foo, b: &'b Foo) -> &'b...
Ideo asked 15/11, 2021 at 21:59

1

I am attempting to define a struct, in Rust, that contains a member of type async_executor::LocalExecutor, a type that, itself, is generic over a lifetime, 'a: pub struct LocalExecutor<'a> { ...
Immunize asked 4/11, 2021 at 13:20

3

Solved

I am in the process of learning Rust and was testing some array copying through a function. I am sure there are built-in Rust functions to copy/clone array information, but a personal implementatio...
Yocum asked 3/11, 2021 at 17:57

2

Solved

I'm trying to learn Rust's ownership and lifetimes in more detail, and I'm very confused by this piece of code: let mut lst = vec![1, 2, 3]; let mut x = &mut 0; for value in &mut lst { *v...
Juggle asked 12/10, 2021 at 18:55

1

Solved

I think my question relates to Rust Issue 57017. The following code does not compile and produces error: future cannot be sent between threads safely due to future created by async block is not 'Se...
Guess asked 30/9, 2021 at 11:54

7

I've tried to code like this several times: struct Foo { double const& f; Foo(double const& fx) : f(fx) { printf("%f %f\n", fx, this->f); // 125 125 } double GetF() const { ret...
Arthritis asked 29/7, 2017 at 4:56

1

Solved

Consider this snippet: #include <iostream> #include <string> #include <string_view> using namespace std::literals; class A { public: std::string to_string() const noexcept { ...
Concurrent asked 23/8, 2021 at 13:26

1

Solved

Put it other way, conversely, are std::span iterators invalidated after the span instance is destroyed? I have a vector I need to iterate over with different layouts. I'm trying to make use of std:...
Molotov asked 11/8, 2021 at 19:38

1

Solved

I have the following code use std::future::Future; fn main() { handle(Test::my_func); } fn handle<Fut>(fun: for<'r> fn(&'r mut Test) -> Fut) -> bool where Fut: Future<Ou...

3

Solved

Does having a reference &'a T immediately cause UB (undefined behavior) if 'a is larger than the referenced value? OR is it fine to have such a reference as long as it does not outlive the refe...
Unskilled asked 20/7, 2021 at 11:14

1

Solved

I would like to return a reference to an owned object that is in a collection (viz., a Vec), but I cannot seem to get the lifetimes correct. Here is what I first tried: struct StringHolder { strin...
Session asked 31/7, 2021 at 23:29

4

Solved

In a project where custom Serde (1.0) serialization and deserialization methods are involved, I have relied on this test routine to check whether serializing an object and back would yield an equiv...
Aegrotat asked 1/10, 2017 at 16:12

1

I want the async block in the following code to implement Send (Playground): use std::collections::BTreeSet; use std::future::ready; pub fn test<T: Sync>(set: &BTreeSet<T>) -> i...
Karylkarylin asked 8/7, 2021 at 8:20

4

Solved

I am having trouble expressing the lifetime of the return value of an Iterator implementation. How can I compile this code without changing the return value of the iterator? I'd like it to return a...
Popsicle asked 24/5, 2015 at 9:54

1

Solved

I'm trying to write a constructor function which takes a generic value implementing some trait by argument, and then boxes it (the point is to then initialize something with these boxes, but the fo...
Shut asked 10/6, 2021 at 20:25

5

Solved

Rust disallows this kind of code because it is unsafe: fn main() { let mut i = 42; let ref_to_i_1 = unsafe { &mut *(&mut i as *mut i32) }; let ref_to_i_2 = unsafe { &mut *(&mut ...
Fenella asked 8/3, 2018 at 13:44

2

Solved

In the following piece of code, I am trying to understand how the generic lifetime parameter 'a is specialized. struct Wrapper<'a>(&'a i32); fn foo() { let mut r; { let x = 0; // the...
Knackwurst asked 21/5, 2021 at 6:48

0

I am trying to pass a closure returning Future<Output=bool> to an async function and call this closure as an async predicate (something like an async .filter or other higher-order function). ...
Ewald asked 17/5, 2021 at 12:20

0

This code compiles: async fn foo(_: impl Iterator<Item = &u32>) {} However, removing the async, it does not work anymore: fn foo(_: impl Iterator<Item = &u32>) {} Instead, it ...
Orazio asked 10/5, 2021 at 11:24

© 2022 - 2024 — McMap. All rights reserved.