{"action":"created","issue":{"url":"https://api.github.com/repos/AltSysrq/lmdb-zero/issues/14","repository_url":"https://api.github.com/repos/AltSysrq/lmdb-zero","labels_url":"https://api.github.com/repos/AltSysrq/lmdb-zero/issues/14/labels{/name}","comments_url":"https://api.github.com/repos/AltSysrq/lmdb-zero/issues/14/comments","events_url":"https://api.github.com/repos/AltSysrq/lmdb-zero/issues/14/events","html_url":"https://github.com/AltSysrq/lmdb-zero/issues/14","id":358150679,"node_id":"MDU6SXNzdWUzNTgxNTA2Nzk=","number":14,"title":"create_map<Unaligned<f64>>","user":{"login":"katyo","id":238571,"node_id":"MDQ6VXNlcjIzODU3MQ==","avatar_url":"https://avatars1.githubusercontent.com/u/238571?v=4","gravatar_id":"","url":"https://api.github.com/users/katyo","html_url":"https://github.com/katyo","followers_url":"https://api.github.com/users/katyo/followers","following_url":"https://api.github.com/users/katyo/following{/other_user}","gists_url":"https://api.github.com/users/katyo/gists{/gist_id}","starred_url":"https://api.github.com/users/katyo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/katyo/subscriptions","organizations_url":"https://api.github.com/users/katyo/orgs","repos_url":"https://api.github.com/users/katyo/repos","events_url":"https://api.github.com/users/katyo/events{/privacy}","received_events_url":"https://api.github.com/users/katyo/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-09-07T17:30:10Z","updated_at":"2018-09-10T04:31:36Z","closed_at":null,"author_association":"NONE","body":"Is it possible to do this `DatabaseOptions::create_map::<Unaligned<f64>>()`?\r\n\r\nI get an error:\r\n\r\n```\r\nerror[E0277]: the trait bound `f64: lmdb::traits::LmdbRaw` is not satisfied\r\n  --> src/index.rs:49:52\r\n   |\r\n49 |             (IndexKind::Unique, KeyType::Float) => DatabaseOptions::create_map::<Unaligned<f64>>(),\r\n   |                                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `lmdb::traits::LmdbRaw` is not implemented for `f64`\r\n   |\r\n   = note: required because of the requirements on the impl of `lmdb::traits::LmdbOrdKeyIfUnaligned` for `f64`\r\n   = note: required because of the requirements on the impl of `lmdb::traits::LmdbOrdKey` for `lmdb::Unaligned<f64>`\r\n   = note: required by `lmdb::DatabaseOptions::create_map`\r\n```"},"comment":{"url":"https://api.github.com/repos/AltSysrq/lmdb-zero/issues/comments/419784337","html_url":"https://github.com/AltSysrq/lmdb-zero/issues/14#issuecomment-419784337","issue_url":"https://api.github.com/repos/AltSysrq/lmdb-zero/issues/14","id":419784337,"node_id":"MDEyOklzc3VlQ29tbWVudDQxOTc4NDMzNw==","user":{"login":"AltSysrq","id":1392512,"node_id":"MDQ6VXNlcjEzOTI1MTI=","avatar_url":"https://avatars0.githubusercontent.com/u/1392512?v=4","gravatar_id":"","url":"https://api.github.com/users/AltSysrq","html_url":"https://github.com/AltSysrq","followers_url":"https://api.github.com/users/AltSysrq/followers","following_url":"https://api.github.com/users/AltSysrq/following{/other_user}","gists_url":"https://api.github.com/users/AltSysrq/gists{/gist_id}","starred_url":"https://api.github.com/users/AltSysrq/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AltSysrq/subscriptions","organizations_url":"https://api.github.com/users/AltSysrq/orgs","repos_url":"https://api.github.com/users/AltSysrq/repos","events_url":"https://api.github.com/users/AltSysrq/events{/privacy}","received_events_url":"https://api.github.com/users/AltSysrq/received_events","type":"User","site_admin":false},"created_at":"2018-09-10T04:31:36Z","updated_at":"2018-09-10T04:31:36Z","author_association":"OWNER","body":"The compiler's error message here is unfortunate. The actual problem is that `f64` is not `LmdbOrdKeyIfUnaligned` because `f64` is not `Ord`.\r\n\r\nYou have a couple options here.\r\n\r\nThe `u64` representation of `f64` sorts real numbers and infinities the same way and gives NaNs a consistent (but not useful) total ordering with the rest of the values, so you could use `create_map::<Unaligned<u64>>()` and use [`from_bits`](https://doc.rust-lang.org/std/primitive.f64.html#method.from_bits) and [`to_bits`](https://doc.rust-lang.org/std/primitive.f64.html#method.to_bits) to go between `u64` and `f64` in your code.\r\n\r\nThe other option is to define your own newtype around `f64` and then add the needed impls to make it work here:\r\n\r\n```rust\r\n#[derive(Clone, Copy, Debug)]\r\nstruct YourWrapper(f64);\r\nimpl PartialEq for YourWrapper { ... }\r\nimpl Eq for YourWrapper { }\r\nimpl PartialOrd for YourWrapper { ... }\r\nimpl Ord for YourWrapper { ... }\r\nunsafe impl LmdbRawIfUnaligned for YourWrapper {\r\n  fn reported_type() -> String { \"YourWrapper\".to_owned() }\r\n}\r\nunsafe impl LmdbOrdKeyIfUnaligned for YourWrapper { }\r\n```\r\n\r\nThere are some suggestions for dealing with NaNs in [this SO question](https://stackoverflow.com/questions/28247990/how-to-do-a-binary-search-on-a-vec-of-floats). Since your `Ord` impl will be called from C code, if you plan to use the option that delegates to a derived `PartialCmp`, you'll need to use something like `.unwrap_or_else(::std::process::abort)` instead of plain `.unwrap()` since panicking across C stack frames is undefined behaviour."}}
{"actor":{"display_login":"AltSysrq"}}