archives of rust-dev@mozilla.org (2010-2015)
 help / color / mirror / Atom feed
* [rust-dev] C interop puzzle
@ 2014-11-25 21:55 Connor Doyle
  2014-11-25 22:12 ` Clark Gaebel
       [not found] ` <CAP6Jx2DES0JoV5DH81oBRqRtwNzU2Z8_j2-AVJ3KwBFOzAvpVg@mail.gmail.com>
  0 siblings, 2 replies; 3+ messages in thread
From: Connor Doyle @ 2014-11-25 21:55 UTC (permalink / raw)
  To: rust-dev

Hi all,

First time on the mailing list!

I'm having trouble setting a raw void pointer in a struct using a recent (72 hrs) nightly.
I'd like to address the underlying bytes for a Vec<u8> I have in-hand.

The FFI guide is a little thin in this area, glad to add detail once I figure out how this is done.

For reference, here is the target struct:

extern crate libc;

#[repr(C)]
pub struct ProtobufObj {
    pub data: *mut libc::c_void,
    pub size: libc::size_t,
}

Thanks,
--
Connor



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [rust-dev] C interop puzzle
  2014-11-25 21:55 [rust-dev] C interop puzzle Connor Doyle
@ 2014-11-25 22:12 ` Clark Gaebel
       [not found] ` <CAP6Jx2DES0JoV5DH81oBRqRtwNzU2Z8_j2-AVJ3KwBFOzAvpVg@mail.gmail.com>
  1 sibling, 0 replies; 3+ messages in thread
From: Clark Gaebel @ 2014-11-25 22:12 UTC (permalink / raw)
  To: Connor Doyle; +Cc: rust-dev

[-- Attachment #1: Type: text/plain, Size: 919 bytes --]

```

let v: Vec<u8> = ...;let repr = v.as_slice().repr();

ProtobufObj {

  data: repr.data,

  size: repr.len

}

```






should do the trick.

On Tue, Nov 25, 2014 at 2:06 PM, Connor Doyle <connor@mesosphere.io>
wrote:

> Hi all,
> First time on the mailing list!
> I'm having trouble setting a raw void pointer in a struct using a recent (72 hrs) nightly.
> I'd like to address the underlying bytes for a Vec<u8> I have in-hand.
> The FFI guide is a little thin in this area, glad to add detail once I figure out how this is done.
> For reference, here is the target struct:
> extern crate libc;
> #[repr(C)]
> pub struct ProtobufObj {
>     pub data: *mut libc::c_void,
>     pub size: libc::size_t,
> }
> Thanks,
> --
> Connor
> _______________________________________________
> Rust-dev mailing list
> Rust-dev@mozilla.org
> https://mail.mozilla.org/listinfo/rust-dev

[-- Attachment #2: Type: text/html, Size: 1524 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [rust-dev] C interop puzzle
       [not found] ` <CAP6Jx2DES0JoV5DH81oBRqRtwNzU2Z8_j2-AVJ3KwBFOzAvpVg@mail.gmail.com>
@ 2014-11-26  0:32   ` Connor Doyle
  0 siblings, 0 replies; 3+ messages in thread
From: Connor Doyle @ 2014-11-26  0:32 UTC (permalink / raw)
  To: José Armando García Sancio, Clark Gaebel, Rust-dev

José and Clark,
An explicit cast as *mut libc::c_void was required to satisfy the type checker.
Works now, thanks!
--
Connor


> On Nov 25, 2014, at 14:15, José Armando García Sancio <jsancio@gmail.com> wrote:
> 
> Hey Connor,
> 
> Small world. Jose here. I suspect that you want to get a slice from the Vec. Slices have two data members: data and len.
> 
> Hope that helps,
> -Jose
> 
> On Tue Nov 25 2014 at 2:06:23 PM Connor Doyle <connor@mesosphere.io> wrote:
> Hi all,
> 
> First time on the mailing list!
> 
> I'm having trouble setting a raw void pointer in a struct using a recent (72 hrs) nightly.
> I'd like to address the underlying bytes for a Vec<u8> I have in-hand.
> 
> The FFI guide is a little thin in this area, glad to add detail once I figure out how this is done.
> 
> For reference, here is the target struct:
> 
> extern crate libc;
> 
> #[repr(C)]
> pub struct ProtobufObj {
>     pub data: *mut libc::c_void,
>     pub size: libc::size_t,
> }
> 
> Thanks,
> --
> Connor
> 
> 
> _______________________________________________
> Rust-dev mailing list
> Rust-dev@mozilla.org
> https://mail.mozilla.org/listinfo/rust-dev


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-11-26  0:32 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-11-25 21:55 [rust-dev] C interop puzzle Connor Doyle
2014-11-25 22:12 ` Clark Gaebel
     [not found] ` <CAP6Jx2DES0JoV5DH81oBRqRtwNzU2Z8_j2-AVJ3KwBFOzAvpVg@mail.gmail.com>
2014-11-26  0:32   ` Connor Doyle

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox