Guild icon
DDraceNetwork
DDraceNetwork / general
This channel is for all Teeworlds/DDNet and related chat. Gameplay questions can be asked here as well rather than in #questions. Ingame screenshots and any other Teeworlds related media goes to #showroom.
Between 2023-05-22 00:00:00Z and 2023-05-23 00:00:00Z
Avatar
morning ddnet ddnet
PES_Hi 5
Avatar
Avatar
Ryozuki
morning ddnet ddnet
Lumpy ◐ω◑ 2023-05-22 10:00:00Z
how's your monday going?
Avatar
as usual
10:00
went to gym and now work
greenthing 2
Avatar
@Ryozuki what is the difference between &str and String in rust. just that &str is not mutable, it has 2 fields in stack, pointer to the start of data and length when String can be flexible size and has ptr, length and capacity fields?
Avatar
a String is owned
11:28
&str is a borrow to string
11:28
a string literal is a &str to
11:29
with 'static lifetime
11:30
and if u want to represent a possibly owned or borrowed string
11:30
cows are ur friend
11:30
Cow< 'static, str> is a nice trick (edited)
Avatar
what happens if i teoretically do let mut x = "Deez"; x = "nuts";
Avatar
u simply change where the &str points to
11:32
both are literals
11:32
also #developer
Avatar
when #developer
11:32
a gg
Avatar
my js monke brain cant handle it
11:32
even tho i hate js feelsbadman
Avatar
Avatar
MilkeeyCat
@Ryozuki what is the difference between &str and String in rust. just that &str is not mutable, it has 2 fields in stack, pointer to the start of data and length when String can be flexible size and has ptr, length and capacity fields?
Lumpy ◐ω◑ 2023-05-22 11:46:42Z
pls don't tell me that you're rewriting the site on rust justatest
Avatar
Avatar
Lumpy ◐ω◑
pls don't tell me that you're rewriting the site on rust justatest
no, i cant even write a fucntion which works correctly with String and &str
11:47
justatest
11:47
but thats a good idea
11:47
for future
Avatar
Lumpy ◐ω◑ 2023-05-22 11:48:23Z
dat site is doomed
Avatar
Avatar
MilkeeyCat
@Ryozuki what is the difference between &str and String in rust. just that &str is not mutable, it has 2 fields in stack, pointer to the start of data and length when String can be flexible size and has ptr, length and capacity fields?
&str is just a view, String is like a buffer that you can write to
12:05
you can get a &str view of String
Avatar
Pointer with extra steps smh
Avatar
Avatar
Learath2
Pointer with extra steps smh
safe pointer*
Avatar
Avatar
Learath2
Pointer with extra steps smh
the problem is that pointers can be owned in C/C++, too
Avatar
with lot of ergonomics due to not needing a stupid \0 char for valid strs
Avatar
std::unique_ptr with extra steps
Avatar
u cannot slice like rust does
12:09
u would need to make ur custom str
Avatar
what the hell is &mut str 😭
Avatar
a mutable view of the string slice
12:09
u can only replace its contents
12:09
not add
Avatar
ok thonk
Avatar
Avatar
Ryozuki
not add
also it's rarely used, if at all
Avatar
ye never seen
Avatar
but does it work in theory?
Avatar
yes, works in theory
Avatar
would be useful if u have a inplace algorithm
12:12
maybe some sort
Avatar
Avatar
Ryozuki
u would need to make ur custom str
Did somebody say std::string_view? coolcry
Avatar
in fact
12:13
u can .sort() a mut str
12:13
it works on any slice
Avatar
Avatar
Learath2
Did somebody say std::string_view? coolcry
justatest
Avatar
Avatar
Ryozuki
u can .sort() a mut str
I don't think so
Avatar
The current algorithm is an adaptive, iterative merge sort inspired by timsort. It is designed to be very fast in cases where the slice is nearly sorted, or consists of two or more sorted sequences concatenated one after another.
>
Also, it allocates temporary storage half the size of self, but for short slices a non-allocating insertion sort is used instead.
Avatar
Avatar
Ryozuki
it works on any slice
but &mut str isn't a slice as far as the language is concerned
Avatar
A dynamically-sized view into a contiguous sequence, [T]. Contiguous here means that elements are laid out so that every element is the same distance from its neighbors.
12:14
hmm
12:14
is a sort on a str different than sorting its bytes view?
Avatar
yes
12:14
due to utf-8
Avatar
i see then yeah
Avatar
going from &mut str to &mut [u8] would be unsound btw
12:14
which is why that method doesn't exist
Avatar
i think u gotta put the chars in a vec<char>
12:15
or idk
Avatar
yea, that'd work
Avatar
let s = wordy.chars().sorted().rev().collect::<String>();
12:15
itertools sorted tho
12:15
or is it std
12:15
itertools is essential anyway
12:16
i love it
Avatar
why do you reverse the sorting?
Avatar
idk i copied it from so
12:23
but maybe the sort is not in the order they like
Avatar
How does this even work btw? Don’t you need to consume the entire iterator to make a sorted version and thus kinda lose all the benefits of using an iterator?
Avatar
Sort all iterator elements into a new iterator in ascending order.
>
Note: This consumes the entire iterator, uses the slice::sort method and returns the result as a new iterator that owns its elements.
>
The sorted iterator, if directly collected to a Vec, is converted without any extra copying or allocation cost.
Avatar
sorted is just like in python
Avatar
An [Iterator] blanket implementation that provides extra adaptors and methods.
Avatar
it creates a new vector
12:27
so yes, it loses all the benefits of it being an iterator
Avatar
Avatar
Ryozuki
u can only replace its contents
do you know how to do it? 0_o
Avatar
Avatar
MilkeeyCat
do you know how to do it? 0_o
there's basically no way to do it with &mut str
12:32
don't get hung up on &mut str, I think
12:32
just ignore it ^^
12:32
it's not a type with a lot of useful methods in rust
12:32
you probably want a &mut String or a String
Avatar
Avatar
heinrich5991
don't get hung up on &mut str, I think
i also think so after staring 40 mins on monitor
Avatar
I don't think I've ever used &mut str in my (checks calendar) ~10 years of rust
12:34
u probs confusing stuff
12:34
use String
12:34
doesnt matter if u clone a lot either when u learn
12:35
and remember, if u want to modify the String, use let mut
Avatar
ok ill remember
Avatar
fn main() { let mut hello = String::new(); hello.push_str("hello"); println!("{hello}") }
Avatar
damn, thanks for the help =]
12:37
i just wanted to know wtf are &str and &mut str and when to use them. it wasnt a problem just to use String
Avatar
&str is useful, &mut str is not
Avatar
2 hours of research also says so =]
Avatar
@keb wanna hop on fng
Avatar
Avatar
MilkeeyCat
2 hours of research also says so =]
Lumpy ◐ω◑ 2023-05-22 15:14:10Z
thanks for bringing up #developer things in #general troll
Avatar
Avatar
Lumpy ◐ω◑
thanks for bringing up #developer things in #general troll
np
15:15
im too dumb for #developer
Avatar
feel free to post in #developer, everyone is free to do so
Avatar
Lumpy ◐ω◑ 2023-05-22 15:16:25Z
you don't want Milkeey in developer, trust me troll
Avatar
Avatar
Lumpy ◐ω◑
you don't want Milkeey in developer, trust me troll
ayo, it hurts 😭
15:18
but true :|
yes 1
16:55
blocks so many directions it had to mention directions twice
Avatar
Hm the word could be replaced with "every" to fix without much code change
Avatar
Avatar
cyberFighter
@keb wanna hop on fng
YES
17:28
IN A BIT
Avatar
Avatar
cyberFighter
Click to see attachment 🖼️
who do I ask for directions on how to use it?
Avatar
Btw, many of the sentences in the Entity Descriptions don't have "." kek
17:55
Some of the words which are capitalized, aren't capitalized at all
17:55
whoever made those descriptions, well... how did you guys not notice it? 😄
Avatar
I think it's in a repo somehwere
17:55
you can fix it
Avatar
if you're interested, I can try finding it
Avatar
found it
Avatar
@Cellegen basically, I think you need to undo all the capitalization changes
19:07
I think the capitalization was correct before
Avatar
If you want to
Avatar
@heinrich5991 pls dm
Avatar
@murpi pls dm bro
Avatar
stop pinging people for no reason
Avatar
Avatar
masque
@murpi pls dm bro
did you get banned from a server
Avatar
Avatar
Voxel
did you get banned from a server
No
Avatar
@Ravie @Skeith
23:48
best skin uncontested
Exported 136 message(s)