These are chat archives for rust-lang/rust

10th
Mar 2018
Moggers
@Moggers
Mar 10 2018 04:28
Two minute incremental build times
JustRustThings
whoops
Niranjan A Kartha
@n-kartha
Mar 10 2018 04:41
I'm building a brainf**k interpreter in Rust as a fun first project
How do I push an i32 into an OsString?
I want the thing to be rendered as a char if it can, but otherwise, it should be stored as invalid Unicode
Huang Wenjun
@WenjunHuang
Mar 10 2018 06:26

hi,i am reading glib-rs’s source code and come to the following code:

#[macro_export]
macro_rules! glib_object_wrapper {
    ([$($attr:meta)*] $name:ident, $ffi_name:path, $ffi_class_name:path, @get_type $get_type_expr:expr) => {
        $(#[$attr])*
        #[derive(Clone, Debug, Hash)]
        pub struct $name($crate::object::ObjectRef, ::std::marker::PhantomData<$ffi_name>);

        #[doc(hidden)]
        impl Into<$crate::object::ObjectRef> for $name {
            fn into(self) -> $crate::object::ObjectRef {
                self.0
            }
        }

there is no capture of variable $crate.So is it a rust macro feature or some magic here?

Huang Wenjun
@WenjunHuang
Mar 10 2018 06:37
@kngwyu thank you:)
Fredrik Portström
@portstrom
Mar 10 2018 08:34
@AyushyaChitransh Thank you for your interest. I'm considering doing an online workshop over Google Hangouts as well.
Fredrik Portström
@portstrom
Mar 10 2018 08:49

@vorner It would be great to have someone help mentor. Would you also be interested in participating as a speaker if I arrange the kind of events with three speakers, beer and sandwiches?

I would like to get Rust adopted in my company as well. I have the feeling that the main problem is that development is very hype-driven and Rust doesn't have enough visibility. If you reinvent the wheel in Javascript, you will have plenty of celebrity bloggers and speakers promoting it, but if you do something well-designed in Rust, decision makers in companies will never hear about it.

Michal 'vorner' Vaner
@vorner
Mar 10 2018 08:59
@portstrom I'm also OK with giving a talk, no problem with that. But for that I'd need a longer notice (I don't need any special preparation for mentoring, but I'd need to prepare the talk) and a suggestion for a topic (and expected audience, etc) would come handy.
And I don't see the hype (not so much) in my company. They are quite open to trying Rust out, they see the possible advantages, but there's a lot of inertia (a lot of custom libraries for Java/Scala, most people don't know Rust but they make services in Scala in no-time because it's similar to what they've done already). So it's matter of finding the right project to try it out, getting some people with time onboard… I think it just needs some time here and it'll happen.
Fredrik Portström
@portstrom
Mar 10 2018 09:35
@vorner That's great to hear! The topic would obviously have to be something that is interesting to people who don't already know Rust. I guess your field is less hype-driven than mine.
Andy Grove
@andygrove
Mar 10 2018 14:17
Hi. I'm having a hard time trying to do something "the right way" in Rust and could use some guidance.
I'm using an enum currently to represent different types of values in a data processing system.
pub enum Value {
    Boolean(bool),
    Double(f64),
    Long(i64),
It's working well and is simple to code against. I use pattern matching at runtime to figure out how to deal with the values.
Denis Lisov
@tanriol
Mar 10 2018 14:19
@andygrove Sounds like a good idea :-)
Andy Grove
@andygrove
Mar 10 2018 14:20
I'm glad you like it too! But one person told me "The data types are compilation concept, they should not exist at run-time. You can use generics, type erasure and columnar dispatch to get it."
The thing is I have to decide at runtime what types I'm dealing with. I do have meta-data though.
So suppose I did use generics, and I dealt with columns of data as Vec<T>
at runtime I could use pattern matching on my metadata
match columnType {
  ColumnType::Int => ???
if I had a Vec<T> I don't think there is a way to cast it to Vec<u32> or whatever?
Andy Grove
@andygrove
Mar 10 2018 14:29
(the last few questions were redundant so I deleted them)
Niranjan A Kartha
@n-kartha
Mar 10 2018 14:41
:wave:
I have a small question
Is it more efficient to use FFI or should I use child_process and spawn a rust .exe and use stdin/out?
Andy Grove
@andygrove
Mar 10 2018 14:42
FFI would be more efficient because you aren't spinning up a new process
Niranjan A Kartha
@n-kartha
Mar 10 2018 14:43
I read somewhere that FFI is expensive
Andy Grove
@andygrove
Mar 10 2018 14:43
but how often are you doing this? just once? maybe it doesn't matter
Niranjan A Kartha
@n-kartha
Mar 10 2018 14:43
Like
I want a stream open between node.js and rust
So that I can do I/O on node.js and all the processing is left with rust
Andy Grove
@andygrove
Mar 10 2018 14:43
I'm no expert but I thought FFI is zero overhead when calling C code. What are you calling?
oh, node.js
Niranjan A Kartha
@n-kartha
Mar 10 2018 14:44
Should I benchmark?
Andy Grove
@andygrove
Mar 10 2018 14:44
with that architecture I think you want to start a server in Rust
that can accept network connections from node.js
Niranjan A Kartha
@n-kartha
Mar 10 2018 14:44
Yes
No, wait
Not exactly
I want to run an AI on Rust and do everything else on node
If I have a stream open with OsStrings being sent, I can do all other backend stuff with node while Rust does the heavy-duty execution part
Andy Grove
@andygrove
Mar 10 2018 14:46
I don't know node but I would think that having your Rust code running as a server would be the way to go and you can stream data between node and Rust
Niranjan A Kartha
@n-kartha
Mar 10 2018 14:47
I'm not as familiar with Rust as I am with node
I can try to benchmark the performance with both
In fact, I'll do that now
Andy Grove
@andygrove
Mar 10 2018 14:48
https://docs.rs/hyper/0.11.22/hyper/ is good for running a HTTP / REST server in Rust
Niranjan A Kartha
@n-kartha
Mar 10 2018 14:55
Man, the node ffi library requires additional build tools
This will take a while
Niranjan A Kartha
@n-kartha
Mar 10 2018 15:52
Turns out that ffi isn't compatible with my node
So I quit, I'm just gonna use child_process
Fredrik Portström
@portstrom
Mar 10 2018 16:29
I've created a collection of programs to use for a Rust workshop for beginners. I welcome feedback and contributions. https://github.com/portstrom/rust_workshop
Andy Grove
@andygrove
Mar 10 2018 18:43
@portstrom you might want to post that to the Rust subreddit if you haven't already - great place to get some feedback
So I have a high level question ... if I'm performing vectorized operations like this:
                    let left_values : Vec<Value> = l(batch);
                    let right_values : Vec<Value> = r(batch);
                    let v = left_values.iter().zip(right_values.iter());
                    v.map(|(a,b)| Value::Boolean(a==b)).collect()
.. does Rust do anything special, like recognizing this is a SIMD operation?
I'm thinking I should be able to take advantage of my GPU here
Dylan DPC
@Dylan-DPC
Mar 10 2018 18:51
@portstrom yeh you can post on reddit or even on users' forum.
Fredrik Portström
@portstrom
Mar 10 2018 19:01
@andygrove @Dylan-DPC Thanks, will join the forum/Reddit.
Dylan DPC
@Dylan-DPC
Mar 10 2018 19:01
:)
Michal 'vorner' Vaner
@vorner
Mar 10 2018 19:44
@andygrove Sometimes Rust/LLVM may recognize it can use SIMD instructions (SSE/AVX…). You can make sure it uses them, with things like faster or stdsimd. GPU will be harder (and won't happen automagically for sure ‒ Rust can't know if you have a GPU or that'll be faster to transfer the data into it, compute it there and get it back).
Denis Lisov
@tanriol
Mar 10 2018 20:09
@andygrove Where Value is an enum? I'd guess it does not.
Ingvar Stepanyan
@RReverser
Mar 10 2018 22:24
@andygrove Questions like that are usually best answered with disassembler (I use rust.godbolt.org all the time). Here is approximation of your sample: https://godbolt.org/g/Ej7djx
You can see in the output that it's not using vectorized instructions
However, if you change Vec<Value> for input types to e.g. Vec<u32>, it's able to make use of them
Andy Grove
@andygrove
Mar 10 2018 22:26
@RReverser That's a huge help. Thank you.
@vorner I missed your earlier answer .. thank you too .. this is all very helpful
yeah so this relates to my earlier question about using generics instead of my value enum ...
Ingvar Stepanyan
@RReverser
Mar 10 2018 22:28
Btw, what kind of other values can you have in Value? Are they all primitives?
Andy Grove
@andygrove
Mar 10 2018 22:28
Sadly, no
pub enum Value {
    Boolean(bool),
    Double(f64),
    Long(i64),
    UnsignedLong(u64),
    String(String),
    /// Complex value which is a list of values (which in turn can be complex
    /// values to support nested types)
    ComplexValue(Vec<Value>),
    /// values for user-defined types are stored as binary
    UserDefined(Vec<u8>)
}
Ingvar Stepanyan
@RReverser
Mar 10 2018 22:28
Oh fun
Yeah, then what I was going to suggest is not very helpful :D
Andy Grove
@andygrove
Mar 10 2018 22:29
well I could have two enums .. one for primitives and one for complex
Ingvar Stepanyan
@RReverser
Mar 10 2018 22:29
Not sure splitting would help for generic comparison function
Andy Grove
@andygrove
Mar 10 2018 23:13
Oh, I just realized how this should be done
```
pub enum ColumnData {
    Boolean(Vec<bool>),
    Float(Vec<f32>),
    Double(Vec<f64>),
    UnsignedLong(Vec<u64>),
    String(Vec<String>)
}