Skip to main content
Filter by
Sorted by
Tagged with
1 vote
0 answers
67 views

I am writing a program in Rust and when debugging in GDB, I noticed that the variables defined within the lazy_static! macro were not displaying as expected. #[derive(Clone, Copy)] struct Addr(usize); ...
Chan S's user avatar
  • 11
0 votes
1 answer
69 views

#[macro_use] extern crate lazy_static; extern crate alloc; use alloc::collections::BTreeMap; use alloc::vec::Vec; fn get_vec<'a>(tree: &'a mut BTreeMap<&'a str, Vec<&'a u8>...
Jihwan Park's user avatar
1 vote
1 answer
133 views

I have the following Rust code targetting x86_64: #[macro_use] extern crate lazy_static; use std::collections::HashMap; lazy_static! { static ref HASHMAP: HashMap<u32, &'static str> = {...
super_jh's user avatar
  • 141
0 votes
1 answer
189 views

This is a PyO3 situation. So the Python calls a long-running task. Using ZeroMQ messaging (inter-process messaging*) it is possible for the user to order the task to be suspended. At that point I want ...
mike rodent's user avatar
  • 16.1k
0 votes
1 answer
1k views

I've already had some success with lazy_static: static ref WORD_COUNT_REPORTING_STEP_MUTEX: Arc<Mutex<usize>> = Arc::new(Mutex::new(0)); static ref INDEX_NAME: RwLock<String> = ...
mike rodent's user avatar
  • 16.1k
0 votes
1 answer
191 views

I'm confused why this code works below: lazy_static! { static ref TSS: TaskStateSegment = { let mut tss = TaskStateSegment::new(); tss.interrupt_stack_table[...
Thetrue kingofwaffles's user avatar
0 votes
0 answers
140 views

I want to develop a library in Rust for microcontrollers that holds some state information. This state data cannot be transferred to the caller of the library. I am using #![no_std]. The library ...
Stefan's user avatar
  • 93
0 votes
2 answers
205 views

I am trying to initialize a static variable at runtime using lazy_static crate. But I'm getting no rules expected the token E1 error while compiling. This is the link lazy_static I followed use ...
Harry's user avatar
  • 4,198
-1 votes
1 answer
365 views

I use Rust's lazy_static crate to assign a frequently used database object to a global variable but I do not want lazy loading. Is there a way to trigger lazy_static to preload the variable or is ...
Konrad Höffner's user avatar
2 votes
1 answer
2k views

I use sqlx for initializing mysql connection (asynchronous) using lazy_static but weird errors occurred. This is the code that I wrote: use actix_web::middleware::Logger; use actix_web::web::{Data, ...
Abdelaziz Said's user avatar
1 vote
1 answer
4k views

I'm new to Rust. I'm trying to create a static variable DATA of Vec<u8> in a library so that it is initialized after the compilation of the lib. I then include the lib in the main code hoping to ...
JKL's user avatar
  • 11
23 votes
2 answers
19k views

lazy_static is a very popular crate. Years ago, it had no better alternatives for certain tasks. But today, are there still any reasons to choose lazy_static over OnceCell (from the standard library, ...
at54321's user avatar
  • 12.4k
0 votes
1 answer
605 views

I am new to Rust. I define a global HashMap of User by lazy_static. There is a lifetime in User, so I have to set a lifetime in lazy_static. It seems that only 'static can be used in lazy_static. Here ...
wub's user avatar
  • 525
3 votes
2 answers
2k views

The documentation states that if the type has a destructor, it won't be called: https://docs.rs/lazy_static/1.4.0/lazy_static/#semantics So how am I supposed to free the memory?
gnevesdev's user avatar
1 vote
1 answer
485 views

lazy_static! { static ref MY_GLOBAL: Mutex<usize> = Mutex::new(100); } MY_GLOBAL.lock().unwrap() += 1; This code gives me these errors: cannot use `+=` on type `MutexGuard<'_, usize>` ...
GirkovArpa's user avatar
  • 5,101
2 votes
0 answers
896 views

My question is the following: Would it be possible to make a deferred initialization of an object and then borrow it as mutable for a 'static lifetime? Some context First of all, I am going to show ...
PauMAVA's user avatar
  • 1,273
1 vote
1 answer
1k views

In my Rust project, I need a globally hold, static array or vec that is initialized once where modules can register values or functions on. I thought, this would be possible using the lazy_static!-...
glasflügel's user avatar
0 votes
1 answer
780 views

I'm trying to use a static HashMap<String, Object> to store some data that I want to use and modify globally in the future. I found out that some way of declaring such a global map is by using ...
Hèctor M.C.'s user avatar
0 votes
0 answers
44 views

I need to create some global mutable variables, using lazy_static! with some types works, but with some other types it doesn't. The mutex is to change value. This works: lazy_static! { static ref ...
Dan D's user avatar
  • 8,779
0 votes
1 answer
1k views

I plan to have a struct which provides the JSON schema via a trait method. The schema is stored compiled in a lazy_static variable, but which type does my schema() function have to return? lazy_static:...
macalloy's user avatar
1 vote
0 answers
421 views

my current project requires recording some information for various events that happen during the execution of a thread. These events are saved in a global struct index by the thread id: RECORDER1: ...
gatoWololo's user avatar
3 votes
1 answer
952 views

I'd like to create a global static boolean value called IS_WINDOWS in a Rust file: lazy_static! { pub static ref IS_WINDOWS: bool = std::env::consts::OS=="windows"; } However, when I do ...
LaVache's user avatar
  • 2,719
3 votes
1 answer
2k views

I am using Rust and I want to use a global mutable HashMap for convenience. However, while it is possible to define a global, mutable HashMap using lazy_static and Mutex, it is hard for my String ...
Stacker Dragon's user avatar
2 votes
1 answer
3k views

I started coding with rust lately and I'm loving it. I'm coding on a project where I want to "wrap" a C-API. In one case I have to define callbacks in Rust, which C can call. I let bindgen ...
JenSeReal's user avatar
3 votes
1 answer
647 views

I have a big project Where I use lazy_static to create a singleton. I think there is a bug in lazy_static crate (which appears in big projects only) or I am doing something wrong because the ...
asmmo's user avatar
  • 7,140
1 vote
1 answer
2k views

If a variable is used in multiple functions in a file, is it better to define it as static rather than passing a non-static variable through function arguments? Does this have a performance impact? An ...
Átila Gama Silva's user avatar
0 votes
1 answer
2k views

I am trying to declare and read/write an instance of a custom struct, using lazy_static as I had to use non-const function at its initialization (string). As I saw here in an other Stackoverflow post, ...
Adrien Chapelet's user avatar
1 vote
2 answers
2k views

In Rust, I am trying to declare a static instance of a custom struct. Because by default I am not able to assign other values than const ones, I am trying to use lazy_static. Here is my custom struct: ...
Adrien Chapelet's user avatar
2 votes
2 answers
639 views

I'm a beginner translating a familiar Cpp project to Rust. The project contains a class called Globals which stores global config parameters. Here is an extract from its cpp file: static Globals &...
Moostropfen's user avatar
4 votes
2 answers
2k views

I have a lazy static struct that I want to be able to set to some random value in the beginning of the execution of the program, and then get later. This little silly snippet can be used as an example:...
Anders's user avatar
  • 8,663
6 votes
4 answers
4k views

I want to use Async MongoDB in a project. I don't want to pass around the client because it would need to go around multiple tasks and threads. So I kept a static client using lazy_static. However, I ...
zireael9797's user avatar
3 votes
2 answers
1k views

I am trying to access a static hashmap for reading and writing but I am always getting error: use std::collections::HashMap; use std::sync::Mutex; pub struct ModuleItem { pub absolute_path: ...
Alexandre's user avatar
  • 3,210