Αλεχ
как в гипере кастомыне ошибки возвращать?:
Αλεχ
только чейнить через then целиком всю футуру?
Αλεχ
низя
Αλεχ
в гипере нельзя пользоваться полем Error для футуры, оно только для гипера
Αλεχ
https://github.com/hyperium/hyper/issues/1131
Αλεχ
Users sometimes try to create hyper::Errors, even though they really shouldn't. It is meant only for saying "this thing went wrong while hyper was parsing HTTP", and nothing else. Part of this can be fixed also by changing the actual error types used, such as in outgoing Streams.
Αλεχ
окей допустим, тогда внимание вопрос, как заставить работать Either<futureA, futureB>?
Αλεχ
у меня есть функция с жесткой сигнатурой (требуется гипером): fn echo( req: Request<Body>, telegram_client: &TelegramClient, ) -> impl Future<Item = Response<Body>, Error = hyper::Error> + Send { let result = req.into_body().concat2().and_then(|chunk| { let result = from_slice::<Update>(chunk.as_ref()); match result { Ok(u) => { let chat_id = u.message.chat.id; Either::Left(telegram_client .send_message(chat_id, "Hello from bot") .map(|_| Response::new(Body::empty()))) }, Err(x) => Either::Right(future::ok(Response::builder() .status(StatusCode::UNPROCESSABLE_ENTITY) .body(Body::empty()) .unwrap())) } }); result }
Αλεχ
Но он срет ошибку
Αλεχ
error[E0277]: the trait bound `either::Either<futures::Map<hyper::client::ResponseFuture, [closure@src\main.rs:91:26: 91:58]>, futures::FutureResult<http::Response<hyper::Body>, _>>: futures::Future` is not satisfied --> src\main.rs:83:6 | 83 | ) -> impl Future<Item = Response<Body>, Error = hyper::Error> + Send { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `futures::Future` is not implemented for `either::Either<futures::Map<hyper::client::ResponseFuture, [closure@src\main.rs:91:26: 91:58]>, futures::FutureResult<http::Response<hyper::Body>, _>>` | = note: required because of the requirements on the impl of `futures::IntoFuture` for `either::Either<futures::Map<hyper::client::ResponseFuture, [closure@src\main.rs:91:26: 91:58]>, futures::FutureResult<http::Response<hyper::Body>, _>>` = note: required because it appears within the type `futures::AndThen<futures::stream::Concat2<hyper::Body>, either::Either<futures::Map<hyper::client::ResponseFuture, [closure@src\main.rs:91:26: 91:58]>, futures::FutureResult<http::Response<hyper::Body>, _>>, [closure@src\main.rs:84:53: 98:6 telegram_client:_]>` = note: the return type of a function must have a statically known size
Αλεχ
чяднт?
Cat
-> Either<Impl Future< ... > + Send> ?
Αλεχ
Это же часть req.into_body().concat2().and_then
Αλεχ
хотя мб ты прав
Αλεχ
не, тогд он срет error[E0308]: mismatched types --> src\main.rs:99:5 | 99 | result | ^^^^^^ expected enum `either::Either`, found struct `futures::AndThen` | = note: expected type `either::Either<_, _>` found type `futures::AndThen<futures::stream::Concat2<hyper::Body>, either::Either<futures::Map<hyper::client::ResponseFuture, [closure@src\main.rs:91:26: 91:58]>, futures::FutureResult<http::Response<hyper::Body>, _>>, [closure@src\main.rs:84:53: 98:6 telegram_client:_]>`
Αλεχ
корневая футура andthen
Αλεχ
and_then заменил на then
Αλεχ
теперь другое срет
Αλεχ
могу скинуть гит чтобы можно было на домашнем компе поиграться
Valery
@Psilon кидай, че
Αλεχ
https://github.com/Pzixel/boyan_detector_bot/tree/feature/database - вот эта бранча
Αλεχ
в мастере говно старое, туда не смотрите :D
Valery
@Psilon fn echo( req: Request<Body>, telegram_client: &TelegramClient, ) -> impl Future<Item = Either<(), Response<Body», Error = hyper::Error> + Send { let result = req.into_body().concat2().map(|chunk| { let result = from_slice::<Update😠chunk.as_ref()); match result { Ok(u) => { let chat_id = u.message.chat.id; Either::Left( telegram_client .send_message(chat_id, "Hello from bot") .map(|_| Response::new(Body::empty())), ) } Err(x) => Either::Right(future::ok( Response::builder() .status(StatusCode::UNPROCESSABLE_ENTITY) .body(Body::empty()) .unwrap(), )), } }); result }
Valery
не понятно что у тебя должно быть
Valery
зачем там either
Valery
но в его ветках либо респонз, либо колбасень
Αλεχ
Either там потому что правая ветка match - FutureResult, а слева - FutureMap
Valery
но это должно быть в сигнатуре выхода функции
Valery
они не унифицируются
Anonymous
Update😠chunk.as_ref()
Эти моменты напоминают мне о свифте.
Αλεχ
Either<(), Response<Body»
Αλεχ
вот это ваще не понял
Αλεχ
Either над двумя футурами
Αλεχ
либо у нас ошибка и мы возвращаем собсна ошибку
Valery
если тебе интересно какой тип, ставь ()
Αλεχ
либо все ок и мы делаем хттп запрос
Valery
он скажет что надо (), а получяется hjfkdlahfjkldsa
Αλεχ
да, знаю
Αλεχ
но там обе ветки футуры
Αλεχ
почему справа ResponseBody?
Valery
потому что это Response<Body>
Αλεχ
но там нет Either с Response
Valery
https://docs.rs/futures/0.1.21/futures/future/enum.Either.html
Valery
это не тот Either походу :D
Αλεχ
лол
Αλεχ
а я из комментов взял, что они перешли на крейт either
Valery
а, ну может быть
Valery
а версия футур какая?
Valery
Either::Right(future::ok( Response::builder() .status(StatusCode::UNPROCESSABLE_ENTITY) .body(Body::empty()) .unwrap(), )),
Αλεχ
21
Αλεχ
Either::Right(future::ok(
Valery
странно это все
Valery
unwrap()
Valery
а не
Valery
показалось
Αλεχ
unwrap() это у них такой метод на билдере
Αλεχ
чтобы создать объект
Αλεχ
очень удобно
Αλεχ
думаешь там паника может быть
Αλεχ
а на саммо деле нет
Valery
так это ваще std::Either походу
Valery
ну он не футуре, даже близко :D
Αλεχ
починилось
Αλεχ
короче беда была в неправильных футурах
Valery
оттак от
Αλεχ
в неправильных Either'ах
Αλεχ
fn echo( req: Request<Body>, telegram_client: &TelegramClient, ) -> impl Future<Item = Response<Body>, Error = hyper::Error> + Send { let result = req.into_body().concat2().and_then(|chunk| { let result = from_slice::<Update>(chunk.as_ref()); match result { Ok(u) => { let chat_id = u.message.chat.id; Either::A( telegram_client .send_message(chat_id, "Hello from bot") .map(|_| Response::new(Body::empty())), ) } Err(x) => Either::B(future::ok( Response::builder() .status(StatusCode::UNPROCESSABLE_ENTITY) .body(Body::empty()) .unwrap(), )), } }); result }
Αλεχ
вот так почти работает
Αλεχ
только обосрался на тему лайфтаймов
Valery
да, только 'static просит
Αλεχ
и че, надо lazy_static в мейне делать?
Αλεχ
а то я даж не знаю)
Маjко
Нет
Маjко
Negative Trait Bounds доступны только для Sync/Send
Маjко
Пошарься по обсуждениям, но емнип не приоритет
Αλεχ
Сделай требование Clone
Αλεχ
они с дропом взаимоисключающие
Маjко
🔥🔥🔥