Warning
This post was published 46 days ago. The information described in this article may have changed.
Hi everyone,
I'm in the process of porting C to Rust and I'm reading:
https://medium.com/dwelo-r-d/wrapping-unsafe-c-libraries-in-rust-d75aeb283c65
One of the examples there:
use std::marker::PhantomData;pub struct Cipher<'a> {
cipher: *const ffi::SSL_CIPHER,
phantom: PhantomData<&'a OpenSSL>,
}fn from<'a>(_: &'a OpenSSL, cipher: *const ffi::SSL_CIPHER)
-> Cipher<'a> {
Cipher { cipher, phantom: PhantomData }
}
Does anyone knows the reasons why the above couldn't be just:
use std::marker::PhantomData;pub struct Cipher<'a> {
cipher: 'a *const ffi::SSL_CIPHER,//lifetime declared here, where it really belongs
}
fn from<'a>(_: &'a OpenSSL, cipher: *const ffi::SSL_CIPHER)
-> Cipher<'a> {
Cipher { cipher, phantom: PhantomData }
}
5 posts - 3 participants
🏷️ rust_feed