From: Miguel Ojeda <miguel.ojeda.sandonis@gmail.com>
To: Finn Behrens <me@kloenk.de>
Cc: Wedson Almeida Filho <wedsonaf@google.com>,
rust-for-linux <rust-for-linux@vger.kernel.org>
Subject: Re: PointerWrapper Trait vs croe::ops::Deref
Date: Sun, 9 May 2021 16:21:38 +0200 [thread overview]
Message-ID: <CANiq72=8M3ALxrmdYvHNfDVX9F4Se0=a-EbzrZPgVv1xsh932Q@mail.gmail.com> (raw)
In-Reply-To: <97E4F6F4-2391-4053-89FC-BB00F9184340@kloenk.de>
On Sun, May 9, 2021 at 12:25 PM Finn Behrens <me@kloenk.de> wrote:
>
> Maybe we could also remove the result, as it would possible be an invariant, and never happen as the pointer should already be valid.
If it can fail, we cannot use `Deref` to begin with. So yeah, to make
the examples equivalent, the first one should not return a `Result`.
Now, assuming it cannot fail, what I mentioned in the meeting is that
with `Deref` all this compiles:
wrapper.deref().number
(*wrapper).number
wrapper.number
The question boils down to: do we want this shortcut or not?
Having said that, I am not sure I understand the traits shown here.
Isn't `PointerWrapper` meant only to save a `Box<T>` and similar types
(which already implement `Deref` themselves etc.) as a pointer in a C
data structure? (which is why `into_pointer()` consumes the object).
In the examples shown, the new `get_pointer()` does not consume
`self`; and `main()` creates a `Wrapper` using `from_pointer()`. But
the idea is that you already have an object (constructed via other
means), transform it into a raw pointer, and then later on
re-construct the original object back from that pointer.
So `PointerWrapper` trait is like a `SavedAsPointer` trait, if you will.
Cheers,
Miguel
next prev parent reply other threads:[~2021-05-09 14:21 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-05-09 10:25 PointerWrapper Trait vs croe::ops::Deref Finn Behrens
2021-05-09 14:21 ` Miguel Ojeda [this message]
2021-05-10 14:04 ` Finn Behrens
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CANiq72=8M3ALxrmdYvHNfDVX9F4Se0=a-EbzrZPgVv1xsh932Q@mail.gmail.com' \
--to=miguel.ojeda.sandonis@gmail.com \
--cc=me@kloenk.de \
--cc=rust-for-linux@vger.kernel.org \
--cc=wedsonaf@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).