These are chat archives for rust-lang/rust

10th
May 2018
Chaitanya Munukutla
@munukutla
May 10 2018 02:06
Hey guys. Anyone has ideas about monitoring Java applications from Rust?
Skylight does something similar; it uses Rust to profile Ruby on Rails applications.
Hans W. Uhlig
@huhlig
May 10 2018 02:29
@munukutla you can use imx easily enough
jmx
alternatively you could write a native rust agent for injection
Chaitanya Munukutla
@munukutla
May 10 2018 02:36
I’m more inclined towards rust injection. Any thoughts on how to?
Hans W. Uhlig
@huhlig
May 10 2018 02:37
jvmti
look at the link
jvmti and jni should do what you need
Chaitanya Munukutla
@munukutla
May 10 2018 02:37
Awesome. Thanks 😊
Hans W. Uhlig
@huhlig
May 10 2018 02:38
be aware you’re going to need to write your own bindings
I don’t know of anyone else who already has
Vyacheslav Kim (Kane)
@kanekv
May 10 2018 02:41

I've stumbled upon this in Vec::from_raw_parts:

Violating these may cause problems like corrupting the allocator's internal data structures. For example it is not safe to build a Vec<u8> from a pointer to a C char array and a size_t.

Is it because of jemalloc? I.e. this pointer will be freed by je_free which expects some metadata about this pointer?

