These are chat archives for rust-lang/rust

6th
Mar 2019
mmynsted
@mmynsted
Mar 06 00:47
I have been writing csv files with Rust and now am thinking that a bit more robust markup would be useful. I see LaTeX, and PDF, etc. Something like markdown with tables seems ideal. What should I be looking for?
Joey
@OddCoincidence
Mar 06 05:44

Anybody know why this isn't allowed:

impl Box<MyType> {
    fn test(self) {
    }
}

but this is:

impl MyType {
    fn test(self: Box<Self>) {
    }
}
Sylwester Rąpała
@xoac
Mar 06 10:06
Is it possible to dynamically match struct in Rust? Here is example https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=8261e2d2e464e5e36026d60df880f02d

@OddCoincidence MyTypecan impl functions that can take whatever they want(second code). You can't implement things for types you don't own. So u can't implement sth for Box.

The workaround for that can be a trait you own. Then u can implement it for any type:

impl MyTrait for Box<MyType> {
    fn test(self) {
    }
}
Tim Robinson
@1tgr
Mar 06 10:11
The ability to do self: Box<Self> is compiler magic
Zakarum
@omni-viral
Mar 06 10:17
@xoac No, match pattern can't accept values. It always constants with bindings
You can use guard though
match <expression> {
  <pattern> if <predicate> => {}
}
Sylwester Rąpała
@xoac
Mar 06 10:19
@omni-viral Thank you. Doc. Love Rust for that everything I want it contains <3
Ingvar Stepanyan
@RReverser
Mar 06 13:23
@xoac you can do what you did in your initial example too, just need to reorder branches
Sylwester Rąpała
@xoac
Mar 06 13:27
@RReverser No it's not what I wanted. The part _ is unracheble() and first a is unused I wanted use guard as mentioned before.
Ingvar Stepanyan
@RReverser
Mar 06 13:28
(shrugs) well, that's what you showed
Sylwester Rąpała
@xoac
Mar 06 13:29
Yep I din't know about guards and by a: a I wanted to use feature a: 7 so just check if MatchTest.a has the same value as main.a
mmynsted
@mmynsted
Mar 06 16:49
I have been search through crates.io. I am looking for a crate that I can use to create either a completely static web (page), or a structured document. The key is that I have data in structs that I wan to serialize as tables and other structures. I can serialize them to CSV or other formats (provided by serde) but want something to help create a useful document or html page.
Any recommendations.
I looked for something to generate markdown, and did not find anything. What I found I would be writing the markdown directly in strings. Seems like there would be something with an AST.
manybe I need to check into the pandoc crates
Ichoran
@Ichoran
Mar 06 20:05
@mmynsted - I always have Rust generate text and use an external tool to process it (pandoc, for instance). I generally find that the few data structures I want to serialize to a viewable format require custom formatting such that an automated derivation wouldn't help anyway, but maybe that's not true for you. If you can do it automatically, maybe you should consider serializing to a JSON AST and then prettyprinting that.
So it's not actually a solution, but that's the best I can offer.
Joey
@OddCoincidence
Mar 06 20:06
@xoac Thanks for answering, I'm more just wondering why you can't have an inherent impl for ExternalType<LocalType> since the boxed-self syntax suggests to me that this would be a sound thing to allow.
Sylwester Rąpała
@xoac
Mar 06 21:34
@OddCoincidence Would you like if other people could implement sth for your type? I think this is fine. You can own trait and implement it for every type. So u have a easy workaround and no conflict with other people ;)
I don't know this is allowed to link here but I just created my first open-source project. Would like to hear it could be useful? Idea is to work like this sink.backup_on_disk(stream, "dir").expected("working filesystem") and even if your program has to be closed all data will be save on disk even if sink (that represent for example internet connection) couldn't flush data at this moment.
Brian Knapp
@knappador
Mar 06 22:22
I've used Circle in the past for CI. I see some Travis out there. I don't know who Travis is. Can I trust them or should I just stick with Circle since it's a computer?
Sylwester Rąpała
@xoac
Mar 06 22:26
@knappador is your personal project or public?
Ichoran
@Ichoran
Mar 06 22:26
Circle seems to have a prebuilt container for Rust: https://circleci.com/docs/2.0/circleci-images/#rust
Though their docs and walkthroughs don't seem to say much about Rust support.
kylegoetz
@kylegoetz
Mar 06 23:17
I'm trying to check if a Vec<u8>'s length is equal to 4lengthheight of an image. my_vec.len()==4lh gives me a type mismatch error re usize and u32. How do I get around this? Seems like I should be just comparing two integers, but I admittedly haven't coded in a language where there are different types of integers in a long time :D
4*length*height I mean. Sorry about the formatting.
Ichoran
@Ichoran
Mar 06 23:18
Use backticks (`) for code to avoid having it try to apply markdown formatting to your multiplication and stuff :)
Lengths are usize. You can do something like 4*(length as usize)*(height as usize)
kylegoetz
@kylegoetz
Mar 06 23:20
Thank you double.
Ichoran
@Ichoran
Mar 06 23:20
Usually usize is u64--depends on the architecture--but it is its own type.
kylegoetz
@kylegoetz
Mar 06 23:21
Why does len have to be a usize, is it because the number of elements in a vector is directly related to something about the architecture?
I guess whether it's a 64-bit or 32-bit OS or something?
Ichoran
@Ichoran
Mar 06 23:21
Right