These are chat archives for rust-lang/rust

May 2018
Ed Page
May 02 2018 03:18
Anyone know how to convert from one Serialize type to another?
serde_transcode seems focused on serialization formats.
Kelly Thomas Kline
May 02 2018 03:32
Is it possible to, using a Cargo file key or otherwise, configure a project to refuse to build if the project or any of its dependencies use unsafe?
Ravi Shankar
May 02 2018 04:28
Ed, one Serialize type to another? Like, integer to string?
Ed Page
May 02 2018 13:20
@wafflespeanut yeah, integer to string is one example of something that is feasible. In my case, I'm wanting to convert from a struct to something like a json::Value
Dimitri Sabadie
May 02 2018 13:33
hey there
Ravi Shankar
May 02 2018 13:40
@epage I'm not sure if there's a generic type for that. Value is specific to an encoding format. There's a Value enum in all serde-based encoding crates (JSON, TOML, etc.) because the serializers and deserializers differ on what they accept, no?
Ed Page
May 02 2018 13:42
They do differ but I was but most types can be converted to any of those value types. For example, I could convert my struct to json and then back to json::Value. I'm assuming there is a reasonable way to do this type coercion without going all the way to a serialization format, kind of like how serde_transcode allows you to convert between serialization formats without loading an in-memory representation.
Michal 'vorner' Vaner
May 02 2018 13:43
I'm not aware if there's such thing, but I believe it could be written (actually, I've been thinking on writing that). Have you checked you can't use serde_transcode in this inside-out way somehow?
Also, there's a serde IRC channel somewhere, you may get a more specific answer there
Ed Page
May 02 2018 13:44

At least when reading transcode docs and looking at the types, it seems like it only works with formats and not types.

Bleh, hate having to get on IRC but maybe thats what I'll have to do

Ravi Shankar
May 02 2018 13:46
#rust IRC channel could be of great help at times!
Ed Page
May 02 2018 13:48
Just not enjoyed Mibbit and haven't take the time to research installed clients
Diggory Blake
May 02 2018 13:48
irccloud is quite nice
Dale Wijnand
May 02 2018 18:50
anyone know how to get rustc not to output "method is never used" type warnings?
Hans W. Uhlig
May 02 2018 18:50
This message was deleted
or #[allow(dead_code)] before the method
Dale Wijnand
May 02 2018 18:59
thank you, hadn't understood the difference of having ! or not
Hans W. Uhlig
May 02 2018 19:02
! means the surrounding entity
without it means the next entity
Dale Wijnand
May 02 2018 19:08
right. I just hadn't given rustc the time of day and actually read its "error: an inner attribute is not permitted following an outer attribute" message :)
May 02 2018 19:29
hi all I have a very weird bug. I am using ssh2 crate to send a binary file across our lab server.
it seems to work for plain text files. when I trying to send a binary file a.war file the content sizes differ all together. any reasons ? Below is the snippet of code that I use! any ideas?

extern  crate ssh2;
extern crate byteorder;

use std::net::TcpStream;
use std::path::Path;
use ssh2::Session;

use std::io::prelude::*;
use std::fs;
use std::fs::File;
use std::io::BufReader;
use byteorder::{ReadBytesExt, NativeEndian};

fn main() {
    println!("Hello, world!");

fn connect_to_server() {

    // Almost all APIs require a `Session` to be available
    let sess1 = Session::new().unwrap();
    let mut agent = sess1.agent().unwrap();

// Connect the agent and request a list of identities

    for identity in agent.identities() {
        let identity = identity.unwrap(); // assume no I/O errors
        println! ("{}", identity.comment());
        let pubkey = identity.blob();

    let tcp = TcpStream::connect("host:22").unwrap();
    let mut sess = Session::new().unwrap();

    let file_name = "a.war";

    let file_size = fs::metadata(file_name).expect("could not get file meta data").len() as usize;

    let file = File::open(file_name).expect("failed to open file");
    let mut buf_reader = BufReader::new(file);

    let mut buffer: Vec<u8> = Vec::with_capacity(file_size);
    println! ("file_size {}",  file_size as u64,);
    buf_reader.read_to_end(&mut buffer).expect("failed to read");

    let mut remote_file = sess.scp_send(Path::new(file_name),
                                        0o644, file_size as u64, None).unwrap();

    remote_file.write( buffer.as_mut_slice()).unwrap();

James McCoy
May 02 2018 19:43
Posting a link to would be move convenient
May 02 2018 19:44
@jamessan sure I would that next time onward thanks!