These are chat archives for rust-lang/rust

23rd
Feb 2019
earthengine
@earthengine
Feb 23 02:52
I am writing a simple console application that supports various commands. Are there an easy way to support command line history (through up and down keys) and coloring text output? ncurses is not in consideration as it does not support Windows (I mean powershell).
matrixbot
@matrixbot
Feb 23 03:21
bspeice Readline is typically how shells handle this; there are a couple implementations available in Rust.
bspeice I haven't tried it personally, but something in the realm of https://github.com/kkawakam/rustyline should be what you're looking for.
earthengine
@earthengine
Feb 23 05:12
OK I can try
tsoernes
@tsoernes
Feb 23 09:12
str.as_bytes() is a zero copy operation, yes? since it returns a slice?
Tim Robinson
@1tgr
Feb 23 09:29
Yep
uncotion
@uncotion
Feb 23 09:53

Hello, my dear friends.
Could you please help me to find the best GUI library for a cross platform application that have a web interface too?
1- Our development team is small and we can not use separately use multi native interfaces,
2-qt and gtk are good but they have overhead, our program isn't really big and these libraries take many storage and ram.
3- electron has overhead too and webview hasn't support web-assembly (our web interface uses yew), today I saw someone talked about deskgap in users.rust-lang, it supports web-assembly but it does not support Linux.

I highly welcome your suggestions.💐

Kelly Thomas Kline
@kellytk
Feb 23 12:40
How can a &Vec<u32> be taken from HashMap keys()?
Denis Lisov
@tanriol
Feb 23 13:10
Not sure I understand what you want, but you can collect them into a Vec and take a reference to it.
Kelly Thomas Kline
@kellytk
Feb 23 14:01
Do you know why collect of foo.keys().collect() generates the error https://ghostbin.com/paste/7sdmu ?
Denis Lisov
@tanriol
Feb 23 14:09
Missing .cloned()?
Kelly Thomas Kline
@kellytk
Feb 23 14:12
I don't believe so, I had tried it. Where were you thinking?
Denis Lisov
@tanriol
Feb 23 14:13
foo.keys().cloned().collect()
But: you won't be able to collect into a &Vec<u32>. You need to collect into a Vec<u32> and then take a reference to it.
Kelly Thomas Kline
@kellytk
Feb 23 14:16
Oh, right. Thank you
Denis Lisov
@tanriol
Feb 23 14:20
Why do you actually need a &Vec<u32>? This is a type that's rarely useful...
Kelly Thomas Kline
@kellytk
Feb 23 15:04
I tried stripping it off and I was able to
I've encountered a borrow error I can't work around with the usual NLL hack https://ghostbin.com/paste/kseof how can it be resolved?
Denis Lisov
@tanriol
Feb 23 15:30
Requires refactoring. What are you trying to do?
Kelly Thomas Kline
@kellytk
Feb 23 15:31
By refactoring does that mean I'll need to remove the self argument from work? What I'm trying to do is have the code of foo run repeatedly on a timer and within its body make a call to work
The problem line is 4 because without that loop the code checks fine
Denis Lisov
@tanriol
Feb 23 15:35
I don't know what do you want to do with this code. Thus I cannot really recommend the best refactor. Maybe you need to remove self from work, or to move the for hashmap in test.hashmaps.values_mut() into work, or something else entirely.
Kelly Thomas Kline
@kellytk
Feb 23 15:39
What is the cause of the error? I can read it of course but why would test be borrowed by line 4? Is the values_mut() the source?
Denis Lisov
@tanriol
Feb 23 15:40
It mutably borrows test.hashmap, which is a part of test.
Kelly Thomas Kline
@kellytk
Feb 23 15:40
Ok
tsoernes
@tsoernes
Feb 23 17:50
What is the reason that HashMap.get and get_mut both take a reference to the key while entry takes ownership?
(I'm just trying to get a grasp on API design)
Denis Lisov
@tanriol
Feb 23 17:51
entry may need the owned version of the key for or_insert