These are chat archives for rust-lang/rust

3rd
Aug 2018
error[E0283]: type annotations required: cannot resolve `_: applications::api::externapis::fedex::ship::ProcessPointersToJson`
  --> manu/src/applications/api/externapis/fedex/ship.rs:70:41
   |
70 |             let MessageParameters_res = ProcessPointersToJson::get_ns1__NotificationParameter(array_item);
   |                                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
I dont understand this error
Ok never mind

I have:

fn is_gl_error(value: &Value) -> bool {
    match value {
        Value::Number(n) => n == 0,
        _ => true
    }
}

I get error:

   |
46 |         Value::Number(n) => n == 0,
   |                               ^^ no implementation for `&stdweb::Number == {integer}`
   |
   = help: the trait `std::cmp::PartialEq<{integer}>` is not implemented for `&stdweb::Number`

How do I compare a stdweb::Number with 0 ?

Denis Lisov
@tanriol
Aug 03 2018 10:31 UTC
Does it work with *n == 0?
*n == 0 fixed it -- how ?
Zakarum
@omni-viral
Aug 03 2018 10:59 UTC
n is a reference. Namely &stdweb::Number. But only stdweb::Number implements PartialEq<{integer}>
So you need to dereference it obviously
'obviously' :-)
Zakarum
@omni-viral
Aug 03 2018 11:01 UTC
¯\_(ツ)_/¯
Rust 'references' confuses me, as C/C++/Java refs can be used "just like values", but then Rust 'refs' have to be de-refed, like C/C++ ptrs ?
well, and 'value' here means something else in Rust
'value' seems to mean "ownership of object"
Zakarum
@omni-viral
Aug 03 2018 11:02 UTC
Yes. & in rust are more like pointers in C except they are checked to be valid
I really like the interplay of RAII/destructors/explicit lifetimes. There's something nice here, even though I can't formlly define what it is.
Zakarum
@omni-viral
Aug 03 2018 11:04 UTC
lifetime is similar to the concept from C but actually appears in code
That's make it great since it can be checked by compiler
And user can reason about it locally

I have:
src/foo/bar/a.rs
src/foo/bar/b.rs

both foo::bar::a and foo::bar::b are "loaded" via "mod" in a bunch of mod.rs files

quetsion: in foo/bar/b.rs, how do I refer to objects in foo/bar/a.rs WITHOUT using full paths, i.e. foo::bar::a::...

I'm looking for something involving 'self' or 'parent' keywords (or maybe no keywords at all, and an implicit local)
Denis Lisov
@tanriol
Aug 03 2018 11:19 UTC
super::a::something
Sylwester Rąpała
@xoac
Aug 03 2018 11:28 UTC

I have sth like this

          + PartialOrd
          + Copy
          + Mul<f32, Output = U>
          + Sub<Output = U>
          + Add<Output = U>
          + Neg<Output = U>
          + Debug,

I would like create alias for that to not change this in many place if I need remove/add trait.
I have tried:

