These are chat archives for rust-lang/rust

15th
May 2019
Ghost
@ghost~5cdaf1b4d73408ce4fc0438e
May 15 05:57
is it possible to develop gui using html css and rust since rust support web rendering engine
Nopey Nope
@Nopey
May 15 05:58
GUI inside of a desktop application?
Ghost
@ghost~5cdaf1b4d73408ce4fc0438e
May 15 05:58
yes
Nopey Nope
@Nopey
May 15 05:58
I think the easiest way would be to embed a rust lib inside an electron app
but embedding servo would certainly be cooler:tm:
Ghost
@ghost~5cdaf1b4d73408ce4fc0438e
May 15 06:02
any other option
Nopey Nope
@Nopey
May 15 06:04
Too many to count.. You could even do the transmission-web thing and make a desktop application's interface a webserver that is opened in the browser. Maybe you can be more specific about what you want?
Ghost
@ghost~5cdaf1b4d73408ce4fc0438e
May 15 06:17
sciter gui help to develop gui using html and css by using c++/c/rust but sciter is not completely free
like sciter gui is it possible to develop gui using web rendering technology in rust
Siddhant Sanyam
@siddhant3s
May 15 08:46
Does anyone uses a Rust REPL?
Denis Lisov
@tanriol
May 15 08:54
Tried one, but not really used... just checked that the basics worked.
matrixbot
@matrixbot
May 15 10:24
moltonel I use evcxr from time to time, to figure out one- or two-liners. And cargo-script for a few small utilities.
David O'Connor
@David-OConnor
May 15 13:26

Serde custom serialization question: In this case, converting an integer to an enum. I've looked through the docs and examples, but none quite seem right. Here's what I think is the closest:

impl<'de> Deserialize<'de> for MyEnum {
    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
        where D: Deserializer<'de>
    {
        let s = String::deserialize(deserializer)?;
        Ok(match s.as_str() {
//        Ok(match s {
            "0" => MyEnum::A,
            "1" => MyEnum::B,
            "2" => MyEnum::C,
            _ => MyEnum::D,
        })
    }
}

Is this the right approach that requires a tweak, or do I need to use Visitors etc?

Ingvar Stepanyan
@RReverser
May 15 13:27
do you really have a stringified number as an input?
David O'Connor
@David-OConnor
May 15 13:27
Yep!
Ingvar Stepanyan
@RReverser
May 15 13:27
:/
David O'Connor
@David-OConnor
May 15 13:28
How would you represent an Enum/choice in a databas?
Ingvar Stepanyan
@RReverser
May 15 13:29
What I mean is, if you had it as a regular number, it could've been a bit easier.
David O'Connor
@David-OConnor
May 15 13:29
It is
Ingvar Stepanyan
@RReverser
May 15 13:29
Did you try something like u32::deserialize instead?
David O'Connor
@David-OConnor
May 15 13:29
I mean it gets passed as aJSON string
Ingvar Stepanyan
@RReverser
May 15 13:29
Ah, then it should work.
matrixbot
@matrixbot
May 15 13:30

moltonel > <@gitter_david-oconnor:matrix.org> How would you represent an Enum/choice in a databas?

https://www.postgresql.org/docs/current/datatype-enum.html ?

Ingvar Stepanyan
@RReverser
May 15 13:30
And then, if such manual integer-to-enum conversion does work, you can switch to https://github.com/dtolnay/serde-repr for derives.
David O'Connor
@David-OConnor
May 15 13:31
Much apprec, gotta run for now. May even switch backend to that. Will attempt u32:deserialize after work
Victor Lopes
@vlopes11
May 15 14:49

Hello Rustaceans.

I need to transpose a String to a delimited bytes slice in the stack. There is a way to do it that I absolutely don't like. Is there anything more idiomatic?

fn main() {
    let mut s: [u8; 4] = [0; 4];
    let text = String::from("abcd");
    text
        .as_str()
        .bytes()
        .take(4)
        .enumerate()
        .for_each(|(i, b)| s[i] = b);
    dbg!(s);
}
Ingvar Stepanyan
@RReverser
May 15 15:08
s.copy_from_slice(text.as_bytes()) ?
Victor Lopes
@vlopes11
May 15 15:21
@RReverser Yep, that will do, thanks
Ingvar Stepanyan
@RReverser
May 15 15:39
Btw, if you want to check the string size too, another way is to use TryFrom
Ichoran
@Ichoran
May 15 17:50

@siddhant3s - I use evcxr also, but only rarely because I find using it embedded in jupyter is more convenient. (It uses the same engine under the hood.) I haven't found it to be as useful as, say, the Scala repl (or ammonite), or the Python one, due to the limitations. The primary limitation that bothers me is this one:

Since each line is compiled as a separate crate, impls generally need to go on the same line as the type they're for.

Siddhant Sanyam
@siddhant3s
May 15 17:55
@lchoran I see. That does seems to be a strong limitation which can make REPL far less fun to use. Ammonite is really awesome, so is IPython. But Rust is a non-interpreted language so I guess it's a bit unfair to ask Rust to have a REPL.
Ichoran
@Ichoran
May 15 18:07
Scala is also a non-interpreted language, but Rust's choices to improve safety as a standard compiled language have made it not work so well for a repl.
But it's still not so bad using play.rust-lang.org or a Jupyter notebook.