Size: a a a

2020 December 09

JC

Julian =) Coffee in Rust Beginners
аа
источник

IB

Ivan Boldyrev in Rust Beginners
Max Kot
Во что лучше обернуть структуру которая будет только читаться в разных потоках?
Arc?
источник

E

Eugene in Rust Beginners
Max Kot
Во что лучше обернуть структуру которая будет только читаться в разных потоках?
если структура будет только читаться из разных потоков, зачем оборачивать структуру во что-то?
источник

MK

Max Kot in Rust Beginners
Я все пытаюсь разобраться с этой проблемой self
источник

Jøhn Đøꝩsøn in Rust Beginners
Eugene
если структура будет только читаться из разных потоков, зачем оборачивать структуру во что-то?
За тем что бы гарантировать что она будет только читаться?
источник

E

Eugene in Rust Beginners
Jøhn Đøꝩsøn
За тем что бы гарантировать что она будет только читаться?
зачем, по-вашему мнению, в rust есть borrowing rules?
источник

ИЛ

Иван Лещенко... in Rust Beginners
Eugene
если структура будет только читаться из разных потоков, зачем оборачивать структуру во что-то?
Потому-что структура может умереть раньше, чем будет использована каким-то потоком
источник

MK

Max Kot in Rust Beginners
Я добился новой ошибки ещё раз полистав книгу, но только больше запутался..
источник

MK

Max Kot in Rust Beginners
error[E0495]: cannot infer an appropriate lifetime due to conflicting requirements
 --> src/network/udp.rs:80:43
  |
80 |   ...                   thread::spawn(move || {
  |  _____________________________________^
81 | | ...                       self.handle(receiver)
82 | | ...                   });
  | |_______________________^
  |
note: first, the lifetime cannot outlive the lifetime 'a as defined on the impl at 33:6...
 --> src/network/udp.rs:33:6
  |
33 | impl<'a> UDPServer {
  |      ^^
note: ...so that the types are compatible
 --> src/network/udp.rs:80:43
  |
80 |   ...                   thread::spawn(move || {
  |  _____________________________________^
81 | | ...                       self.handle(receiver)
82 | | ...                   });
  | |_______________________^
  = note: expected &mut UDPServer
             found &'a mut UDPServer
  = note: but, the lifetime must be valid for the static lifetime...
note: ...so that the type [closure@src/network/udp.rs:80:43: 82:30] will meet its required lifetime bounds
 --> src/network/udp.rs:80:29
  |
80 | ...                   thread::spawn(move || {
  |                       ^^^^^^^^^^^^^

error: aborting due to previous error

For more information about this error, try rustc --explain E0495.
error: could not compile udpserver
источник

ИЛ

Иван Лещенко... in Rust Beginners
Max Kot
error[E0495]: cannot infer an appropriate lifetime due to conflicting requirements
 --> src/network/udp.rs:80:43
  |
80 |   ...                   thread::spawn(move || {
  |  _____________________________________^
81 | | ...                       self.handle(receiver)
82 | | ...                   });
  | |_______________________^
  |
note: first, the lifetime cannot outlive the lifetime 'a as defined on the impl at 33:6...
 --> src/network/udp.rs:33:6
  |
33 | impl<'a> UDPServer {
  |      ^^
note: ...so that the types are compatible
 --> src/network/udp.rs:80:43
  |
80 |   ...                   thread::spawn(move || {
  |  _____________________________________^
81 | | ...                       self.handle(receiver)
82 | | ...                   });
  | |_______________________^
  = note: expected &mut UDPServer
             found &'a mut UDPServer
  = note: but, the lifetime must be valid for the static lifetime...
note: ...so that the type [closure@src/network/udp.rs:80:43: 82:30] will meet its required lifetime bounds
 --> src/network/udp.rs:80:29
  |
80 | ...                   thread::spawn(move || {
  |                       ^^^^^^^^^^^^^

error: aborting due to previous error

For more information about this error, try rustc --explain E0495.
error: could not compile udpserver
but, the lifetime must be valid for the static lifetime
источник

ИЛ

Иван Лещенко... in Rust Beginners
Max Kot
error[E0495]: cannot infer an appropriate lifetime due to conflicting requirements
 --> src/network/udp.rs:80:43
  |
80 |   ...                   thread::spawn(move || {
  |  _____________________________________^
81 | | ...                       self.handle(receiver)
82 | | ...                   });
  | |_______________________^
  |
note: first, the lifetime cannot outlive the lifetime 'a as defined on the impl at 33:6...
 --> src/network/udp.rs:33:6
  |
33 | impl<'a> UDPServer {
  |      ^^
note: ...so that the types are compatible
 --> src/network/udp.rs:80:43
  |
80 |   ...                   thread::spawn(move || {
  |  _____________________________________^
81 | | ...                       self.handle(receiver)
82 | | ...                   });
  | |_______________________^
  = note: expected &mut UDPServer
             found &'a mut UDPServer
  = note: but, the lifetime must be valid for the static lifetime...
note: ...so that the type [closure@src/network/udp.rs:80:43: 82:30] will meet its required lifetime bounds
 --> src/network/udp.rs:80:29
  |
80 | ...                   thread::spawn(move || {
  |                       ^^^^^^^^^^^^^

error: aborting due to previous error

For more information about this error, try rustc --explain E0495.
error: could not compile udpserver
https://doc.rust-lang.org/std/thread/fn.spawn.html содержит баунд на 'static, так что тебе нужно либо передать владение, либо статическую ссылку
источник

MK

Max Kot in Rust Beginners
Но как мне уже объяснили проблема в self
источник

MK

Max Kot in Rust Beginners
Ведь ресив я передаю
источник

MK

Max Kot in Rust Beginners
Сделать всю структуру сервера static?
источник

MK

Max Kot in Rust Beginners
источник

PP

Pavel Perestoronin in Rust Beginners
Если ты не хочешь сильно париться, то ты можешь сделать метод для обертки селфа
источник

PP

Pavel Perestoronin in Rust Beginners
секунду
источник

MK

Max Kot in Rust Beginners
Хорошо
источник

PP

Pavel Perestoronin in Rust Beginners
Max Kot
Хорошо
источник

PP

Pavel Perestoronin in Rust Beginners
просто в противном случае ты не можешь разделить self на 2 потока, при условии, что тебя в обоих надо, чтобы можно было mut методы вызывать
источник