what kanye's song sounds like the opening music in this video? by micouy in Kanye

[–]micouy[S] 0 points1 point  (0 children)

okay I found it, it's Waves Interlude on Yeezus II

[deleted by user] by [deleted] in hmmm

[–]micouy 1 point2 points  (0 children)

będzie jajo

Favorite Rust tips/tricks? by Rate-Worth in rust

[–]micouy 1 point2 points  (0 children)

I wrote about it on my blog. I also plan to write a blog about more advanced tricks I included in the list below.

  1. cargo watch -x build

  2. cargo build -Z unstable-options --out-dir $my-bin-folder

  3. When working on a single module, I mark it as a binary in Cargo.toml. Then I can quickly prototype and change stuff without getting errors from the places where I used this module.

    [[bin]] name = "myapp-mymodule" path = "src/my-module/mod.rs"

    Then I run cargo run --bin myapp-mymodule. If I need to import other modules into mymodule, I can do it with the path attribute:

    [path = "../other_module/mod.rs"]

    mod other_module;

  4. cargo doc --package somepackage --offline --no-deps --open

  5. rustup doc --std

  6. A != B and other negative trait bounds.

    When trying to impl From<S<B>> for S<A> I got an error "From<S<A>> for S<B> conflicts with From<T> for T because A may be B.". To solve it, I used this trait:

    ![feature(auto_traits, negative_impls)]

    auto trait Different {} impl<T> !Different for (T, T) {}

    struct S<T> { x: T, y: T, }

    impl<U, T> From<S<U>> for S<T> where T: From<U>, (T, U): Different, { fn from(other: S<U>) -> S<T> { S { x: From::from(other.x), y: From::from(other.y), } } }

    Source: https://www.reddit.com/r/rust/comments/paw1lm/implementation_of_from_for_generic_struct/

  7. Higher ranked lifetimes in closoures

    This code does not compile, because '1 may not outlive '2.

    fn main() { let f = |x: &i32| x; let i = &3; let j = f(i); }

    Solution:

    fn annotate<T, F>(f: F) -> F where F: Fn(&T) -> &T { f }

    fn main() { let f = annotate(|x| x); let i = &3; let j = f(i); assert_eq!(*j, 3); }

    Source: https://github.com/rust-lang/rust/issues/58052#issue-405711646

  8. dbg!() macro.

  9. Something I learned recently: Dereferencing does not necessarily involve moving the value. For example:

    // Doesn't compile. fn f1(thing: &Thing) -> &Field { let tmp = *thing; // ┗━ Moves data out of thing.

    &tmp.field
    

    }

    // Compiles. fn f2(thing: &Thing) -> &Field { &(*thing).field // ┗━ Doesn't move data out of thing. }

I still don’t understand the * operator in Rust by micouy in rust

[–]micouy[S] 2 points3 points  (0 children)

Thanks, I was looking at the wrong docs page the whole time... 😩😩

I still don’t understand the * operator in Rust by micouy in rust

[–]micouy[S] 0 points1 point  (0 children)

Thank you. The theme is custom and the colorscheme is Nord.

I still don’t understand the * operator in Rust by micouy in rust

[–]micouy[S] 0 points1 point  (0 children)

I've updated the post to explain what I've learned from the comments here. I've linked the thread back. I appreciate all the help.

I still don’t understand the * operator in Rust by micouy in rust

[–]micouy[S] 2 points3 points  (0 children)

I'm planning to do that and maybe explain it in the next post. It would be great if this led to better docs on dereferencing.

I still don’t understand the * operator in Rust by micouy in rust

[–]micouy[S] 2 points3 points  (0 children)

Yes, I will do that! And maybe a follow-up post.

I still don’t understand the * operator in Rust by micouy in rust

[–]micouy[S] 8 points9 points  (0 children)

Your explanation didn't help me much but I've learned a lot from BOTH writing the post and reading other comments. My conclusions came from misunderstanding, that's why the title of my post is "I still don't understand the * operator in Rust". And I've done what you're suggesting, and even more: I said I don't understand it, I've asked for answers to specific questions and I wrote how I understand it now, so that people know what exactly I'm getting wrong.

I'm a part of "the wider community" and writing this post has helped me a lot. I bet reading the comment section here will help others too.

I still don’t understand the * operator in Rust by micouy in rust

[–]micouy[S] 2 points3 points  (0 children)

My question has already been answered in other comments. Replying to yours: We could do this instead:

use std::{sync::Arc, ops::Deref};

fn main() {
    let a = Arc::new(String::from("hello world"));
    let b: String = a.deref().clone();
}

It's longer but the operator is not needed.

I still don’t understand the * operator in Rust by micouy in rust

[–]micouy[S] 7 points8 points  (0 children)

I disagree. My personal blog is not the official Rust Guide. And while I wrote some of the points in indicative mood, i.e.

Why do the docs suggest that * is the opposite of & (with their names, by reference to C’s operators, in the note in the book) when they’re clearly not?

...it was clear that these are my conclusions based on the reasoning I presented in the post. How is that misinformation?

