These are chat archives for rust-lang/rust

24th
Apr 2018
Zakarum
@omni-viral
Apr 24 2018 10:44
Is there a way to transmute &mut Foo to the &mut Bar for struct Bar(Foo, PhantomData<Baz>) without UB?
Andrey Gridchin
@Gedweb
Apr 24 2018 12:14
@omni-viral you can do it via raw pointer inside unsafe block, of course. Look example inside std::any::Any::downcast_mut() source
Michal 'vorner' Vaner
@vorner
Apr 24 2018 12:15
But the question was if it is or isn't UB ‒ is there anything that promises Foo and Bar will have the same in-memory representation?
Bryan Burgers
@bryanburgers
Apr 24 2018 12:43
What does UB mean?
Michal 'vorner' Vaner
@vorner
Apr 24 2018 12:43
Undefined Behaviour.
Bryan Burgers
@bryanburgers
Apr 24 2018 13:07
Thanks.
Dylan DPC
@Dylan-DPC
Apr 24 2018 13:10
lol i thought unsafe block :D
This message was deleted
Do Duy
@juchiast
Apr 24 2018 13:22
@omni-viral https://doc.rust-lang.org/reference/type-layout.html
This section looks helpful
Zakarum
@omni-viral
Apr 24 2018 13:28
@juchiast Thanks. Looks like for my example there is no guarantees. Yet no other reasonable options
Denis Lisov
@tanriol
Apr 24 2018 13:29
@omni-viral Is adding the corresponding accessor or impl DerefMut not an option?
Zakarum
@omni-viral
Apr 24 2018 13:30
@tanriol I want to convert field type to the type strucutre that has only that field and zero-sized field
Not the other way around which can be done with accessor
Denis Lisov
@tanriol
Apr 24 2018 13:31
Sorry, misread. Without moving it, I assume?
Zakarum
@omni-viral
Apr 24 2018 13:31
Yes
I want to transmute reference, use it and leave object in place
Denis Lisov
@tanriol
Apr 24 2018 13:38
Sounds like #[repr(transparent)], which is not stable yet...
Michal 'vorner' Vaner
@vorner
Apr 24 2018 13:38
I think going through the guarantees, something could be deduced from them. It says an outer struct can't change representation of inner field. So, if you assert that both the outer and inner have the same size & alignment, that should guarantee the outer one has the same repr. as the inner one. But I'm not a compiler-lawyer, so there might be a problem in the deduction.
Zakarum
@omni-viral
Apr 24 2018 15:19
@vorner That's actually makes a lot of sense
Michal 'vorner' Vaner
@vorner
Apr 24 2018 16:32
Only slightly related to Rust, but… does anyone know of something like mdbook, but for presentations/slides? I want code snippets and images there ‒ and I can do that with beamer, but that's far from comfortable.
Ingvar Stepanyan
@RReverser
Apr 24 2018 16:35
If you mean generally Markdown-as-slides, there's plenty of solutions. Or are you looking for something specific?
Michal 'vorner' Vaner
@vorner
Apr 24 2018 16:38
I've looked through something markdown-as-slides, but I didn't manage to make anything work. Most of them are either some kind of editors bundled with something, web services… or require non-trivial setup. On the other hand, mdbook Just Works. I don't really need markdown, per se, but something that I can put into git, generate PDF or something from it and is able to include code (with colorful highlighting) and has some way to put images and diagrams in. What do people use when they give talks on rustfests or other conferences?
Ingvar Stepanyan
@RReverser
Apr 24 2018 16:44
remark, reveal.js, etc. are fairly popular and worked with no issues for me
well there were some probably but I don't remember :)
not sure what you mean when saying "bundled with something, web services" - these are all just literally tools where you can put markdown and they will render as slides
Dylan DPC
@Dylan-DPC
Apr 24 2018 16:44
let's build one ;)
Ingvar Stepanyan
@RReverser
Apr 24 2018 16:45
yet another one? nah, there is too many already so it's hard to choose from :D
Ed Page
@epage
Apr 24 2018 16:52
Avoiding npm is a good enough reason to me ... if my attention wasn't already too divided
Michal 'vorner' Vaner
@vorner
Apr 24 2018 16:52
Maybe I do something wrong about them. But both remark and reveal.js seem to talk about html. I was thinking more about something command line ‒ running tool stuff.md and stuff.pdf would get out. But I'll try to read through the docs some more.
Ingvar Stepanyan
@RReverser
Apr 24 2018 16:55
well yeah they render markdown without explicit conversion, but still that allows you to save as PDF from the browser if you want version w/o animations etc.
(they have corresponding styles for "print" version so that PDF will look as clean as presentation on screen)
@epage who said anything about npm?
as https://github.com/gnab/remark README shows, you literally put your Markdown into provided HTML template and host it anywhere you want, or just open as file in the browser. anything works.
Ed Page
@epage
Apr 24 2018 16:58
Ok, was looking into how to use it, went to see what its command line was like, and it used npm. Didn't know it was that straightforward
Michal 'vorner' Vaner
@vorner
Apr 24 2018 17:00
Thanks, I'll try looking at it.
Sylwester Rąpała
@xoac
Apr 24 2018 17:00
I don't know nothing about code highlight :(
David Harvey-Macaulay
@alteous
Apr 24 2018 20:30
Any web people around? I'm unfamiliar with the idea behind XMLHttpRequest. Is it different to a HTTP request? I'm wondering whether it is possible to write the following in Rust:
<script>
    function $(e){if(typeof e=='string')e=document.getElementById(e);return e};
    function collect(a,f){var n=[];for(var i=0;i<a.length;i++){var v=f(a[i]);if(v!=null)n.push(v)}return n};

    ajax={};
    ajax.x=function(){try{return new ActiveXObject('Msxml2.XMLHTTP')}catch(e){try{return new ActiveXObject('Microsoft.XMLHTTP')}catch(e){return new XMLHttpRequest()}}};
    ajax.serialize=function(f){var g=function(n){return f.getElementsByTagName(n)};var nv=function(e){if(e.name)return encodeURIComponent(e.name)+'='+encodeURIComponent(e.value);else return ''};var i=collect(g('input'),function(i){if((i.type!='radio'&&i.type!='checkbox')||i.checked)return nv(i)});var s=collect(g('select'),nv);var t=collect(g('textarea'),nv);return i.concat(s).concat(t).join('&');};
    ajax.send=function(u,f,m,a){var x=ajax.x();x.open(m,u,true);x.onreadystatechange=function(){if(x.readyState==4)f(x.responseText)};if(m=='POST')x.setRequestHeader('Content-type','application/x-www-form-urlencoded');x.send(a)};
    ajax.get=function(url,func){ajax.send(url,func,'GET')};
    ajax.gets=function(url){var x=ajax.x();x.open('GET',url,false);x.send(null);return x.responseText};
    ajax.post=function(url,func,args){ajax.send(url,func,'POST',args)};
    ajax.update=function(url,elm){var e=$(elm);var f=function(r){e.innerHTML=r};ajax.get(url,f)};
    ajax.submit=function(url,elm,frm){var e=$(elm);var f=function(r){e.innerHTML=r};ajax.post(url,f,ajax.serialize(frm))};

    ajax.get( "__restart", function(){} );
</script>
Please excuse the formatting. I'm reverse-engineering this code for personal use. :)
So far, I have tried making a regular HTTP request with the reqwest crate. That didn't do anything, although the request succeeded.
extern crate reqwest as request;

const HOST_ADDRESS: &'static str = "http://192.168.0.10:42000";
const PROJECT_PATH: &'static str = "projects/Hall Of Mirrors II v0.1";

fn main() {
    let client = request::Client::new();
    let file_name = "Main";
    let url = format!("{}/{}/{}", HOST_ADDRESS, PROJECT_PATH, file_name);
    client
        .get(&url)
        .body("__restart")
        .send()
        .expect("Failed to send");
}