{"action":"created","issue":{"url":"https://api.github.com/repos/retep998/winapi-rs/issues/36","labels_url":"https://api.github.com/repos/retep998/winapi-rs/issues/36/labels{/name}","comments_url":"https://api.github.com/repos/retep998/winapi-rs/issues/36/comments","events_url":"https://api.github.com/repos/retep998/winapi-rs/issues/36/events","html_url":"https://github.com/retep998/winapi-rs/issues/36","id":55517538,"number":36,"title":"Broken implementation of winuser::INPUT, must use largest variant","user":{"login":"alexchandel","id":637714,"avatar_url":"https://avatars.githubusercontent.com/u/637714?v=3","gravatar_id":"","url":"https://api.github.com/users/alexchandel","html_url":"https://github.com/alexchandel","followers_url":"https://api.github.com/users/alexchandel/followers","following_url":"https://api.github.com/users/alexchandel/following{/other_user}","gists_url":"https://api.github.com/users/alexchandel/gists{/gist_id}","starred_url":"https://api.github.com/users/alexchandel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alexchandel/subscriptions","organizations_url":"https://api.github.com/users/alexchandel/orgs","repos_url":"https://api.github.com/users/alexchandel/repos","events_url":"https://api.github.com/users/alexchandel/events{/privacy}","received_events_url":"https://api.github.com/users/alexchandel/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":7,"created_at":"2015-01-26T18:18:40Z","updated_at":"2015-01-27T16:14:56Z","closed_at":null,"body":"The implementation you provide for INPUT is broken. The union field is too small to contain any of its variants, as it is type `()`.\r\n\r\nGiven the state of union support in Rust, the only declaration that produces a correctly sized struct is declaring the struct with the largest, most-aligned variant, as I did in my [pull request](https://github.com/retep998/winapi-rs/pull/33).\r\n\r\nThus this:\r\n```rust\r\n#[repr(C)] #[derive(Copy)] pub struct INPUT {\r\n    pub type_: ::DWORD,\r\n    pub union_: MOUSEINPUT,\r\n}\r\n```\r\n\r\nrather than this:\r\n```\r\n#[repr(C)] #[derive(Copy)] pub struct INPUT {\r\n    pub type_: ::DWORD,\r\n    pub union_: (), // FIXME - Use unions or unsafe enums here somehow\r\n}\r\n```\r\n\r\nI get that it's a fixme, but it's also unusable right now. I'd basically have to declare my own INPUT with the correct size and pass that to `SendInput()`, ignoring this altogether.\r\n\r\nFor now, using the largest variant will guarantee the correct size of the struct, and will allow `transmute_copy`s of all three union variants into the `union_` field.\r\n\r\nCould you fix this?"},"comment":{"url":"https://api.github.com/repos/retep998/winapi-rs/issues/comments/71675213","html_url":"https://github.com/retep998/winapi-rs/issues/36#issuecomment-71675213","issue_url":"https://api.github.com/repos/retep998/winapi-rs/issues/36","id":71675213,"user":{"login":"alexchandel","id":637714,"avatar_url":"https://avatars.githubusercontent.com/u/637714?v=3","gravatar_id":"","url":"https://api.github.com/users/alexchandel","html_url":"https://github.com/alexchandel","followers_url":"https://api.github.com/users/alexchandel/followers","following_url":"https://api.github.com/users/alexchandel/following{/other_user}","gists_url":"https://api.github.com/users/alexchandel/gists{/gist_id}","starred_url":"https://api.github.com/users/alexchandel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alexchandel/subscriptions","organizations_url":"https://api.github.com/users/alexchandel/orgs","repos_url":"https://api.github.com/users/alexchandel/repos","events_url":"https://api.github.com/users/alexchandel/events{/privacy}","received_events_url":"https://api.github.com/users/alexchandel/received_events","type":"User","site_admin":false},"created_at":"2015-01-27T16:14:56Z","updated_at":"2015-01-27T16:14:56Z","body":"@retep998 `INPUT_generic` does not work for KEYBDINPUT or HARDWAREINPUT. One would assume that the Windows APIs only accept something that is the size of *the* INPUT struct.\r\n\r\nUntil Rust has better support for C unions, I would declare all Rust unions using the largest, most-aligned variant. This ensures that they're correctly sized and aligned, precludes stack corruption by win32 functions, and saves in headaches. I think my original PR had the best declaration:\r\n```rust\r\n#[repr(C)] #[derive(Copy)] pub struct INPUT {\r\n    pub type_: ::DWORD,\r\n    pub union_: MOUSEINPUT,\r\n}\r\n``"}}