These are chat archives for rust-lang/rust

6th
Nov 2018
Sean Perry
@shaleh
Nov 06 2018 06:17
Tonight's hacking project:
char *
test_internal_equal_float() {
  Lisp_Object n1 = make_float(5.0);
  Lisp_Object n2 = make_float(5.0);
  unit_test_assert(true == internal_equal(n1, n2, EQUAL_PLAIN, 0, Qnil), "internal_equal(5.0, 5.0");
  return 0;
}
Sean Perry
@shaleh
Nov 06 2018 06:44
Sadly I get segfaults on my MacOS when allocations are made.... so I am going to work on Linux for a bit.
Sean Perry
@shaleh
Nov 06 2018 07:28
// This is not right, but much easier than doing what is right.
Denis Lisov
@tanriol
Nov 06 2018 07:30
Does not sound good :-(
Sean Perry
@shaleh
Nov 06 2018 07:32
no comment about what would be right of course. Just snark.
Alexi
@thrashland
Nov 06 2018 07:32
🤔
Zakarum
@omni-viral
Nov 06 2018 07:37
Did somebody proposed manually controlled enum layouts?
IIRC you can only control data-less enum representation.
Sean Perry
@shaleh
Nov 06 2018 07:39
can you provide an example @omni-viral ? The C enums we use via bindgen output so we lack control there.
Zakarum
@omni-viral
Nov 06 2018 07:45
For example you can often find this tecnique for handling API extensions in C:
Function takes structure by pointer and reads first field that is the type or size of that structure to determine how to interpret the data.
If you build wrapper for that API in Rust you'd like to make it safer. For example you can make an enum with known structure types this function can accept. Now you have to convert enum to the C structure with type field on each call.
Would be nice to make the enum layout match structure layout to avoid conversion.
Espectially if function takes array of said structures and conversion requires allocation
Denis Lisov
@tanriol
Nov 06 2018 07:47
@omni-viral RFC 2195 allows you to force C-compatible layout. It has been accepted and should be already implemented. Explicit control over tag values is mentioned in future extensions of the RFC.
Sean Perry
@shaleh
Nov 06 2018 07:49
Are you thinking for LispObject?
Zakarum
@omni-viral
Nov 06 2018 07:52
@tanriol This looks like it. Thanks for the link )
Zakarum
@omni-viral
Nov 06 2018 10:02

Just checked.

#[repr(u8)]
enum Foo {
  Bar,
  Baz(u32),
}

has 64 bits size and Foo::Baz(42) has layout with tag at byte 0, bytes 1..4 undefined and 4..8 contains 42

Exactly what I want )
Except maybe control over discriminant values
Sylwester Rąpała
@xoac
Nov 06 2018 14:35

I want to take a first n elements and then iterate it from the end:

iter().take(no).rev()

but

^^^ the trait `std::iter::DoubleEndedIterator` is not implemented for `std::iter::Take<std::slice::Iter<'_, std::option::Option<meas::raw::Harmonic>>>`
Sylwester Rąpała
@xoac
Nov 06 2018 20:03
I would like to impl Stream for V1Builder. And tell Rust to implement it only if S::Error implement Into<MyError>. How can I tell this?
  impl<S> Stream for V1Builder<S>
  where
      S: Stream<Item = Item>,
Tim Robinson
@1tgr
Nov 06 2018 21:33
where S: Stream, S::Error: Into<MyError>
Sylwester Rąpała
@xoac
Nov 06 2018 22:30
@1tgr Thx it works.
Tom Watson
@FridgeSeal
Nov 06 2018 23:38
Does anyone use the Rust Enhanced plugin for sublime text 3? I’ve somehow broken one of the cargo build options and I can’t seem to fix it lol