Jarrett Billingsley
@JarrettBillingsley
May 10 2018 04:33
how to ask this... I'm porting a small lexer/parser from C++ to rust. in this parser I have a tagged union for tokens, which maps to an enum in rust. but each token has some information associated with it, and rather than scattering that all over the file, I'd like to keep it all in one place
I solved this in C++ with an X macro (and many years ago in D with some metaprogramming tricks), and I tried playing around with rust macros to do this but I don't think they have quite the expressive power to do what I want
Jarrett Billingsley
@JarrettBillingsley
May 10 2018 04:40
I'm probably way over-engineering this tbh
Jarrett Billingsley
@JarrettBillingsley
May 10 2018 04:49
since rust is actually smart and will tell me if I forget to add something if I add a token, it's probably not a big deal :P
trsh
@trsh
May 10 2018 10:15
Hi guys. Im working on some FFI for rust. Bringing some c lib to Rust. For now I have seen only examples on returning primitives (ints, floats, etc). How about an Extern Object (Struct). Any advice, docs and mostly example highly appreciated. Please :)
trsh
@trsh
May 10 2018 11:28
@ozkriff your pasted example return an primitive
int
I want to return a struct {xx : 1, yy: 2, ss: "aaaaaaa"}
I pointed that out very clearly in my question
or you can write bindings manually if you want - http://siciarz.net/ffi-rust-writing-bindings-libcpuid/
tandrysyawaludin
@tandrysyawaludin
May 10 2018 11:46
Hi, anyone know what kind of this error?
thread '<unnamed>' panicked at 'Received more than 4 bytes decoding i32. Was a BigInteger expression accidentally identified as Integer?
it was come when i try to call the API
Andrey Lesnikov
@ozkriff
May 10 2018 11:48
@tandrysyawaludin Maybe you need BigInt instead of Integer? (https://github.com/diesel-rs/diesel/issues/1194#issuecomment-331850160)
tandrysyawaludin
@tandrysyawaludin
May 10 2018 11:51
pub struct Supplier {
    pub id: i32,
    pub name: String,
    pub email: String,
    pub password: String,
    pub phone_number: String,
    pub created_at: i32
}
pub fn read(connection: &PgConnection) -> Vec<Supplier> {
        suppliers::table.order(suppliers::id).load::<Supplier>(connection).unwrap()
    }
this is my code. Where is that i have to change?
i did not use Integer like what you've said
trsh
@trsh
May 10 2018 11:55
@ozkriff I can detect the source of your surprisingness, but thanks for the materials. Will try to work on that.
segeljakt
@segeljakt
May 10 2018 12:40
Is someone here familiar with region inference?
Denis Lisov
@tanriol
May 10 2018 12:45
@tandrysyawaludin What are the column types in the database?
Andy Bell
@Andy-Bell
May 10 2018 12:45
@tandrysyawaludin i suspect that it may be the created_at value causing the issue - I assume as you are wanting it as an i32 you are storing it as the unix time on the db? if you are storing it as a DateTime value it will have a size of 8 bytes (if I remember correctly) and should be streamed to a chrono::DateTime or chrono::naive::NaiveDateTime struct
(just had to check that current unix time would fit into an i32)
trsh
@trsh
May 10 2018 12:48
How do you ignore such warning "structure field Minor should have a snake case name such as minor" for entire file?
Andrey Lesnikov
@ozkriff
May 10 2018 12:50
#![allow(non_snake_case)] - http://play.rust-lang.org/?gist=688442f56fb434e131d774cc8e363967 (or #![allow(bad_style)])
tandrysyawaludin
@tandrysyawaludin
May 10 2018 12:52
I use timestamp @tanriol
Andy Bell
@Andy-Bell
May 10 2018 12:54
timestamp is 8 bytes of data (at least on postgreSQL): https://www.postgresql.org/docs/9.5/static/datatype-datetime.html and would probably be better streamed to a chrono struct instead of an integer
(though assuming diesel handles timestamp -> integer, maybe changing it to an i64 would work)
tandrysyawaludin
@tandrysyawaludin
May 10 2018 12:58
oke i will try, thanks @Andy-Bell @tanriol
Denis Lisov
@tanriol
May 10 2018 12:58
By the way, diesel-cli has a diesel print-schema command that you can use to look what types Diesel would suggest...
tandrysyawaludin
@tandrysyawaludin
May 10 2018 12:59
i got this when i run that command created_at -> Nullable<Timestamp>,
Andy Bell
@Andy-Bell
May 10 2018 13:00
print-schema shows the db types, not rust types from memory
tandrysyawaludin
@tandrysyawaludin
May 10 2018 13:00
so, is it fit with DateTime or NaiveDateTime
?
Denis Lisov
@tanriol
May 10 2018 13:00
See Timestamp
NaiveDateTime or SystemTime if working with Postgres
Andy Bell
@Andy-Bell
May 10 2018 13:03
@tandrysyawaludin if you need the timezone offset - DateTime, if not, Naive. probably worth looking at the chrono docs for each : https://docs.rs/chrono/0.4.2/chrono/struct.DateTime.html and https://docs.rs/chrono/0.4.2/chrono/naive/struct.NaiveDateTime.html
most of the time i use naive - but i do not know your use case
tandrysyawaludin
@tandrysyawaludin
May 10 2018 13:15
what is this?
pub created_at: DateTime
   |                     ^^^^^^^^ expected 1 type argument
Denis Lisov
@tanriol
May 10 2018 13:16
Try DateTime<Utc>
prataprc
@prataprc
May 10 2018 13:32
Can pattern matching deal with smart pointers the way it deals with references & ?
we have ref and ref mut for references, do we have something like that for smart pointers ?
Zakarum
@omni-viral
May 10 2018 13:37
Why repr(align(X)) changes size of the type?
For instance. Here size_of::<Foo>() will return 8. And Bar::y will be placed at offset 8 when 4 would be optimal
#[repr(align(8))]
struct Foo(u32);

struct Bar {
  x: Foo,
  y: u32,
}
prataprc
@prataprc
May 10 2018 13:43
Rust documentation says:
More specifically, this is the offset in bytes between successive elements in an array with that item type including alignment padding.
Zakarum
@omni-viral
May 10 2018 13:44
But why insert unnecessary padding into struct?
prataprc
@prataprc
May 10 2018 13:45
How can we know whether Bar::y is placed at offset 8 ?
Pointer arithmetics
tandrysyawaludin
@tandrysyawaludin
May 10 2018 13:47
Why i got this
 #[derive(Serialize, Deserialize, Queryable, Insertable, AsChangeset)]
   |                                                         ^^^^^^^^^^^ the trait `diesel::AppearsOnTable<schema::suppliers::table>` is not implemented for `chrono::DateTime<chrono::Utc>`
John-John Tedro
@udoprog
May 10 2018 13:48
@omni-viral are you wondering why structs might be padded in general?
Zakarum
@omni-viral
May 10 2018 13:48
I wonder why strcut field is padded in this particular case
John-John Tedro
@udoprog
May 10 2018 13:49
@tandrysyawaludin serde is an optional feature for chrono, so you'll need something like chrono = { version = "0.4", features = ["serde"] } in your Cargo.toml.
I'm also not 100% sure it's implemented for that type, but at least make sure you have the above.
Zakarum
@omni-viral
May 10 2018 13:50
More specifically I wonder how to make this field to be not padded.
tandrysyawaludin
@tandrysyawaludin
May 10 2018 13:50
I hvae implement it
i have implemented it
prataprc
@prataprc
May 10 2018 13:50
Modified the snippet to use repr(packed) for Bar. But looks like it won't work with repr(align)
tandrysyawaludin
@tandrysyawaludin
May 10 2018 13:50
@udoprog
Zakarum
@omni-viral
May 10 2018 13:51
@prataprc Yeap, Tried that. packed can't have align fields
John-John Tedro
@udoprog
May 10 2018 13:51
@tandrysyawaludin my bad, that's a diesel type not implemented for a chrono type. Not sure about that one.
prataprc
@prataprc
May 10 2018 13:51
To me it looks like a side effect of using the offset between two successive values
tandrysyawaludin
@tandrysyawaludin
May 10 2018 13:52
what is version of diesel can be supported it? @udoprog
prataprc
@prataprc
May 10 2018 13:52
@omni-viral May be worth asking it in https://users.rust-lang.org/ or may be even internals-rust.lang.org
Andy Bell
@Andy-Bell
May 10 2018 13:53
@tandrysyawaludin if you are using utc - try using naivedatetime and see if that sorts your issues
tandrysyawaludin
@tandrysyawaludin
May 10 2018 13:54
i have tried it and this is an error
error[E0277]: the trait bound `chrono::NaiveDateTime: diesel::AppearsOnTable<schema::suppliers::table>` is not satisfied
@Andy-Bell
John-John Tedro
@udoprog
May 10 2018 13:57
@omni-viral If I'd speculate, I'd guess that size % align == 0 to make sure that arrays of the given struct are properly aligned.
Zakarum
@omni-viral
May 10 2018 13:58
@udoprog I guess this is the reason. Rust size synonymous with stride and stride % align == 0 must hold.
John-John Tedro
@udoprog
May 10 2018 13:59
Embedding that struct into another will have specific packing requirements as well: https://play.rust-lang.org/?gist=46ec086b771f7835653729a4e06e0b0d&version=stable&mode=debug
prataprc
@prataprc
May 10 2018 14:01
@omni-viral looks like it. rust-lang/rfcs#1397
Zakarum
@omni-viral
May 10 2018 14:08
@prataprc Indeed
tandrysyawaludin
@tandrysyawaludin
May 10 2018 14:22
how to set nullable struct?
Denis Lisov
@tanriol
May 10 2018 14:23
For Diesel? Most likely, Option...
tandrysyawaludin
@tandrysyawaludin
May 10 2018 14:24
like this Option<Assocc<T>>?
it is for Timestamp?
Denis Lisov
@tanriol
May 10 2018 14:25
Option<NaiveDateTime> or something like that
tandrysyawaludin
@tandrysyawaludin
May 10 2018 14:25
i see, thanks
Kevin Choubacha
@kbacha
May 10 2018 21:53
anyone notice an issue with cargo fmt since the 1.26 upgrade? I have a r# string that appears to get indented over and over again:
https://travis-ci.org/kbacha/stellar-sdk/builds/377478444?utm_source=github_status&utm_medium=notification
It appears to be only when inside a macro from my quick testing
Kevin Choubacha
@kbacha
May 10 2018 22:13
opened ticket: rust-lang-nursery/rustfmt#2695