Missing good example/tutorial for Pin

Hello.
For my task, I need a structure that has links to its fields.
There are no concrete examples of how to do this on the Internet or in the official documentation.
Imagine that we have the following structure:

struct Temp <'a>
{
file: File,
file_copy: & 'a mut File
}
or
struct Temp <'a>
{
file: File,
file_copy: Option <& 'a mut File>
}

where file_copy is a mutable reference to the file field.
And the function that opens the file for reading (error handling omitted):

fn open (filename: & dyn AsRef < Path >) -> Pin <Box < Temp> >;

The reason the file_copy ref is required is beyond the scope of the discussion. I want to say that there are several crates that provide APIs, where one structure gives rise to a structure of another type whose lifetime corresponds to the first (for example, zip crate). And I absolutely can not imagine how to put them in one structure and transfer them somewhere else.

Consider using rental crate. Pin is unlikely to be what you want.

2 Likes

Good starting point. I have to research it!!!!

Note that you can create code blocks with three backtics:

```
// your code here
```
1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.