Skip to content

Wrapper for yaml get_matches() #1887

Answered by kbknapp
Bechma asked this question in Q&A
Apr 30, 2020 · 1 comments · 1 reply
Discussion options

You must be logged in to vote

The problem you're running into is two-fold and related to Rust and memory, not necessarily clap.

The first and more simple problem is you're trying to store and return a pointer to memory that is immediately deallocated (don't live long enough).

Here is the equivalent, but simplified version of what you're doing:

struct Prueba<'a> {
    s: &'a str, // <-- A reference to some memory in a "String"
}

impl<'a> Prueba<'a> {
  fn new() -> Self {
    let my_string = String::new("Memory"); // <-- Memory is allocated here and owned by "my_string"
    Prueba { s: &my_string } // <-- Prueba has a reference to to the memory owned by "my_string"
 } // <-- "my_string" is de-allocated. What does Prueb…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@Bechma
Comment options

Answer selected by Bechma
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants