These are chat archives for rust-lang/rust

5th
Aug 2018
qq00
@qq00
Aug 05 2018 00:24
Is the following correct:
Arrays: Immutable, fixed size
Vectors: Mutable, will autogrow
Slice: subsection of a vector, 'shares' memory, so writing to one will modify the underlying vector.
qq00
@qq00
Aug 05 2018 01:13
use stdweb::web::{ArrayBuffer, TypedArray};
use std::mem::transmute;

pub fn to_array_buffer<T>(v: Vec<T>) -> ArrayBuffer {
    let vs: &[T] = v.as_slice();
    let bytes: &[u8] = unsafe { transmute(vs) };
    let ans = <TypedArray<u8> as From<&[u8]>>::from(bytes).buffer();
    ans
}
Are all of the above lines O(1), or is there a linear copy going on somewhere?
Tim McNamara 🐍🦀
@timClicks_twitter
Aug 05 2018 02:19
@qq00 you could also use Vec::from_raw_parts() https://doc.rust-lang.org/std/vec/struct.Vec.html#method.from_raw_parts that way you know that you'll only be working with pointers
slices are implemented as pointers within the assembly language
so there shouldn't be a copy happening here
Andrey Lesnikov
@ozkriff
Aug 05 2018 05:26
@tsoernes check your Cargo.lock to see which dependency uses rand 0.4, then either upgrade it, or downgrade your own rand dep
Tim McNamara 🐍🦀
@timClicks_twitter
Aug 05 2018 05:51
can anyone recommend some videos about dyn Trait?
tandrysyawaludin
@tandrysyawaludin
Aug 05 2018 10:27
@ozkriff for return the result not print
Andrey Lesnikov
@ozkriff
Aug 05 2018 10:35
escape characters don't exist in the String itself, they are just added by Debug trait when you're printing the value
Also see the docs of escape_debug and escape_default methods of char type
tandrysyawaludin
@tandrysyawaludin
Aug 05 2018 10:53
so, the best way is using regex or there is another way?
Andrey Lesnikov
@ozkriff
Aug 05 2018 10:59
I'm not sure that I understand what is the exact problem that you are trying to solve here. You have a string with '\"' chars in it. They are dynamically escaped when you print them out with Debug trait, but why does it matter to you? If you print the string as is - there will be no escape characters added.
tandrysyawaludin
@tandrysyawaludin
Aug 05 2018 11:03
"email": "\"2aa@.a\"",
here my result
what i want is
"email": "2aa@.a",
i wanna return it for API
Andrey Lesnikov
@ozkriff
Aug 05 2018 11:07
so you want to trim the quotes from the string, like this https://play.rust-lang.org/?gist=4373ecc1c0823e66c2110e30edf02a77 ?
tandrysyawaludin
@tandrysyawaludin
Aug 05 2018 11:13
okay, it works, thank you @ozkriff
tandrysyawaludin
@tandrysyawaludin
Aug 05 2018 13:11
#[post("/auth", data = "<supplier>", format = "application/json")]
fn auth_supplier(
  supplier: Json<AuthSupplier>,
  connection: database::db_setting::Connection,
) -> Json<Value> {
  println!("{:?}", supplier);
}
how to get headers from client-request?
qq00
@qq00
Aug 05 2018 16:53
Is there a way o tell Rust "cargo check" to be maximally verbose with borrow checker analysis?
qq00
@qq00
Aug 05 2018 20:12
In Rust, is there a way to define a macro/function that is Type -> value

so something where

Foo<Vec3> -> 3
Foo<Vec2> -> 2
Foo<Vec4> -> 4
Foo<Color3> -> 3

Andrey Lesnikov
@ozkriff
Aug 05 2018 20:20
qq00
@qq00
Aug 05 2018 20:22
How are you able to make the function cal without an instance of u8 or f32 ?
Andrey Lesnikov
@ozkriff
Aug 05 2018 20:23

Is there a way o tell Rust "cargo check" to be maximally verbose with borrow checker analysis?

I don't think so. I'd say that rust lifetime errors are really verbose by default) What exactly is your problem with error messages?

qq00
@qq00
Aug 05 2018 20:24
I don't have a < 40 line minimal failure example yet (currently at ~500 lines), I need to create a minimal example first.