These are chat archives for rust-lang/rust

16th
Mar 2019
Martijn Bakker
@Gladdy
Mar 16 14:26
I was looking around for a way to tidy up patterns like this a bit and wasn't able to find anything - currently I've got to duplicate all of my field names and all of their types in both the struct definition and the main constructor - does anyone have any pointer/suggestions or is this the cleanest I'd be able to get this kind of code? After running rustfmt on it it just takes up a lot of lines with fairly little information on them.
pub struct ThreadState {
    id: usize,
    pub log: slog::Logger,
    ctrl_sender: ThreadClient,
    local_senders: DataSenders,
    remote_senders: RefCell<Option<TcpStream>>,
    ps: ProcessorLookup<ProcessorEnum>,
    factory: Factory,
}

impl ThreadState {
    fn new(
        id: usize,
        log: slog::Logger,
        ctrl_sender: ThreadClient,
        local_senders: DataSenders,
        factory: Factory,
    ) -> Self {
        Self {
            id,
            log,
            ctrl_sender,
            local_senders,
            ps: ProcessorLookup::new(),
            factory,
            remote_senders: RefCell::new(Option::None),
        }
    }
...
tsoernes
@tsoernes
Mar 16 15:08
how can i display f64 as binary?
Martijn Bakker
@Gladdy
Mar 16 15:11
you can do a transmute (or transmute copy) into a u64 or an array of 8 bytes and then show that?
transmute is the rust equivalent of the C++ reinterpret_cast<>
actually: https://doc.rust-lang.org/std/fmt/trait.Binary.html is implemented for f64 so that should do