Quantcast
Channel: Recent Questions - Solana Stack Exchange
Viewing all articles
Browse latest Browse all 8031

Vec sorting doesn't work

$
0
0

It's a bit Rust question, but the type I used was anchor's Vec<Pubkey> type, so came here to ask. Here is the code.

pub fn set_tokens(&mut self, tokens: Vec<Pubkey>) -> Result<()> {    msg!("unsorted tokens: {:?}", tokens);    let mut sorted_tokens: Vec<_> = tokens.iter().collect();    sorted_tokens.sort();    msg!("sorted tokens: {:?}", sorted_tokens);    Ok(())}

And the result is like this.

unsorted tokens: [1111111QLbz7JHiBTspS962RLKV8GndWFwiEaqKM, 1111111ogCyDbaRMvkdsHB3qfdyFYaG1WtRUAfdh, 11111112D1oxKts8YPdTJRG5FzxTNpMtWmq8hkVx3, 11111112cMQwSC9qirWGjZM6gLGwW69X22mqwLLGP, 111111131h1vYVSYuKP6AhS86fbRdMw9XHiZAvAaj]sorted tokens: [1111111QLbz7JHiBTspS962RLKV8GndWFwiEaqKM, 1111111ogCyDbaRMvkdsHB3qfdyFYaG1WtRUAfdh, 11111112D1oxKts8YPdTJRG5FzxTNpMtWmq8hkVx3, 11111112cMQwSC9qirWGjZM6gLGwW69X22mqwLLGP, 111111131h1vYVSYuKP6AhS86fbRdMw9XHiZAvAaj]

It's totally same. Sort didn't happen. Why is it like this? And how could I fix it?


Viewing all articles
Browse latest Browse all 8031

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>