trait LimitType<T>:
    PartialEq
    + PartialOrd
    + Mul<f32, Output = T>
    + Copy
    + Sub<Output = T>
    + Add<Output = T>
    + Neg<Output = T>
    + Debug
{
}
but this is not a alias but new trait..
and thats is sad
Denis Lisov
@tanriol
Aug 03 2018 11:33 UTC
Add impl<S> LimitType<T> for S where S: PartialEq + PartialOrd + /* all the others */ {}
Sylwester Rąpała
@xoac
Aug 03 2018 11:37 UTC
oo thats nice hack
there should be impl<S, T> I guess.
Heinz N. Gies
@Licenser
Aug 03 2018 11:40 UTC
hmm I got another question for you good folks. I've a library that builds against a c-project and I'd like to define the tag to clone as a feature for the crate but I can't see a way in the docs to provide a feature witha . value to it, just a true/false
Denis Lisov
@tanriol
Aug 03 2018 11:43 UTC
Not possible as a feature. If you have more specific information, there may be a good solution... or maybe not.
Heinz N. Gies
@Licenser
Aug 03 2018 11:44 UTC
basically what I try to do is:
[dependencies]
my_lib_wrapper = { git = "my_lib_wrapper.git", c_lib_version="v1.0.0"}
doesn't need to be a feature I just thought that'd be the way to go :) I figure one way is setting up an environment variable but it'd be nice to be able to specify the version as part of the git
Denis Lisov
@tanriol
Aug 03 2018 11:47 UTC
So you're trying to make a wrapper for some library that allows the dependencies to request any specific version they need? What if multiple dependencies want to wrap different versions of the library?
Sylwester Rąpała
@xoac
Aug 03 2018 11:47 UTC
@tanriol Is somewhere a place where I can buy u a beer?
Heinz N. Gies
@Licenser
Aug 03 2018 11:48 UTC
I understand the problems with it and don't like it, sadly it's $requirement$ :/
Lyle Mantooth
@IslandUsurper
Aug 03 2018 11:49 UTC
@Licenser, what about binding your wrapper's version to the C lib's version?
Denis Lisov
@tanriol
Aug 03 2018 11:49 UTC
@xoac No need, glad to help :-)
Lyle Mantooth
@IslandUsurper
Aug 03 2018 11:49 UTC
Maybe as different branches, so you can fix bugs.
Heinz N. Gies
@Licenser
Aug 03 2018 11:50 UTC
ja that's the way I would like to to do it but nah
Sylwester Rąpała
@xoac
Aug 03 2018 11:50 UTC
I see your help all the time. Like it would be your work?
Denis Lisov
@tanriol
Aug 03 2018 11:53 UTC
The other way round: it's different enough from my work to be a good distraction :-)
Heinz N. Gies
@Licenser
Aug 03 2018 11:53 UTC
:D
Stefan Majewsky
@majewsky
Aug 03 2018 13:29 UTC
Hi there! I have a question. Or actually, I have painted myself in a kind of weird corner. I have a module in my crate that has the same name as some crate I'm using, so my module shadows the crate and I cannot use anything from the crate. To illustrate, let's assume that the crate in question is core. So I have this in my repo:
Michal 'vorner' Vaner
@vorner
Aug 03 2018 13:30 UTC
You have extern trace that_crate somewhere at the top. You can do extern crate that_crate as renamed_crate.
Stefan Majewsky
@majewsky
Aug 03 2018 13:30 UTC
Oooh, nice.
Does that also work for std and core?
Like extern crate core as libcore?
Just checked, and it does. Thanks for the pointer!
Michal 'vorner' Vaner
@vorner
Aug 03 2018 13:33 UTC
But maybe a better option is to… not name your module core.
Stefan Majewsky
@majewsky
Aug 03 2018 13:34 UTC
The thing is, I'm implementing a spec, and the top-level modules in my crate match the modules of the spec.
But there happens to be a module called "core".
Jan Hlavatý
@hlavaatch
Aug 03 2018 14:26 UTC
Hi, how do i get part of data in Vec<u8> written into a File?
I have starting offset and size
Zakarum
@omni-viral
Aug 03 2018 14:26 UTC
std::fs::File::create(...)?.write_all(&vec[start .. end])?
Jan Hlavatý
@hlavaatch
Aug 03 2018 14:27 UTC
tx
Zakarum
@omni-viral
Aug 03 2018 14:27 UTC
You need std::io::Write trait in scope
Jan Hlavatý
@hlavaatch
Aug 03 2018 14:29 UTC
Yes i got that just wasnt sure about the slice syntax
Zakarum
@omni-viral
Aug 03 2018 14:30 UTC
It's Index<Range> syntax btw. Not only slices may implement it
Jan Hlavatý
@hlavaatch
Aug 03 2018 14:37 UTC
Looks too easy to be true, but it is! Lol love Rust more and more the deeper I get into it...
tandrysyawaludin
@tandrysyawaludin
Aug 03 2018 17:40 UTC
anyone know why after i converted str to String the result has \
example.to_string()
result: "\"2aa@.a\""
Andrey Lesnikov
@ozkriff
Aug 03 2018 18:12 UTC
it's just an escape character. it should be visual only (are you printing it with Debug trait?) you can print out exact data using bytes
btw, it should work exactly the same way for str/String
Jan Hlavatý
@hlavaatch
Aug 03 2018 18:22 UTC
you probably have the quotes in the str

Does Rust have notion of 'friend module'? I.e. something like:
src/a/b/c/d/foo.rs
src/a/b/c/d/bar.rs

where the two module can refer to the non-public types/functions/methods of each other?

I prefer to split the 'module' into smaller units, but doing so would require things to be described public.

Hans W. Uhlig
@huhlig
Aug 03 2018 19:04 UTC
pub(crate)
ah, so foo and bar would both use "pub(super)" ?
tsoernes
@tsoernes
Aug 03 2018 19:25 UTC
Considering the ndarray package, is it possible to do this without cloning? I though into_iter stole ownership
let k_ys: Array1<Y> = ...
    // Group targets by their count
    let mut y_counts: HashMap<Y, usize> = HashMap::new();
    for y in k_ys.into_iter() {
        if y_counts.contains_key(&y) {
            let inc = y_counts.get(&y).unwrap() + 1;
            y_counts.insert(y.clone(), inc);
        } else {
            // TODO should this not be possible without cloning, since its into_iter
            y_counts.insert(y.clone(), 1);
        }
    }
Ichoran
@Ichoran
Aug 03 2018 21:42 UTC
When you have two traits that have identically typed functions, and a struct that has implementations for both, how do you pick the one you want? For instance, both Display and Debug have the same fmt function.
Also, why can you derive Debug for [Foo; 9] but not [Foo; 36]? What is the limit?
Ichoran
@Ichoran
Aug 03 2018 21:52 UTC
And I guess the answer to the first is just to use function syntax not method syntax, i.e. Debug::fmt(&myThing, f)
Is there a way to statically, at compile time, get the size of a Struct ?

I want to declare a struct consisting of 3 f32's so that it can be accessed

either as x, y, z, w or r, g, b, a

(I'm trying to mimic GLSL vec4)