Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature request: allow packed types #1704

Closed
bnoordhuis opened this issue Jan 30, 2012 · 3 comments
Closed

feature request: allow packed types #1704

bnoordhuis opened this issue Jan 30, 2012 · 3 comments
Labels
A-typesystem Area: The type system C-enhancement Category: An issue proposing an enhancement or a PR with one.

Comments

@bnoordhuis
Copy link
Contributor

Would it be possible to add support for packed types? Types appear to be unpacked right now (which is fine in itself) but it blocks interop with C APIs like epoll_wait.

Example: on x86_64, (0u32, 0u64) is 12 bytes when packed and 16 bytes when unpacked.

@brson
Copy link
Contributor

brson commented Jan 30, 2012

While I do think we should support this in the language, you could probably hack around the problem with unsafe pointers.

bnoordhuis added a commit to bnoordhuis/rust-epoll that referenced this issue Feb 6, 2012
The kernel expects a packed (no holes) epoll_event struct but Rust doesn't
support packed types yet.

Depends on rust-lang/rust#1704.
@graydon
Copy link
Contributor

graydon commented Feb 15, 2012

I'm ok taking a patch to add packed as a prefix type operator to a record, vector or tuple type. It'll be a bit of a pain to support but does seem to be part of the world we live in.

huonw added a commit to huonw/rust that referenced this issue Apr 9, 2013
A struct (inc. tuple struct) can be annotated with #[packed], so that there
is no padding between its elements, like GCC's `__attribute__((packed))`.

Closes rust-lang#1704.
huonw added a commit to huonw/rust that referenced this issue Apr 10, 2013
A struct (inc. tuple struct) can be annotated with #[packed], so that there
is no padding between its elements, like GCC's `__attribute__((packed))`.

Closes rust-lang#1704
bors added a commit that referenced this issue Apr 10, 2013
#5758 take 2.

This adds a `#[packed]` attribute for structs, like GCC's `__attribute__((packed))`, e.g.

```rust
#[packed]
struct Size5 {
   a: u8,
   b: u32
}
```

It works on normal and tuple structs, but is (silently) ignored on enums.

Closes #1704.
@thestinger
Copy link
Contributor

Fixed by cad2260

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-typesystem Area: The type system C-enhancement Category: An issue proposing an enhancement or a PR with one.
Projects
None yet
Development

No branches or pull requests

4 participants