These are chat archives for rust-lang/rust

19th
Dec 2018
Ali Shirvani
@alishir
Dec 19 2018 06:23

Hi all, I want to create simple generic type enum that contains generic type elements such as:

enum Message<T> {
     Request<T>,
     Response<T>
}

but I couldn't figure out how can I create this enum.

Proton
@feisuzhu
Dec 19 2018 06:25

You mean

enum Message<T> {
     Request(Request<T>),
     Response(Response<T>),
}

?

aohan237
@aohan237
Dec 19 2018 09:12
when should rust be compiled? compiled when code done? or when you publish your code to server,which compiled on server??
Michal 'vorner' Vaner
@vorner
Dec 19 2018 09:35
@aohan237 What exactly are you asking? Certainly, both can be done. But for example, in my company, we compile it on a CI server, make .rpm packages out of it and install on the production servers.
aohan237
@aohan237
Dec 19 2018 09:43
yeah,thanks..just want to ask how you guys doing this job?
searching for a best practice...
Michal 'vorner' Vaner
@vorner
Dec 19 2018 09:46
A docker image based on the OS the servers run, with rust installed into it for compilation. The packaging happens in another docker, with an in-house tool that does the packaging (that's probably not best-practice, it just fits into what we already have here for software in other languages). But for some packages, there are rust-specific tools (eg. cargo-deb).
aohan237
@aohan237
Dec 19 2018 09:52
yeah,thank you~
so all your service are based on docker
Michal 'vorner' Vaner
@vorner
Dec 19 2018 09:54
No, the real service actually runs normally inside the OS (well, at least the Rust service we have right now). Only the build happens in docker, but the docker is based on the same distro ‒ to use the same OpenSSL version and such as the target server will have.
Tim Robinson
@1tgr
Dec 19 2018 09:55
I do the build in Docker, but because the binary is statically linked (no dependencies), I copy it and run it directly
I don’t think there’s a single best practice and it’s not a question that’s specific to Rust
aohan237
@aohan237
Dec 19 2018 09:58
yeah,from both of you,built in docker seems the best practice in some way
@1tgr but as @vorner said, openssl will have the dependency issue
if they have different versions
Ali Shirvani
@alishir
Dec 19 2018 10:22
@feisuzhu thanks a lot.
Zakarum
@omni-viral
Dec 19 2018 11:17

Why can't implementation of trait remove unsafe from function?
Consider this example


trait Trait {
    /// # Safety. `x` must not be `0`.
    unsafe fn foo(&self, x: usize);
}

struct Foo;

impl Trait for Foo {
  /// Actually works even if `x` is `0`.
  fn foo(&self, x: usize) { ... }
}

But rustc disallow this

Michal 'vorner' Vaner
@vorner
Dec 19 2018 12:12
Traits need the exact same signature. I guess it's mostly not to create too much confusion, because then you could call foo safely if you passed the exact type but not in generics, which would be a mess. But you certainly can have foo_safe on Foo itself and call that (even from the unsafe fn foo)
Zakarum
@omni-viral
Dec 19 2018 12:14
I know that implementation can relax trait bounds on type parameters. So it is already not exactly the same signature
You couldn't call Foo::foo safely this way.
Sylwester Rąpała
@xoac
Dec 19 2018 12:56
Would u accept this in your code? Why, why not?
.for_each(|_| Ok(trace!("Some part sent")))
Zakarum
@omni-viral
Dec 19 2018 13:01
No. It doesn't compile
Michal 'vorner' Vaner
@vorner
Dec 19 2018 13:07
@xoac Depends on situation, in PoC probably yes, but in some code with a chance to be read half a year from now, I'd vote for something less cryptic and more readable.