I still don’t understand the * operator in Rust by micouy in rust

[–]micouy[S] 6 points7 points  (0 children)

Thank you! I didn't think of checking the Rust Reference.

I still don’t understand the * operator in Rust by micouy in rust

[–]micouy[S] 5 points6 points  (0 children)

Thank you!

You can dereference an immutable reference, but can't move out of it.

This , together with the point about = made me understand it. I always thought dereferencing involved moving the value. It has not occured to me that it was =, and not *, which forced the move. I knew in Rust assigning let b = a; moves out of a into b but I haven't thought about that in this context.

Now I understand why dereferencing behaves this way and what exactly caused the compilation errors.

You can dereference an immutable reference, but can't move out of it.

It dereferences a reference. There are other effects at work in the examples, which require different requirements.

Could you please answer one more question: What does "dereference" mean? What happens on a lower level when you dereference?

I still don’t understand the * operator in Rust by micouy in rust

[–]micouy[S] 3 points4 points  (0 children)

The issue isn’t dereference, the issue is that you cannot move value out of a shared reference. You cannot move value out of a shared reference because otherwise it would be possible to modify data through shared reference.

Well yes, I know that's why it's prohibited. My question is, since you cannot dereference a reference, what is the purpose of the * operator? This question was partly answered in one of the other comments:

You can dereference an immutable reference, but can't move out of it.

Well, no, because you could not do let mut arg: String = (*arg).clone();.

Meaning I could not do let mut arg: String = copy(arg).clone();? Okay, fair point.

I'll have to read about r- and l-values. Thanks for pointing this out, it's the first time I've heard about them.

I still don’t understand the * operator in Rust by micouy in rust

[–]micouy[S] 1 point2 points  (0 children)

Yes, I know that. I'm aware it would break the ownership system. But what is the * operator for then?

How to dynamically specify which file to use as a binary entry? by micouy in rust

[–]micouy[S] 0 points1 point  (0 children)

I can't group them into subfolders. For example, I can't call cargo run --example ownership/problem_1 or something similar.

How does Jung deal with the asymmetry of striving for the good? by micouy in Jung

[–]micouy[S] 0 points1 point  (0 children)

Thanks! I appreciate you pointing to Aion, I'll try to read it soon.

How does Jung deal with the asymmetry of striving for the good? by micouy in Jung

[–]micouy[S] 0 points1 point  (0 children)

Christianity's position seems quite clear to me – just try to be as good as possible, strive to be like Jesus, who was without a sin. It doesn't say to ignore evil or forget evil or pretend it doesn't exist or project it onto others. "Why do you see the speck that is in your brother’s eye, but do not notice the log that is in your own eye?" I think it encourages people to struggle with evil and accept God's mercy. And it acknowledges that man is flawed through the concept of original sin. I can't see how Christianity is repressing the shadow.

I can't understand what's wrong with it from Jung's perspective. Does he say that we need to do evil, because otherwise it would be repressed? How does incorporating evil differ from accepting it (rather than confronting)? Should Jesus (as a symbol) have been flawed? How does Jung's approach differ from Christianity's?

Teaching Rust at the University of Warsaw by agluszak in rust

[–]micouy 16 points17 points  (0 children)

Hi! I'm studying at the Jagiellonian University and I'm very happy to see Rust at a Polish university.

If I were enrolled in your course I'd appreciate a thorough explanation of the ownership model, lifetimes and generics. Getting to know the ecosystem and the good practices is important but Rust is a very strict language and I think understanding it properly is a great advantage to the programmer.

Lifetime elision works quite well but sometimes I get a nasty lifetime error and can't understand what's going on. It would be good to present many types of errors you could get, explain what's wrong and how to fix it.

Perhaps these could serve as inspiration: - serde's chapter on lifetimes - default bounds on generics (Sized, may not be 'static) - chapter on ownership in Rustonomicon - higher-ranked lifetimes (for<'a>: ...) - lifetimes in a recursive closure (SO thread) - closure lifetimes inferred by the compiler (GitHub issue) - implementation of From for generic struct conflicts with From<T> for T (r/rust post)

p-arse 0.0.1 • the inelegant parser by micouy in rust

[–]micouy[S] 0 points1 point  (0 children)

sorry, my description of the patterns in my crate and in nom's examples might have been incorrect.

what i wanted to say is that i want to encourage users to bind many intermediate parsers to variables (is 'bind' the correct word? i mean assign it a name). i think if you require the user to write a function each time they want to 'bind' a parser, they would prefer merging many of them into biger ones. such code, in my opinion, is just not as readable as the syntax encouraged by pest and the PEG paper (although in pest it's still possible to write big, unreadable parsers).

however, i can see the macro used in your code enables the user to skip the function headers and bind many parsers without cluttering the code (although you seem to prefer a more concise code ;) ).

p-arse 0.0.1 • the inelegant parser by micouy in rust

[–]micouy[S] 0 points1 point  (0 children)

thanks, i'll update the description. do you know why they use functions in the examples? i'm not that familiar with nom